-
Senior Member
[mx]A more eloquent way to code.
Hi,
I have been working on a way to make a preloader for a number of clips being loaded into a main clip.
I have got it to work with the following code (this is the relevant snippet from the main code which is included below as an attachment):
code: _root.holdtext_mc.onEnterFrame = function() {
moonAmount = Math.floor((ticking_array[0].getBytesLoaded()/1024));
magAmount = Math.floor((ticking_array[1].getBytesLoaded()/1024));
empAmount = Math.floor((ticking_array[2].getBytesLoaded()/1024));
inAmount = (moonAmount+magAmount+empAmount);
this.read_txt.text = inAmount;
};
This all works fine but I was after a more eloquent way of going about it & so tried:
code: _root.holdtext_mc.onEnterFrame = function() {
for (i in _root.ticking_array) {
tot_array.push(Math.floor((_root.ticking_array[i].getBytesLoaded()/1024)));
}
for (i in _root.tot_array) {
am += _root.tot_array[i];
trace(am);
}
But this gives some really wild figures.
I think I'm on the right track but am just getting the designation of the bytesLoaded code wrong
Anyone any help please
Last edited by pup100; 01-04-2008 at 08:38 AM.
You will know everything when you know you never will.
-
Registered User
hi,
Take a look at this simple example:
code:
var myArray = new Array(1, 2, 3, 4);
var total = 0;
for (n in myArray)
{
total += myArray[n];
}
trace(total); // 10
-
Are you creating the variable am to begin with? If you don't define a variable by doing am=0 then anything else will be am+=1 or undefined+=1 == undefined. Be sure to make am = 0 before trying to add to it.
-
Senior Member
Thank you both for your input.
Nunomira- Problem I have got is that all of this is wrapped up in an onEnterFrame event, so although I would say your code would work wrapping it in the event wacks the numbers out.
This is where I'm at as of this morning.
code: _root.holdtext_mc.onEnterFrame = function() {
for (i in _root.ticking_array) {
_root.tot_array.push(Math.floor((_root.ticking_arr ay[i].getBytesLoaded()/1024)));
for (i in _root.tot_array) {
am += _root.tot_array[i];
}
}
You will know everything when you know you never will.
-
Registered User
Depending on what you want to do, initialize the variable (total, in my example), inside the onEnterFrame.
code:
var myArray = new Array(1, 2, 3, 4);
this.onEnterFrame = function()
{
var total = 0;
for (n in myArray)
{
total += myArray[n];
}
trace(total);// 10
};
Tip:don't use _root, use relative paths instead.
-
Senior Member
Sorry to take a while to get back to you on the nunomira, but no joy
Latest post on it, shows where i'm at http://board.flashkit.com/board/show...28#post3815828
Thanks any way for your input.
You will know everything when you know you never will.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|