开发者

gotoAndPlay frames based on the percentage of an AS3 preloader's progress

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 hel开发者_运维知识库p is greatly appreciated.


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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜