Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Adapt a Preloader to Use with a Movieclip? 2

Status
Not open for further replies.

flasher40

Technical User
Apr 13, 2007
80
US
Hi,

I’ve successfully used a preloader that I built from a tutorial on the internet. In the movie where it is functioning correctly, all the actions are on the main timeline.

But now I’m trying to use the same preloader for a movie where the main action, instead of being on the main timeline, is a movieclip of about 60 frames that is controlled by buttons on the main timeline. When I tried using the same preloader setup as I had used previously, it didn’t work. I’ve tried various changes, but my limited ActionScript knowledge isn’t up to the task.

For the preloader in its original configuration, two layers are added to the main timeline, each having five frames. Five empty frames are added to each of the other layers, so that their starting points line up where the preloader layers’ frames end. The preloader layers are:

Actions Layer: Five empty keyframes, with the code gotoAndPlay(1); in the fifth frame (so that the preloader loops until the loading is completed).

Preloader Layer: The first five frames are keyframes that have the “Loading” message. The sixth frame is a keyframe labeled “start.” Following the sixth keyframe are a bunch of empty frames that span the length of the main timeline. At the end of this layer is a keyframe labeled “end.” The first keyframe of this layer has the code:

ifFrameLoaded ("end") {
gotoAndPlay ("start");
}

So, my question is, can I adapt the script so that it will work in a situation where the main action is not on the main timeline but is, instead, a movieclip? If so, how would the code or setup be changed to do that? Or is a completely different approach needed?

Thanks!
Bill
 
You can do this in one frame.

Put "stop();" in the first frame of your MovieClip.

Place the MovieClip on Stage. Then name it - let's name it "mc" for now.

The script in the main timeline:
Code:
stop();
onEnterFrame = function ():Void {
	if (mc.bytesLoaded>=mc.bytesTotal) {
		mc.play();
		delete onEnterFrame;
	}
};

Kenneth Kawamoto
 
I'm using Flash 8 Professional. I'll look for a more up-to-date preloader on the internet.

Bill
 
Sorry I posted inaccurate code - in your case this should do it:
Code:
stop();
onEnterFrame = function ():Void {
	if (this.getBytesLoaded()>=this.getBytesTotal()) {
		gotoAndStop(_currentframe+1);
		delete onEnterFrame;
	}
};

Kenneth Kawamoto
 
That did the job! Thanks, Ken. You're the greatest!

Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top