geod100
asked on
Flash 5 Preloader Question: How to run an MC in a preloader in proportion to loading?
Here's the question, in a nutshell:
I designed a nifty little MC to use as a preloader for a movie. Basically, it's a watering can that tips over and then pours out water on a flower pot. The MC is simple: straight time line tweening animation.
Now, my question is this -- I know how to make fairly decent preloaders, with progress bars, etc., but I'm wondering if it is possible to:
1. Drop the MC into Frame 1 of the main move
2. Include an action script (flash 5, please) that would run the MC, once, not looping, smoothly and in proportion the the loading of the movie. In short, like a progress bar, but it's a watering can tipping over. The MC itself is about 16 frames.
Make sense? This is for an on-going project, so I'd appreciate your help!
I designed a nifty little MC to use as a preloader for a movie. Basically, it's a watering can that tips over and then pours out water on a flower pot. The MC is simple: straight time line tweening animation.
Now, my question is this -- I know how to make fairly decent preloaders, with progress bars, etc., but I'm wondering if it is possible to:
1. Drop the MC into Frame 1 of the main move
2. Include an action script (flash 5, please) that would run the MC, once, not looping, smoothly and in proportion the the loading of the movie. In short, like a progress bar, but it's a watering can tipping over. The MC itself is about 16 frames.
Make sense? This is for an on-going project, so I'd appreciate your help!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
O sorry once more =.=|||
I missed the braces...
maybe I repost the code
onClipEvent (enterFrame)
{
progress_percentage = Math.round (_root.getBytesLoaded () / _root.getBytesTotal () * 100);
frame_target = Math.round (progress_percentage * 16); // in here 16 is your mc total frame number
_root.abcd.gotoAndStop (frame_target);
}
To apologize, I have uploaded a sample to:
http://www.geocities.com/vickerleung/loader_animation.zip
I have enlarge the file so that you can feel the loading sequence.
Further, the FLA is saved in MX format... Hope Flash 5 can open
If not, you still can open the swf file, it is in flash player 5 format.
Cheers :)
Vicker
I missed the braces...
maybe I repost the code
onClipEvent (enterFrame)
{
progress_percentage = Math.round (_root.getBytesLoaded () / _root.getBytesTotal () * 100);
frame_target = Math.round (progress_percentage * 16); // in here 16 is your mc total frame number
_root.abcd.gotoAndStop (frame_target);
}
To apologize, I have uploaded a sample to:
http://www.geocities.com/vickerleung/loader_animation.zip
I have enlarge the file so that you can feel the loading sequence.
Further, the FLA is saved in MX format... Hope Flash 5 can open
If not, you still can open the swf file, it is in flash player 5 format.
Cheers :)
Vicker
And dont forget to include gotoAnd.play or gotoAndStop for the main movie...otherwise it will stop at the 16th frame of the preloader..or..I can suggest like this..
put the preloader(mc_preloader) MC in frame 1 and put the main movie in frame 5(or something)
inserrt >Movieclip>name it as script
put the script on to a new layer on the main time line (Instance name "script")
//in the first frame of the script put this code..
var totalBytes ;
var loadedBytes ;
//in the third frame of the script put this code..
totalBytes = _root.getBytesTotal();
loadedBytes = _root.getBytesLoaded();
if(totalBytes==loadedBytes ){
_root.gotoAndPlay(5); //or you can use _root.gotoAndStop() depending on the situation
}
else{
numCurruntFrame = Math.ceil((loadedBytes/tot alBytes)*1 6);
_root.preloader.gotoAndSto p(numcurre ntFrame);
gotoAndPlay(2);
}
put the preloader(mc_preloader) MC in frame 1 and put the main movie in frame 5(or something)
inserrt >Movieclip>name it as script
put the script on to a new layer on the main time line (Instance name "script")
//in the first frame of the script put this code..
var totalBytes ;
var loadedBytes ;
//in the third frame of the script put this code..
totalBytes = _root.getBytesTotal();
loadedBytes = _root.getBytesLoaded();
if(totalBytes==loadedBytes
_root.gotoAndPlay(5); //or you can use _root.gotoAndStop() depending on the situation
}
else{
numCurruntFrame = Math.ceil((loadedBytes/tot
_root.preloader.gotoAndSto
gotoAndPlay(2);
}
ASKER
Unfortunately, this is all Flash MX -- I needed a Flash 5 solution....
geod100,
I am sure that Flash 5 already have getbytesloaded and getbytestotal functions
for the onclipevent, I am not sure
Okay
I provide a method that don't depend on onclipevent
First of all, prepare the animation mc,
again on frame 1 add stop ();
drag to stage and name it abcd
last frame with scene transition (i.e. something like _root.gotoAndPlay ("start_movie"))
Second, make another mc which have two frames and empty content
the first frame add the following script
progress_percentage = Math.round (_root.getBytesLoaded () / _root.getBytesTotal () * 100);
frame_target = Math.round (progress_percentage * 16); // in here 16 is your mc total frame number
_root.abcd.gotoAndStop (frame_target);
the second frame add the following
gotoAndPlay (1);
Drag this new mc on stage also
That's it!!
The logic is that the 2nd mc will loop count the percentage and control the abcd mc
Hope this time works :)
Vicker
I am sure that Flash 5 already have getbytesloaded and getbytestotal functions
for the onclipevent, I am not sure
Okay
I provide a method that don't depend on onclipevent
First of all, prepare the animation mc,
again on frame 1 add stop ();
drag to stage and name it abcd
last frame with scene transition (i.e. something like _root.gotoAndPlay ("start_movie"))
Second, make another mc which have two frames and empty content
the first frame add the following script
progress_percentage = Math.round (_root.getBytesLoaded () / _root.getBytesTotal () * 100);
frame_target = Math.round (progress_percentage * 16); // in here 16 is your mc total frame number
_root.abcd.gotoAndStop (frame_target);
the second frame add the following
gotoAndPlay (1);
Drag this new mc on stage also
That's it!!
The logic is that the 2nd mc will loop count the percentage and control the abcd mc
Hope this time works :)
Vicker
ASKER
Vicker,
This isn't clear to me. From your points above: "Last frame with scene transition (ie, something like...) -- what do you mean by this? Is this code that goes into the last frame of the MC I dragged to screen? IE, do I put this code in the last frame of the MC itself?
Ah, okay, I understand. The stop() goes in the first frame of the animation MC. I'm not sure what you mean by the second line of code, though. Can you be more specific?
This isn't clear to me. From your points above: "Last frame with scene transition (ie, something like...) -- what do you mean by this? Is this code that goes into the last frame of the MC I dragged to screen? IE, do I put this code in the last frame of the MC itself?
Ah, okay, I understand. The stop() goes in the first frame of the animation MC. I'm not sure what you mean by the second line of code, though. Can you be more specific?
ASKER
Vicker,
I tried all your steps, but it doesn't really work. Basically, the first frame of the animation MC flashes on the screen, and then it immediately jumps to the rest of the movie (the rest of the movie being a 2.6megabyte SWF that I load into frame two of this movie).
I tried all your steps, but it doesn't really work. Basically, the first frame of the animation MC flashes on the screen, and then it immediately jumps to the rest of the movie (the rest of the movie being a 2.6megabyte SWF that I load into frame two of this movie).
ASKER
Okay, here's what I'm getting: your script jumps the animation MC from the first frame to the last frame, but it doesn't *play* the tweened frames in between.
ASKER
I guess I should post this question again -- all I've gotten so far is inadequately commented good that, well, simply does not work...and no responses to my follow-up questions.
geod100,
O~~ at least you know that Flash 5 have that getBytesTotal and getBytesLoaded functions,
sorry for being late reply, cause I am too tired and gone to sleep XD
Okay, I am too sleepy last night that the code forget that you have to play the tweened animation. So please try the following code instead:
progress_percentage = Math.round (_root.getBytesLoaded () / _root.getBytesTotal () * 100);
frame_target = Math.round (progress_percentage * 16); // in here 16 is your mc total frame number
if (_root.abcd._currentframe < frame_target)
{
_root.abcd.nextFrame ();
}
CAUTION: I am not sure if in Flash 5, it is called abcd.next (); instead
Cheer up friend~~!!
Vicker
O~~ at least you know that Flash 5 have that getBytesTotal and getBytesLoaded functions,
sorry for being late reply, cause I am too tired and gone to sleep XD
Okay, I am too sleepy last night that the code forget that you have to play the tweened animation. So please try the following code instead:
progress_percentage = Math.round (_root.getBytesLoaded () / _root.getBytesTotal () * 100);
frame_target = Math.round (progress_percentage * 16); // in here 16 is your mc total frame number
if (_root.abcd._currentframe < frame_target)
{
_root.abcd.nextFrame ();
}
CAUTION: I am not sure if in Flash 5, it is called abcd.next (); instead
Cheer up friend~~!!
Vicker
Please try first...can you say one function in my code to not working with Flash 5?
ASKER
Vicker, I appreciate your trying. I think you now understand the logic I'm getting it -- the for the movie to play the animation MC in proportion to the loading process.
However, now I get the error " unexpected } " refering, apparently, to the last bracket.
However, now I get the error " unexpected } " refering, apparently, to the last bracket.
ASKER
nishasrilankan,
Your script is fine -- there are no error messages whatsover. The problem is, it only plays frame one of the preloader MC and then skips over to the main movie. What I need is for the preloader MC to play smoothly, in proportion to the loading process.
Your script is fine -- there are no error messages whatsover. The problem is, it only plays frame one of the preloader MC and then skips over to the main movie. What I need is for the preloader MC to play smoothly, in proportion to the loading process.
geod100,
use
_root.abcd.next ();
instead~
Gd luck
Vicker
I think is the nextFrame problem,
use
_root.abcd.next ();
instead~
Gd luck
Vicker
I think is the nextFrame problem,
Sorry typing error
repost
geod100,
I think is the nextFrame problem,
use
_root.abcd.next ();
instead~
Gd luck
Vicker
repost
geod100,
I think is the nextFrame problem,
use
_root.abcd.next ();
instead~
Gd luck
Vicker
ASKER
Sorry, Vicker...it doesn't work. Basically, now the preloader now freezes on the first frame of the preloader MC ("abcd") and then goes on to the movie. No error message (yeah!) but it doesn't play the MC, either.
geod100,
o~~~ boy
Is really hard for me to test cause I don't have Flash 5 in hand...
sorry that I always post unwork answer
Try this
if (_root.abcd._currentframe < frame_target)
{
_root.abcd.gotoAndStop (_root.abcd._currentframe + 1);
}
Gd luck this time~~
Vicker
P.S. If you still don't work... I beg that I better find a Flash 5 and write it for you LOL
o~~~ boy
Is really hard for me to test cause I don't have Flash 5 in hand...
sorry that I always post unwork answer
Try this
if (_root.abcd._currentframe < frame_target)
{
_root.abcd.gotoAndStop (_root.abcd._currentframe + 1);
}
Gd luck this time~~
Vicker
P.S. If you still don't work... I beg that I better find a Flash 5 and write it for you LOL
ASKER
Nope, doesn't work -- preloader remains frozen on first frame, and then movie loads.
Thank you, though.
Thank you, though.
geod100,
oh my god
Maybe you do me a favour
Use this script to replace the existing one
so that I can do some debugging
if (_root.abcd._currentframe < frame_target)
{
trace ("current_frame" + _root.abcd._currentframe);
_root.abcd.gotoAndStop (_root.abcd._currentframe + 1);
}
Copy what displays in the output window to me, thx~~!!
IF!! You don't get any output... Just to remind you that
This script is attached to the 1st frame of a new mc
2nd frame is a "gotoAndPlay (1);" statement
AND THIS MC HAVE PUT ONTO THE STAGE ALSO!!
OF COURSE PUT ONTO THE STAGE'S FIRST FRAME
(or I should say the same frame as you put your animation mc)
Vicker
oh my god
Maybe you do me a favour
Use this script to replace the existing one
so that I can do some debugging
if (_root.abcd._currentframe < frame_target)
{
trace ("current_frame" + _root.abcd._currentframe);
_root.abcd.gotoAndStop (_root.abcd._currentframe + 1);
}
Copy what displays in the output window to me, thx~~!!
IF!! You don't get any output... Just to remind you that
This script is attached to the 1st frame of a new mc
2nd frame is a "gotoAndPlay (1);" statement
AND THIS MC HAVE PUT ONTO THE STAGE ALSO!!
OF COURSE PUT ONTO THE STAGE'S FIRST FRAME
(or I should say the same frame as you put your animation mc)
Vicker
O sorry geod100
gotta sleep
help u tmr~ :p
gotta sleep
help u tmr~ :p
try this...
in the preloader timeline, select all the frames and right click> convert to key frames...
then put stop(); in all the key frames....
** there might be an easy way to do this than the above
in the preloader timeline, select all the frames and right click> convert to key frames...
then put stop(); in all the key frames....
** there might be an easy way to do this than the above
that should be
onClipEvent (enterframe)
only~ :p
sorry for that