A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: For Loop and Array onPress Assignments

Hybrid View

  1. #1
    Senior Member
    Join Date
    Jan 2003
    Location
    Nebraska
    Posts
    448

    For Loop and Array onPress Assignments

    I have a script like this to assign a number of buttons to change a variable on rollover:
    code:

    for (logoCount=1; logoCount<=6; logoCount++) {

    temp = eval("logo"+logoCount);
    temp.onRollOver = function() {
    scaleFactor[logoCount] = true;
    };
    temp.onRollOut = function() {
    scaleFactor[logoCount] = false;
    };

    }



    The problem I have is the scaleFactor array gets assigned to the variable named logoCount when you rollOver any of the move clips. So rolling over logo1 makes scaleFactor[logoCount]=true, but logoCount is irrelavant after this loop is done. I want it so when you rollOver logo1 then scaleFactor[1]=true and rolling over logo2 then scaleFactor[2]=true and so on. Anyone know a looping way to do this?
    ecards - My full flash site.

  2. #2
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    To answer your immediate question, you can create your own properties on buttons. I create a property called idx and use it to store the logoCount number.

    Then, within the event handler, you can use this.property to refer to the thing you stored.

    code:

    for (logoCount=1; logoCount<=6; logoCount++)
    {
    temp = eval("logo"+logoCount);
    temp.idx = logoCount; // store it here...
    temp.onRollOver = function()
    {
    scaleFactor[this.idx] = true;
    };
    temp.onRollOut = function() {
    scaleFactor[this.idx] = false;
    };
    }



    If it were me, I probably wouldn't store scaleFactor in a separate array, but would also assign scaleafactor to each individual button, just I'm doing with idx. I like to keep stuff associated with buttons or movieclips in the buttons or movieclips.

    code:

    for (logoCount=1; logoCount<=6; logoCount++)
    {
    temp = eval("logo"+logoCount);

    temp.onRollOver = function()
    {
    this.isScaling = true;
    };
    temp.onRollOut = function() {
    this.isScaling = false;
    };
    }

    Last edited by jbum; 10-21-2004 at 05:13 PM.

  3. #3
    Senior Member
    Join Date
    Jan 2003
    Location
    Nebraska
    Posts
    448
    Oh yea duh, just a variable within the movie clip for each button. Thanks for the help man. I am actually just the opposite of you when it comes to buttons it seems. I like to keep all the events for buttons (and all code actually) in a seperate or root actionscript file so when changes need to be made to a bunch of things, I don't have to movie explore all over to find them.
    ecards - My full flash site.

  4. #4
    Senior Member
    Join Date
    Jan 2003
    Location
    Nebraska
    Posts
    448
    Or wait, I think I misread what you said wrong. By storing them in the buttons or clips, you meant in relative with your code, not actually in the actionscript for the thing?
    ecards - My full flash site.

  5. #5
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    Yes, that's right.

    I agree with you that it's best to keep all the actionscript in a single frame script so you don't go crazy having to find it.

    I just like to keep the variables associated with objects attached to those objects, rather than in separate data structures. It's an OOP thing...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center