A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: simple concept I can't figure...

  1. #1
    Spit
    Join Date
    Oct 2008
    Location
    Philly, PA
    Posts
    51

    simple concept I can't figure...

    Hello,

    I have CS3 fro starters. My problem is, there's a concept in AS2 that deals with variables that's stumping me.

    Lets say I have a bunch of variables set with values:

    Ex:

    Time_1 = 200;
    Time_2 = 229;
    Time_3 = 250;
    Time_4 = 280;

    Now I just want to say subtract a value from all of these to populate text areas:

    Ex:

    -14 from all of these.


    Instead of making a separate equation for all of these, how would I write 1 equation in a function that would do this for me so that all of the variables take turns using the equation?

    It has something to do with setting the individual variables equal to a different variable in the equation that takes turns being equal to each of the variables...right?

    thanks!

    Spit
    Last edited by SpitSpitSpitty; 08-21-2010 at 08:31 PM.

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    Actionscript Code:
    function retract14 (what){
    return what - 14;
    }
    To target all variables, you can use a for or for in loop.

    gparis

  3. #3
    Spit
    Join Date
    Oct 2008
    Location
    Philly, PA
    Posts
    51
    Sorry, but I don't understand how any of the code you just put up exactly relates/or would relate to the variables if they were Time_1 through Time_4.

    I've been messing with the for loop and have gotten it to set a variable = to 1 through 4. I even got it to = to "Time_1" through "Time_4", but not to there values. So I still don't understand how to make it apply to all of my variables values.

    I want the function to basically use "Time_" as the default part of it that will join the variable numbers in the for loop to it, so that it looks for the value of "Time_1" the first time it runs, then "Time_2" etc... I'm just not understanding how to make it check each one of these with this for loop.

    Thanks for you time!

    Spit

  4. #4
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    If you want a delay in between, you don't need a for loop, just use setInterval. And in doing so another function

    Actionscript Code:
    Time_1 = 200;
    Time_2 = 229;
    Time_3 = 250;
    Time_4 = 280;

    function retract14 (what){
    return what-14;
    }
    var count:Number = 0;
    function updateVars() {
    _root["Time_"+count]= retract14(_root["Time_"+count]);
    count==4?clearInterval(intervalID):count++;

    }

    intervalID = setInterval(updateVars,1000);

    Not tested but it should work.

    gparis

  5. #5
    Spit
    Join Date
    Oct 2008
    Location
    Philly, PA
    Posts
    51
    Thank you so much! I'll let you know if it works once I integrate it.

    Spit

  6. #6
    Spit
    Join Date
    Oct 2008
    Location
    Philly, PA
    Posts
    51
    This is really awesome! I Can't thank you enough! All of this code makes perfect sense to me and has my mind brewing with more great ideas on how to use it. Never knew about setInterval, I could have used this a log time ago.

    You Rock!

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