Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Sum an Array for Preloader of Images

Posted on 2005-03-17
5
Medium Priority
?
149 Views
Last Modified: 2012-05-05
onClipEvent(load) {

myResult=0;
sumArray = new Array();

}
onClipEvent(enterFrame) {
for (d=0; d < _root.numberOfQuestions; d++) {
this["imageBytesLoadedSum"+d] = _root.score.imageHolder["image" + d].jpg.getBytesLoaded();
sumArray[d] = this["imageBytesLoadedSum"+d];

myResult += sumArray[d];
trace(myResult);  //  Traces as NaN
trace(sumArray[d]) // Report the bytes loaded okay.
}

}

In the above, I expected "myResult"  to add up the contents of the array called sumArray. Instead, it report NaN.  How can I sum the bytesloaded in the above scenario?  Thanks.

0
Comment
Question by:Aspirin99
  • 3
  • 2
5 Comments
 
LVL 18

Accepted Solution

by:
Billystyx earned 2000 total points
ID: 13566916
what is supposed to be in you sumArray?
It looks like nothing is there. Is this the line that is meant to add to the array?
sumArray[d] = this["imageBytesLoadedSum"+d];
.
You add to an array by myArr.push(value);

getBytesLoaded increments as the movieclip loads - why are you summing it?
Billystyx
0
 
LVL 1

Author Comment

by:Aspirin99
ID: 13567011
for (d=0; d < _root.numberOfQuestions; d++) {
this["imageBytesLoadedSum"+d] = _root.score.imageHolder["image" + d].jpg.getBytesLoaded();
sumArray[d] = this["imageBytesLoadedSum"+d]; //<--------------------- Right here I'm grabbing the bytes total.

Gettting the bytes total is working fine. I don't want to push to the array because that would create a new array item each push. I only want as many array items as I indicate in the for loop. As to what I'm summing it, I want to add the bytes total for all the images I'm loading. The code has to accomodate a different number of images each time.
0
 
LVL 1

Author Comment

by:Aspirin99
ID: 13567382
I figured it out.

if (typeof(sumArray[d])=="number") {
myResult = myResult + sumArray[d];
}
0
 
LVL 18

Expert Comment

by:Billystyx
ID: 13567947
Good work and good luck!
Billystyx
0
 
LVL 1

Author Comment

by:Aspirin99
ID: 15411034
I awarding points to Billystyx just to close this - and because he's helped me a few times.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
Suggested Courses

564 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