views:

306

answers:

1

Hi, i followed this excellent as3 preloader tutorial, and below is the code i have so far.

var l:Loader = new Loader();
l.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loop);
l.contentLoaderInfo.addEventListener(Event.COMPLETE, done);
l.load(new URLRequest("content.swf"));

function loop(e:ProgressEvent):void
{
var perc:Number = e.bytesLoaded / e.bytesTotal;
percent.text = Math.ceil(perc*100).toString();
trace("loading...");
}

function done(e:Event):void
{
removeChildAt(0);
percent = null;
addChild(l);
trace("done!");
}

this loads the main content perfectly. displaying the percent of the loading progress.

now i'd like to take it a step farther. my goal is to have 3 images in 3 different frames on a timeline and have one become visible on 25% done, the second on 50% done, and the final image on 75% done.

i'm assuming i need to add some if statements but i'm having trouble figuring out what the syntax would be to listen for the percentage for flash to know what frame to move to.

thanks for reading and any help is greatly appreciated.

A: 

Add a movie clip called movieClipWithImages with the 3 images, one on each frame, to the stage, and then use the following code.

function loop(e:ProgressEvent):void
{
  var perc:Number = e.bytesLoaded / e.bytesTotal;
  percent.text = Math.ceil(perc*100).toString();
  trace("loading...");
  movieClipWithImages.gotoAndStop(Math.floor(perc*3/100)+1);
}
Marius
Thanks a lot Marius! just one question, should the images be on 3 frames in the main timeline or within the movieclip?
measles
never mind, i sorted it out. thank you so much for your help. i had to add the movie clip to the main time line with 3 frames inside like you said, but it took me a couple tries to figure out that every frame needed a stop(); on it (on the main timeline and inside the movie clip) thanks again Marius!
measles