Jump to content
GreenSock

Skeenee

ProgressHandler: how to make a timeline based preloader

Recommended Posts

I am trying to make a timeline based animated preloader: I made a 100 frame animation, and would like progressHandler function to define the frame on my timeline. The preloader works perfectly, but i am having issue with the progressHandler function.

 

I am using:

 

 

private function progressHandler(event:LoaderEvent):void{

//trace("progress: " + Math.round(event.target.progress*100));

MovieClip(projectLoader).gotoAndStop(Math.round(event.target.progress*100));

 

 

}

 

The movieClip "projectLoader" is the 100 frames preloader animation.

 

 

Issue: the projectLoader animation is stuck on frame 1 and does not increase with the progressHandler.

 

I am sure I am making a stupid mistake, but i am quite new to this so go easy on me :P

 

Thanks for your help

Link to comment
Share on other sites

What code are you using to add the progress listener? I didn't see that anywhere. Is the function not getting called at all? (can you trace() anything?)

Link to comment
Share on other sites

just saw that GreenSock replied. yeah, please confirm that the trace is working and you can grab the progress. If so, it just means you aren't targeting your projectLoader clip properly. I would think you would also be getting a run time error.

Link to comment
Share on other sites

The trace is indeed working, i can grab the progress, and i don´t get any run time error. Loading wise everything works perfectly.

 

this is the complete code i am using:

 

 

package
{

import flash.display.MovieClip;
import flash.events.*;
import flash.display.*;
import flash.utils.*;
import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.*;
import com.greensock.loading.display.*;








public class Preloader extends MovieClip {
private var projectLoader:ProjectLoader = new ProjectLoader();
private var bg:BG = new BG();
public var mainLoader:SWFLoader = new SWFLoader("project.swf",{name:"project",onProgress:progressHandler,onComplete:completeHandler,  autoplay:true,container:this,x:0,y:0});

public function Preloader() {
this.addEventListener(Event.ADDED_TO_STAGE, addedToStage);
}


private function addedToStage(event:Event):void {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;

stage.addEventListener(Event.RESIZE, resizeListener);

preload();
positionElements();
}


private function resizeListener(e:Event):void {
positionElements();
}

private function positionElements():void {
projectLoader.x = stage.stageWidth / 2;
projectLoader.y = stage.stageHeight / 2;

bg.width = stage.stageWidth;
bg.height = stage.stageHeight;

}

private function preload():void {
addChild(bg);
addChild(projectLoader);

mainLoader.load();
}

private function progressHandler(event:LoaderEvent):void{
trace("progress: " + Math.round(event.target.progress*100));
MovieClip(projectLoader).gotoAndPlay(Math.round(event.target.progress*100));


}

private function completeHandler(event:LoaderEvent):void{
trace(event.target + " complete");
removeChild(projectLoader);
removeChild(bg);

this.removeEventListener(Event.ADDED_TO_STAGE, addedToStage);
stage.removeEventListener(Event.RESIZE, resizeListener);
}

private function errorHandler(event:LoaderEvent):void{
trace("error occured with " + event.target + ": " + event.text);
}

}//class

}//package

 

 

Thanks for your help, i really appreciate

Link to comment
Share on other sites

Maybe it's a problem with your MovieClip. I noticed you're doing gotoAndPlay() instead of gotoAndStop(), so you should fix that but it wouldn't explain why it's not moving at all. Are you sure that you've got 100 frames on that MovieClip? Feel free to post a sample FLA if you still need some help.

 

And ProjectLoader does extend MovieClip, right? It's a little tough to troubleshoot when we can't check all this stuff (which is why the sample files would help). I'm sure there's a good explanation - it's just not obvious from your code.

 

Oh, and I noticed that you're creating your mainLoader SWFLoader instance right away, even before the constructor, and you're referencing methods and "this" in the vars object which may very well work, but it's a bit risky in my view. I'd recommend creating that in your constructor or in some other method to ensure that everything gets instantiated in the correct order. Again, it may work as-is just fine and I doubt this has anything to do with your original issue.

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.
×