Tuesday, June 10, 2008

new loadMovie

You don't need a container to load an external file anymore:

var loadMovie = new Loader();
addChild(loadMovie );
loadMovie .load(new URLRequest("page1.swf"));

but if you do want it to load into a certain movie or container, do it like this:
var loadMovie = new Loader();
container_mc.addChild(loadMovie );
loadMovie .load(new URLRequest("page1.swf"));

Apparently you can't just load a new movie in place of the new one anymore. You have to boot the old one out and then load in the new one:
container.removeChild(loadMovie);
loadMovie = new Loader();
container.addChild(loadMovie);
loadMovie.load(new URLRequest("page2.swf"));

Talking to the new movie's timeline is different too,
you'll have to cast it (it's called):
MovieClip(loadMovie.content).gotoAndStop("outro");

So far the new way to load a movie is the most annoying change about as3.

5 comments:

ccrider said...

Uh... I can't get these to work at all. Am I doing something wrong?

myBtn.addEventListener(MouseEvent.CLICK, click1);

function click1(event:MouseEvent):void //loads first subMenu movie
{
var request:URLRequest = new URLRequest("images/killMeNow.swf");
var loader:Loader = new Loader()
loader.load(request);
addChild(loader);
}

ccrider said...

Oh yeah, I STARTED with your examples. They didn't work, so I found this other variety of non-working code, too, which I've pasted above.

Regardless of whichever version I try, I get this error:

Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.

ccrider said...

Do I have to add a bunch of this bullshit to the beginning of my code or something?

import flash.display.Loader;
import flash.display.Sprite;
import flash.events.*;
import flash.net.URLRequest;

nate said...

My code should work. It looks like blogger added a few spaces before a couple of the periods, maybe you just have to take those out. In the next post up (Intro/Outro) there is an fla you can download that loads movies, maybe that will help. You don't have you add that import stuff unless you're making a class. Good luck.

ccrider said...

Thanks. The spaces did indeed fug me up, but I caught them and fixed it.

Having a new problem... Do you know how to direct a movie to the root or parent swf?