2
votes

i am currently working in adobe flash cc 2014 and i have loaded one .swf file that contains about 5000 frames of animation. And then i want to go to next scene after this loaded file finished playing.

this is the code i have, just simple loader code :

stop();
var myLoader:Loader = new Loader();
var url:URLRequest = new URLRequest("jenissendi.swf");
myLoader.load(url);
addChild(myLoader);

now, what should i do to this code? can someone give me a simple step, because i am still newbie here

thanks.

2
next scene here means next scene in the main .fla fileMaulana Ilham
did you get it figured out?BadFeelingAboutThis

2 Answers

0
votes

The thing about Loader class that can confuse beginners is that events, related to loading process, are dispatched from a LoaderInfo object attached to Loader rather than Loader itself.

stop();

var myLoader:Loader = new Loader;
var url:URLRequest = new URLRequest("jenissendi.swf");

myLoader.contentLoaderInfo.addEventListener(Event.INIT, onInit);
myLoader.load(url);

addChild(myLoader);

function onInit(e:Event):void
{
    nextScene();
}
0
votes

First, you will need to listen for when your content has completed it's load - as you won't know how many frames the content has until then.

Then, you need to figure out when the timeline of that loaded content has finished playing.

Here is a code example with comments explaining what's going on.

stop();
var myLoader:Loader = new Loader();
var url:URLRequest = new URLRequest("jenissendi.swf");

//before you load, listen for the complete event on the contentLoaderInfo object of your loader
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, contentLoaded, false, 0, true);

myLoader.load(url);
addChild(myLoader);

//this function runs when the content is fully loaded
function contentLoaded(e:Event):void {
    var loadedSwf:MovieClip = myLoader.content as MovieClip; //this is the main timeline of the loaded content
    loadedSwf.addFrameScript(loadedSwf.totalFrames - 1, contentFinished);
    //the line above tells the movie clip to run the function 'contentFinished' when it reaches the last frame.
}

//this function runs when the loaded content reaches it's last frame
function contentFinished():void {
    //clean up to avoid memory leaks
    removeChild(myLoader);
    loadedSwf.addFrameScript(loadedSwf.totalFrames - 1, null);

    nextScene();
}

addFrameScript has a few nuances. First, is that it reads frame numbers as 0 based. So that means the first frame is frame 0. That's why you subtract 1 from the totalframes to get the last frame. Second, addFrameScript is an undocumented feature - which means it may on some future flash player/AIR release not work anymore - though that's very unlikely at this point. It's also very important to remove your frame scripts (by passing null as the function) to prevent memory leaks.