2010-08-26 61 views
0

我对ActionScript完全陌生。我将SWF嵌套到另一个SWF容器中,以便能够将Flash对象的点击发送到外部的JavaScript。我能够接收外部的点击,并且该部分工作正常。但内部内容不会缩放到外部容器的大小。我使用了来自3.5 SDK的mxmlc,除了actionscript文件名之外没有任何其他参数来将ActionScript编译为SWF。我怎样才能让内容填满容器?ActionScript:缩放嵌套的SWF以填充容器

这里的动作脚本:

package 
    { 
    import flash.external.ExternalInterface; 
    import flash.events.MouseEvent; 
    import flash.display.MovieClip; 
    import flash.display.Loader; 
    import flash.net.URLRequest; 
    import flash.events.*; 
    import flash.display.Sprite; 
    import flash.text.TextField; 
    import flash.text.TextFormat; 
    import flash.text.TextFieldAutoSize; 

    [SWF(backgroundColor="#ffff00", frameRate="24")] 

public class Container extends MovieClip 
{ 
    private var loader:Loader = new Loader(); 
    private var textfield : TextField = new TextField(); 

    public function Container() 
    { 
    root.addEventListener(MouseEvent.CLICK, useExternal, true);  
    var request:URLRequest = new URLRequest("adv.swf"); 
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_OnComplete); 
    loader.addEventListener(MouseEvent.CLICK, loader_OnClick); 
    loader.load(request); 

    addChild(textfield);  
    } 

    private function loader_OnComplete(event:Event):void 
    { 
    textfield.text = stage.stageWidth + ", " + stage.stageHeight; 
    textfield.autoSize = TextFieldAutoSize.LEFT; 
    textfield.setTextFormat(new TextFormat(null,48)); 
    textfield.x = stage.stageWidth - textfield.width; 
    textfield.y = stage.stageHeight/2 - textfield.height/2; 

    loader.content.width = stage.stageWidth; 
    loader.content.height = stage.stageHeight; 

    addChild(loader); 
    } 

    private function loader_OnClick(event:MouseEvent):void 
    { 
    ExternalInterface.call("swfClickFunction"); 
    } 

    private function useExternal(event:MouseEvent):void 
    { 
    ExternalInterface.call("ExternalFunction"); 
    } 
} 
} 

和HTML:

<html> 
<head> 
<script language="javascript"> 
function swfClickFunction() 
{ 
alert('Flash Clicked!'); 
} 

function ExternalFunction() 
{ 
alert('ExternalFunction!'); 
} 

</script> 
<body> 
<OBJECT 
name = Container 
id = Container 
codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0 
width = 800 
height = 80 
classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000> 
<PARAM NAME="movie" VALUE='Container.swf'> 
<PARAM NAME="quality" VALUE="high"> 
<embed 
    name='Container' 
    id='Container' 
    src='Container.swf' quality="high" 
    pluginspage="http://www.macromedia.com/go/getflashplayer" 
    type="application/x-shockwave-flash" 
    width='800' 
    height='80'> 
</embed> 
</OBJECT> 
</body> 

回答

0

将此添加到集装箱()方法的顶部:

  stage.align=StageAlign.TOP_LEFT; 
      stage.scaleMode=StageScaleMode.NO_BORDER ; 

这到专用函数loader_OnCom的顶部完成(事件:事件):无效方法

loader.content.width=stage.stageWidth; 

它的工作原理!

0
 
loader.content.width = 800; 
loader.content.height = 80; 
+0

没有工作 – naveed 2010-08-26 17:38:48

+0

我看到你得到它的工作! :)对不起,我认为你已经设置了舞台属性。 – PatrickS 2010-08-26 17:59:32