View Full Version : Making calculations in Flash MX
nicolegoogh
08-04-2003, 03:24 AM
The code below works the percentage bar on my preloader. However I have two preloaders, one to load the main site and one to load the portfolio. My problem with this code is that it calculates the whole movie rather than the first 170k which I want it to. I've tried making moviesize = 170; and I've tried moviePercent = 170/100; but that doesn't work. Does anyone know how to write this correctly in Flash MX?
FRAME 1.
movieSize = this.getBytesTotal();
moviePercent = movieSize/100;
sliderMove = _root.redBar._x;
percentMove = _root.percentContain._x;
FRAME 2.
current = this.getBytesLoaded();
_root.percentContain.percent = Math.round(current/moviePercent);
_root.redBar._x = sliderMove+_root.percentContain.percent;
_root.percentContain._x = percentMove+_root.percentContain.percent;
Thank you so much for your help!:confused:
simontheak
08-04-2003, 05:00 AM
In order to get your preloader working for your second movie clip, couldn't you just use:
portfolioSize=portfolioMC.getBytesTotal();
where portfolioMC is the Movie Clip containing your portfolio. That way you should just be able to use the same code as you do for your original preloader. It's just that you're telling Flash to focus in on one thing as opposed to the whole movie
nicolegoogh
08-04-2003, 09:13 PM
Is this right because it's still not working. The scene I'm trying to load is called "Photos". Is there a way of just setting the movieSize = 170k or doing the calculation and having moviePercent = 170/100?
movieSize = Photos.getBytesTotal();
moviePercent = movieSize/100;
sliderMove = _root.redBar._x;
percentMove = _root.percentContain._x;
Thanks for all your help! How do I start to learn the syntax of actionscript? Do you recommend a book or just picking it up as you go?
simontheak
08-05-2003, 05:04 AM
Well 2 things strike me straight away.
1. I don't think you can preload scenes (somebody stop me if I'm wrong!). The scenes are dealt with as part of the overall movie. What would be a better idea is to put "Photos" into a seperate movie clip and load that on to the stage when you need it. That way you can add a preloader to the beginning of it just like you would any other timeline.
2. The code you're using in your actionscript is a little bit off. The _x property you're using in the last 2 lines will only get the x position of redbar on the stage. You want to use _xscale, as that will increase the length of your bar. You can use some code like this:
total=this.getBytesTotal();
loaded=this.getBytesLoaded();
percent = int((total/loaded)*100) // works out the percentage loaded as a whole number (Integer)
loaderbar._xscale=percent // scale the length of your loader bar MC in accordance to the percentage of the movie loaded
3. As far as books go, there are loads of different posts on that. Try doing a search for all of them, but here's a couple that I've contributed to, to start you off!!
- http://www.actionscript.org/forums/showthread.php3?s=&threadid=18010&highlight=Books
- http://www.actionscript.org/forums/showthread.php3?s=&threadid=19530&highlight=Books
nicolegoogh
08-05-2003, 08:36 PM
Thanks for all your help! I'm starting to get a better idea of how Flash works. When people make large sites are all the sections scenes in the one swf file or are they swf files being loaded by the main swf file? And if they are all separate swf is this so the user only loads what they want to see and in the order they want to see it?
Cheers!
Nicole
smoke10010
08-06-2003, 04:36 AM
you can load a specific scene but I don't see why you want to...
generally a flash site is done through a template that loads multiple swf files upon navigating. Yes this is because the generally flash sites can be huge in size.. When I first started I tried putting all the flash into 1 site.. the filesize quickyl became about 3mb imagine trying to imagining yourself sitting through 3mb of download to see a site you might want to navigate through it's annoying.. usually you'll have the base which loads navigation when then loads the sections depends on where someone wants to go.. pictures and everything are also usually best kept out of flash since they also add to filesize... Even through it's semi-understandable to have larger sites when they're flash it's still better for everyones sake to keep it as small as you can.
FRAME 1.
movieSize = this.getBytesTotal();
moviePercent = movieSize/100;
sliderMove = _root.redBar._x;
percentMove = _root.percentContain._x;
depending on where you put the code
movieSize = this.getBytesTotal();
Which i'm guessing is on the ROOT timeline.. you are telling flash that you want the bytesize for ROOT which is the whole movie. if you want a specific section you need to target the instance..
In your preloader I might have missed something I kinda of skimmed through it I don't see a get bytes loaded in there
_root.getBytesLoaded();
try something like this
total_bytes = _root.getBytesTotal();
loaded_bytes = _root.getBytesLoaded();
remaining_bytes = total_bytes - loaded_bytes;
percent_done = int((loaded_bytes / total_bytes)*100);
_root.bar.gotoAndStop(percent_done);
then you can set some code in frame 2 like this
if (loaded_bytes == 170k.. OR loaded_bytes) {
gotoAndPlay("movie"
} else {
gotoAndPlay(1);
}
I guess if you have anymore questions which you probably will make another post...
simontheak
08-06-2003, 04:58 AM
No problem nicolegoogh.
Give us a shout if you've got any more problems!
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.