The easiest way to do it
The code is as follows |
Copy Code |
var my_urlloader:loader=new Loader (); My_urlloader.load (New URLRequest ("swf.swf")); My_urlloader.contentLoaderInfo.addEventListener (event.complete,_show); function _show (e:event): void { AddChild (My_urlloader); } |
Example 2
The code is as follows |
Copy Code |
Import Flash.net.URLRequest; Import Flash.display.Loader; Import flash.events.Event; Import flash.events.ProgressEvent; var mc:movieclip = new MovieClip (); Function Startload ($swf: String) { var ldr:loader = new Loader (); var mrequest:urlrequest = new URLRequest ($ SWF); Ldr.contentLoaderInfo.addEventListener (Event.complete, Oncompletehandler); Ldr.contentLoaderInfo.addEventListener (progressevent.progress, Onprogresshandler); Ldr.load (mrequest); } Function Oncompletehandler ($e: Event) { MC = $e. Currenttarget.content as MovieClip; AddChild ($e . currenttarget.content); } Function Onprogresshandler ($e:P rogressevent) { var percent:number = $e. bytesloaded/ Mprogress.bytestotal; Trace (percent); } Startload ("mouseactions.swf"); |
The top 22 is simple to load, and if you want to implement AS3 loading an external SWF file and interacting with it we can follow the following method.
The loader class loads the. swf file and then accesses it through the content property of the loader instance
The code is as follows |
Copy Code |
Externalmovie Code: Package { Import Flash.display.Sprite; Import Flash.display.Shape; public class Externalmovie extends Sprite { private Var _color:uint=0x000000; private Var _circle:shape; Public Function Externalmovie () { Updatedisplay (); } Private Function Updatedisplay (): void { If circle is not created, it is created and displayed if (_circle = = null) { _circle=new Shape; AddChild (_circle); } To redraw and populate the previously drawn content _circle.graphics.clear (); _circle.graphics.beginfill (_color); _circle.graphics.drawcircle (100,100,40); } Change color Public Function SetColor (color:uint): void { _color=color; Updatedisplay (); } Get color Public Function GetColor (): UINT { return _color; } } } Loaderexample Code: Package { Import flash.display.*; Import Flash.net.URLRequest; Import flash.events.Event; public class Loaderexample extends Sprite { private Var _loader:loader; Public Function Loaderexample () { Create loader and display _loader = new loader (); AddChild (_loader); Interaction events added to a loaded SWF file _loader.contentloaderinfo.addeventlistener (Event.init,handleinit); Loading external files _loader.load (New URLRequest ("externalmovie.swf")); } Trigger this function when the file is loaded Private Function Handleinit (event:event): void { This is set to * means not knowing what type to load in advance. var movie:* = _loader.content; Get color value, display as 0 Trace (Movie.getcolor ()); Set color Movie.setcolor (0X016BE2); } } } |