Jump to content
Search Community

Synchronise oncomplete events at load

carlosfandang test
Moderator Tag

Recommended Posts

Hi, just discovered Loadermax - very nice thank you. I have a snag I can't seem to get around (mainly because my knowledge is still limited). The scenario is this:

 

1) I have a number of timeline animations for each menu button - each has an onComplete event to load an external swf - "addChild(Loader.content);"

2) I am using the onComplete in my animation timeline because the animation needs to finish first, then load the swf (interim solution).

3) The external swf's (e.g "First.swf") run their own animations BEFORE they then load another swf into themselves ("external subwindow") - these are 3rd party swf's including highslide photo gallery and coverflow gallery. I accept it's clunky, but I was trying to minimise initial preload and lack of skill!!

 

Right that aside, all that's important is that "First.swf" preloads (3rd party apps take care of their own loading).

 

4) Thus, I have 2 oncomplete events that I need to synchronise. How do I ensure that "timeline1" ONLY runs addChild IF "FirstLoader" has actually completed its loading of "First.swf". So in very basic terms and stripped down, my code is:

 

var timeline1:TimelineMax = new TimelineMax({onReverseComplete:triggerQueue, paused:true})
timeline1.insertMultiple([
new TweenMax(whatever}}),
new TweenMax(whatever, 2, {blurFilter:{blurX:3, blurY:3, quality:2}, onComplete:finish}),
], 0);
//

function finish(){
FirstLoader.load(true);
addChild(FirstLoader.content);
} 

 

My Loadermax is set up as this:

 

FirstLoader = new SWFLoader("First.swf", {name:"First", x:0, y:0, estimatedBytes:920000, onComplete:FirstcompleteHandler});
}

function FirstcompleteHandler(event:LoaderEvent):void {
Object(FirstLoader.rawContent).Firststart(); //that gets my external timeline running in First.swf
}

function FirstClick(MouseEvent:Event):void {
RunTimelineAnimation(); //runs timeline1
}

 

Any help much appreciated, I'm not very good with IF statements and listeners!!

 

Thanks so much in advance

Link to comment
Share on other sites

So you're waiting to subload other swfs until your menu animation finishes? You're welcome to do that, but it seems awefully wasteful - one of the nice things about LoaderMax is that you can easily have stuff loading in the background and then grab it when you need it. And of course you can prioritize() a specific asset too, like if swfs for menu items 2 is loading but the user clicks on menu item 5, you can just prioritize that one and it'll suspend loading the swf for menu item 2 and instead start doing menu item 5.

 

Anyway, to answer your question, you can tell if a particular loader is done in several different ways:

 

1) If its "progress" property is 1, it's done.

 

-OR-

 

2) If its "status" property is LoaderStatus.COMPLETE (2), it's done.

 

So you could:

 

if (FirstLoader.progress == 1) {
   addChild(FirstLoader.content);
}

 

But the problem is that if it is NOT loaded yet, what do you plan on doing? You could, of course, add a COMPLETE event listener so that you're notified when it's done:

 

FirstLoader.addEventListener(LoaderEvent.COMPLETE, completeHandler);
function completeHandler(event:LoaderEvent):void {
   trace(event.target + " is done!");
   event.target.removeEventListener(LoaderEvent.COMPLETE, completeHandler);
   //do stuff here.
}

 

Hope that helps.

Link to comment
Share on other sites

Thanks for the quick response, I agree I am probably doing it wastefully - and through lack of expertise!!

 

I think I need to re-think the loading process. Currently, the external swf's only start loading on a menu click. I think therefore, I should have everything loading at the beginning, and have a look at prioritising.

 

Thanks, I'll have to try and get to grips with the queue mechanism.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...