Accessing MovieClips in one file from another SWF file
I am new to Flash and AS. I have 2 swf files, one in as2 and the other in as3, I have loaded the swf file (as2) in as3 swf, it works, but I need to access all the movie clips (swf (as2)) and change the property (like style ) dynamically. How can i do this.
Here's my code ::
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handleComplete);
addChild(loader);
loader.load(new URLRequest("games.swf"));
loader.x = 50;
loader.y = 125;
function handleComplete(event:Event):void{
trace("swf loaded");
}
the above code works fine and the swf file is loaded as well. how to access an individual movie clip from a swf as2 file .. I also know the entire name (ID) of the clip.
Help me overcome this problem ... Thanks in advance.
a source to share
I recommend using Event.INIT instead of Event.COMPLETE. INIT gets a trigger after the load is FULL and all classes / instances in the loaded swf are initialized and ready for use.
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT, handleInit);
addChild(loader);
function handleInit(e:Event):void{
var as2Movie:AVM1Movie = e.target.content as AVM1Movie;
}
You can access the loaded content through the content property of the Loader class. Not so, since you are loading an as2 movie into an as3 movie, some restrictions apply:
"AVM1Movie is a simple class that represents AVM1 clips that use ActionScript 1.0 or 2.0. (AVM1 is the ActionScript virtual machine used to run ActionScript 1.0 and 2.0. AVM2 is the ActionScript virtual machine used to run ActionScript 3.0.) Flash Player 8 or later The SWF file is loaded by the Loader object, the AVM1Movie object is created.The AVM1Movie object can use methods and properties inherited from the DisplayObject class (such as x, y, width, etc.), however, no interaction is allowed (for example, methods calling or using parameters) between the AVM1Movie and AVM2 objects.
There are several restrictions on the SWF AVM1 file loaded with the SWF AVM2 file:
The loaded AVM1Movie object acts as a psuedo-root object for the AVM1 SWF file and all AVM1 SWF files loaded by it (as if the ActionScript 1.0 lockroot property were set to true). The AVM1 movie is always the pinnacle of any ActionScript 1.0 or 2.0 execution for all children. The _root property for loaded children is always this AVM1 SWF file, unless the lockroot property is set in the loaded SWF AVM1 file. AVM1 content cannot load files into levels. For example, it cannot load files by calling loadMovieNum ("url", levelNum). The SWF AVM1 file loaded by the SWF AVM2 file cannot load another SWF file into it. That is, it cannot load another SWF file on top of itself. However, it can load child Sprite objects, MovieClips, or other AVM1 SWF files loaded by this SWF file."From the as3 docs.
See AMV1Movie Reference for more information .
If you want to call as2 movies from as3, you will need to use Local Connection to establish communication between the two swfs.
Grant Skinner wrote a handy thing called SWF Bridge for this kind of situation (easy as2 for as3 communication). It's worth trying.
Good luck!
a source to share