Solved

Flash 5 Preloader Question: How to run an MC in a preloader in proportion to loading?

Posted on 2004-10-20
22
322 Views
Last Modified: 2008-02-01
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!
0
Comment
Question by:geod100
  • 10
  • 9
  • 3
22 Comments
 
LVL 16

Accepted Solution

by:
vickerleung earned 500 total points
ID: 12366777
qeod100,

I am not sure whether Flash 5 have onClipEvent and getbytesloaded
Please check, if no, do let me know

The method is not that difficult actually.

In your mc, insert the stop(); actionscript in the first frame;

And then drag your mc on stage.
Name the mc like abcd
Add the following actiosncript to your mc

onClipEvent (enterFrame) = function ()
{
     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);
}

That's it!!
Vicker
0
 
LVL 16

Expert Comment

by:vickerleung
ID: 12366788
O~~~ sorry
that should be

onClipEvent (enterframe)

only~ :p

sorry for that
0
 
LVL 16

Expert Comment

by:vickerleung
ID: 12366830
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
0
 
LVL 6

Expert Comment

by:nishasrilankan
ID: 12367048
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/totalBytes)*16);
_root.preloader.gotoAndStop(numcurrentFrame);
gotoAndPlay(2);
}


0
 

Author Comment

by:geod100
ID: 12372666
Unfortunately, this is all Flash MX -- I needed a Flash 5 solution....
0
 
LVL 16

Expert Comment

by:vickerleung
ID: 12373149
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
0
 

Author Comment

by:geod100
ID: 12373868
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?
0
 

Author Comment

by:geod100
ID: 12373931
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).
0
 

Author Comment

by:geod100
ID: 12374253
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.
0
 

Author Comment

by:geod100
ID: 12377185
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.
0
 
LVL 16

Expert Comment

by:vickerleung
ID: 12377283
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
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 6

Expert Comment

by:nishasrilankan
ID: 12378203
Please try first...can you say one function in my code to not working with Flash 5?
0
 

Author Comment

by:geod100
ID: 12382657
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.
0
 

Author Comment

by:geod100
ID: 12382798
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.
0
 
LVL 16

Expert Comment

by:vickerleung
ID: 12382899
geod100,
use

_root.abcd.next ();

instead~

Gd luck

Vicker
I think is the nextFrame problem,
0
 
LVL 16

Expert Comment

by:vickerleung
ID: 12382904
Sorry typing error

repost

geod100,
I think is the nextFrame problem,

use

_root.abcd.next ();

instead~

Gd luck

Vicker
0
 

Author Comment

by:geod100
ID: 12382929
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.
0
 
LVL 16

Expert Comment

by:vickerleung
ID: 12383034
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
0
 

Author Comment

by:geod100
ID: 12383072
Nope, doesn't work -- preloader remains frozen on first frame, and then movie loads.

Thank you, though.
0
 
LVL 16

Expert Comment

by:vickerleung
ID: 12383287
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
0
 
LVL 16

Expert Comment

by:vickerleung
ID: 12383428
O sorry geod100
gotta sleep
help u tmr~ :p
0
 
LVL 6

Expert Comment

by:nishasrilankan
ID: 12397772
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
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now