[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details

How to build new array from _width values in loop?

Asked by BentoBenji in Adobe Flash, Scripting Languages

Tags: Macromedia/Adobe, Flash, 8, ActionScript

Ok, here goes.

I have a bunch of thumb mc instances on my stage, using the same mc symbol. They're all sized differently so the widths(which are same as heights) vary.

I want to be able to access their width value from an array independent of all the scaling I'm doing with rollovers. That is, I need to have each mc instance's original width accessible from anywhere in my code.

The simplest way to do this is to hard code an array, like:

var Twidth:Array = new Array();
Twidth[0] = "33";
Twidth[1] = "45";
Twidth[2] = "45";
Twidth[3] = "45";
Twidth[4] = "33";

But since I have 22 thumbs and several portfolios, and want the option of changing their original sizes on the stage, I want to create the array above on the fly using information in a loop. For instance, I already have a loop in a function called generateThumbs(). Here's what I've tried:

    for (var i = 0; i<total; i++) {
    Twidth = new Array();
    Twidth[i] = this["thumb_mc"+i]._width;
    trace(Twidth[i]);

    // OR
    var Twidth:Array = this["thumb_mc"+i]._width;
    trace(Twidth);
    }

trace results:
33
45
45
45
33

for trace on the first method, replacing 'i' with the key I want (Twidth[2]):
undefined
undefined
45
undefined
undefined

As you can see, this gives me non-indexed non-delimited value for the whole loop (the actual in my real movie is 22). There's no length or array because its actually just one value. Entering a number in the key will display a bunch of undefined with one defined. I have no way of extracting that one key without getting all the other undefined values.

Basically, my question is: How do I put 'this["thumb_mc"+i]._width' values into a loop with each value indexed for the rest of my functions to access?

thanks!
 
Related Solutions
Keywords: How to build new array from _width v…
 
Loading Advertisement...
 
[+][-]09/09/07 12:43 PM, ID: 19857766Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/09/07 02:33 PM, ID: 19858016Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/09/07 06:01 PM, ID: 19858466Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/10/07 05:24 AM, ID: 19860373Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091118-EE-VQP-93 / EE_QW_2_20070628