Actionscript 3: loading AS2 swf
- Started
- Last post
- 6 Responses
- CyBrain
I need an example of how to load a Flash 8/AS2 movie into a Flash 9/A3 movie. I'd like to set up a portfolio site that is in AS3 but loads all my AS2 work from the last few years. I just want to load, display and be able to close the AS2 content from a close button in the main movie.
I'm looking for a very simple solution here. I don't need any cross-scripting. I do not need any access to the loaded movie's functions, variables or anything. Both SWFs will be in the same domain and folder.
I posted my code and output error here:
http://code-bin.homedns.org/422
- CyBrain0
All the Googlings I did this morning resulted in complex uses of LiveConnect to cross script the two but overlooked how to display the content to begin with.
- kumori040
AS2 movies can be loaded into AS3 movies fairly simple. Just create a new loader instance, load the AS2 .SWF movie you want, and add it to the display stack.
For example (make sure you import all appropriate classes):
private function loadChild():void {
var _loader:Loader = new Loader();
loader.load(new URLRequest("myMovie.swf"));
addChild(loader);
}
//
loadChild();
- CyBrain0
Ok, I got the movie to load and play properly, but I'd like to be able to cast this thing as a movie clip. (This is where 90% of my AS3 problems lie) When I tried:
addChild(hopeDiamondLoader);
hope_diamond300x250_mc = MovieClip(hopeDiamondLoader);I got a type coercion error when I tried to reference the movie clip.
I'd like to mask out the swf to it's original stage size and fade it out with tweenlite eventually.
- kumori040
"hopeDiamondLoader" is an instance of the Loader class, and cannot be coerced to be a MovieClip. Maybe instead of directly adding "hopeDiamondLoader" to the stage, first create a new MovieClip instance, add that to the stage, and then add "hopeDiamondLoader" into that MovieClip.
- CyBrain0
Thanks. I probably should have thought of that. That will also help me through a lot of "needing movieClip reference" issues that I get all the time.
- kumori040
Yeah, as you'll find when learning AS3 (as I still am), you'll need to create Sprites or MovieClips only as containers just to be able to command other things. Containers are your friends!