2019-10-22 zhulinan Flash
对于外部加载的swf文件,无论是as2.0的还是as3.0的,我们不仅可以获得其本身的尺寸,还可以利用contentLoaderInfo获得其原始舞台的尺寸。 package { import flash.display.MovieClip; import flash.display.Loader; import flash.events.*; import flash.net.URLRequest; public class M extends MovieClip { public function M() { addEventListener(Event.ADDED_TO_STAGE, addedHandle); } private function addedHandle(e:Event):void { removeEventListener(Event.ADDED_TO_STAGE, addedHandle); btn1.addEventListener(MouseEvent.CLICK, btnClickHandle); btn2.addEventListener(MouseEvent.CLICK, btnClickHandle); } private function btnClickHandle(e:MouseEvent):void { var swf:String; if (e.target == btn1) { swf = "2.0.swf"; } else { swf = "3.0.swf"; } var loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandle); var request:URLRequest = new URLRequest(swf); loader.load(request); } private function completeHandle(e:Event):void { var swfStageWidth:Number = e.target.width; var swfStageHeight:Number = e.target.height; var swfWidth:Number = e.target.loader.width; var swfHeight:Number = e.target.loader.height; trace("加载的swf舞台尺寸是:" + swfStageWidth + "*" + swfStageHeight); trace("加载的swf尺寸是:" + swfWidth + "*" + swfHeight); } } }