ActionScript:缩放嵌套的SWF以填充容器

时间:2010-08-26 16:23:00

标签: actionscript-3

我是ActionScript的新手。我在另一个SWF容器中嵌套SWF,以便能够将flash对象的点击发送到外部的javascript。我能够收到外面的点击,那部分工作正常。但内部内容不会缩放到外部容器的大小。我使用3.5 SDK中的 mxmlc ,除了actionscript文件名之外没有任何其他参数,将actionscript编译为SWF。如何让内部内容填满容器?

这是ActionScript:

   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>

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

将其添加到Container()方法的顶部:

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

这是私有函数loader_OnComplete(event:Event)的顶部:void方法

loader.content.width=stage.stageWidth;  

它有效!