How to create unique variables in loops? (AS2)

Hello

I wonder if it is possible to create variables in a loop for which uses an incremental number in the name of the variable.

This is the code I tried (like a long shot) but does not work:

var i: Number;
for (i = 1; i < 10; i ++) {}
var ['number' + String (i)]: number = i;
}

trace (number5);

What I'm trying to create here is a series of variables called "Number 1", "Number2" and 'Number3', etc. Is there another way to do it? I need them to be public (I think that's the word?), so they can be used elsewhere in the script.

I would appreciate any advice.

Try this:

for(var i : Number = 1; i < 10; i++)
{
    this["number" + i.toString()] = i;
}
trace(number1); // will output 1

Tags: Adobe Animate

Similar Questions

  • How to create unique variables for... in loop? (AS2)

    Hello

    I have a function onEnterFrame controlling all the movie clips in a table. The movement of each of these clips is controlled by a few variables - speed, acceleration, etc - that are changed on every enterFrame. I can't understand how to create unique variables for each element of the array. Now my variables are the same for all elements, and therefore the proposals of each video clip are the same.

    I used this code to add my video clips in the table:

    for (i = 0; i < starNumber; i ++) {}
    duplicateMovieClip (star, "star" + I, i);
    starArray.push (this ["star" + String (i)]);
    }

    I do a similar thing to create unique variables for each? Or is there something I need to do my loop (myClip in myArray) which is contained in my onEnterFrame function?

    I can post my code if that would help (65 lines).

    Creating unique variables is easy way out. Here's the modified code using unique variables that should solve your problem:

    var i: Number;

    var starArray:Array = [];

    var starArray_X:Array = [];

    var starArray_Y:Array = [];

    var mc:String;

    var scale: number;

    var speedXMod:Number;

    var speedYMod:Number;

    var starNumber:Number = 10;

    var minSize:Number = 15;

    var maxSize:Number = 80;

    var speed: number = 0.2;

    var minSpeed:Number = 0;

    var maxSpeed:Number = 1;

    for (i = 0; i< starnumber;="">

    duplicateMovieClip (star, "star" + I, i);

    starArray.push (this ["star" + String (i)]);

    }

    (MC starArray) {}

    starArray [mc] ._x = (Math.Random () * Stage.width);

    starArray [mc] ._y = (Math.Random () * Stage.height);

    scale = (minSize + (Math.Random () * (maxSize - minSize)));

    ._xscale starArray [mc] = scale;

    starArray [mc] ._yscale = scale;

    var startSpeedX:Number = ((Math.pow (-1, (Math.round (Math.random ())) * (minSpeed + (Math.Random () * (maxSpeed - minSpeed)));)))

    var startSpeedY:Number = ((Math.pow (-1, (Math.round (Math.random ())) * (minSpeed + (Math.Random () * (maxSpeed - minSpeed)));)))

    [mc] starArray_X = startSpeedX;

    [mc] starArray_Y = startSpeedY;

    onEnterFrame = function() {}

    (MC starArray) {}

    speedXMod = ((Math.random () * acceleration)-(0,5 * accélération));

    speedYMod = ((Math.random () * acceleration)-(0,5 * accélération));

    If (((Math.abs (starArray_X [mc] + speedXMod)) < maxspeed)="" &&="" ((math.abs(stararray_x[mc]="" +="" speedxmod))=""> minSpeed)) {}

    [mc] starArray_X += speedXMod;

    } else {}

    [mc] starArray_X = speedXMod;

    }

    If (((Math.abs (starArray_Y [mc] + speedYMod)) < maxspeed)="" &&="" ((math.abs(stararray_y[mc]+="" speedymod))=""> minSpeed)) {}

    [mc] starArray_Y += speedYMod;

    } else {}

    [mc] starArray_Y = speedYMod;

    }

    If (((starArray [mc]._x + starArray_X[mc]) > 0) & ((starArray [mc]._x + starArray_X[mc])))<>

    starArray [mc] ._x += starArray_X [mc];

    } else {}

    starArray_X [mc] * = - 1;

    starArray [mc] ._x += starArray_X [mc];

    }

    If (((starArray [mc]._y + starArray_Y[mc]) > 0) & ((starArray [mc]._y + starArray_Y[mc])))<>

    starArray [mc] ._y += starArray_Y [mc];

    } else {}

    starArray_Y [mc] * = - 1;

    starArray [mc] ._y += starArray_Y [mc];

    }

    }

    }

    }

  • How to create a few new loops to monitor parameters

    Hi all

    Now, I should create a few new loops to monitor the parameters, all parameters have own monitoring frequency.

    I'm trying to use to use sub VI, but the sub VI contains the infinite loop for monitoring and For just run only once, is that I just followed a values.

    My main question is this: how to create some news loops of real-time monitor parameters of different frequencys

    Without seeing your application as a whole, it is difficult to give an exact answer, but there are basically two steps (and many details):

    1. The data that you want to monitor must be accessible or published somehow like being in a global, FGV, event defined by the user, etc.

    2. Create a VI that a while loop that global readings, FGV or whatever several times. The rate at which you read is based on speed, the value can change.

    That's all - with the exception of all the details that I mentioned earlier.

    Mike...

  • How to create a dynamic text in AS2 box

    I am trying to create an area of dynamic text in AS2.  Here's what I have so far:

    Import mx.controls.TextArea;

    var myTextArea:TextArea = new TextArea();

    myTextArea.setSize (320, 240);

    myTextArea.move (10, 10);

    addChild (myTextArea);

    I have the textarea component in my library, but nothing appears on the screen.

    Help

    It sounds lie AS3 code.  Here is a link to an explanation of how to do to add components using AS2...

    http://help.Adobe.com/en_US/AS2LCR/Flash_10.0/help.HTML?content=00001820.html

  • How to create a variable

    Hello;

    I need to have a variable created to assign to a group. Is it possible to create a variable for the title of the extension of the word beep? I have the impression of seeing a syntax somewhere before (like variable@incontext:varname...), but could not understand how to create? Can you help me?

    Thank you.

    Munshar

    Check this forum thread: http://forums.oracle.com/forums/thread.jspa?messageID=9530049�

    See examples of use of variables in the various blogs here: http://blogs.oracle.com/xmlpublisher/templates/templates_rtf/xslxpath/

    Thank you
    Bipuser

  • How to create Global Variables in Essbase

    Hi gurus,

    In essbase automation, I saw generally the statement below.

    Connection $1 identified by $2 $ 3;

    and of course many other statements also.

    1. now, my question is where and how can we create the variables ($1, $2 and $3).
    2. they are Substitutinal Variables or Environment Variables.

    Pls let me know in detail how to create and define the variables above.


    I tried to create them as variables indirect in environmental assessments, but when you run the maxl order Login $1 $ 2 $3 its saying this $1.. variable cannot find etc.

    They are variable positional parameter and are passed in a maxl script, you can read all about it at:-http://download.oracle.com/docs/cd/E12825_01/epm.111/esb_techref/maxl_syntax_vars.htm#syntax_techref_proj_maxl_ddl_utils_shell_d0e227

    See you soon

    John
    http://John-Goodwin.blogspot.com/

  • How to create a variable in a mapping or process_flow

    I am creating a flow where I spend the audit_id of the mapping of a map as input parameters. How to do that.

    I thought create a variable and assign the id verification to this variable and linking this variable mapping that will become the entry for the mapping.

    Thank you

    joining this average assign the variable.

  • How to create a variable &lt; sql:setDataSource &gt; database password

    Hello

    I hope someone can enlighten me on that.

    I am trying to create a jsp page that uses JSTL to access the database. Regulations in my company requires me to use the password for the encrypted database.

    Here is an excerpt of my codes. The error I get is the password = "${decryptedPassword}" never work. However, it can print the password correctly from "System.out.println ("password is"+ decryptedPassword);" How can I pass the variable 'decryptedPassword' in the password?

    Thank you very much!

    Steve

    < %
    System.setProperty ("oracle.net.tns_admin", "C: / NEW PC BACKUP/oracle/product/10.2.0/client_1/NETWORK/ADMIN");
    System.setProperty ("oracle.net.tns_admin", "/ usr/local/oracle/10.2.0.3/network/admin");
    String decryptedPassword = "";

    Logger.info ("PLANNER_REPORT_EDOW_PSWD_ENCRYPT_KEY = <" + keyAlias + ">");
    Logger.info ("PLANNER_REPORT_EDOW_PSWD_KEY_STORE = <" + keyStoreFile + ">");

    FStore FileBasedKeyStore = new FileBasedKeyStore ("/ usr/local/scripts/keystorefile/key.dat", null);
    If (fStore == null) System.out.println ("keystore is null");
    Key = fStore.getKey ("cities") (Key);
    If (key == null) System.out.println ("key is null");
    decryptedPassword = new String (CryptoUtil.decryptFromBase64 ("OIC/n5asIP6CDR01WwvXtw is", key));
    System.out.println ("password is" + decryptedPassword);
    % >

    < sql:setDataSource var = 'snapshot' driver = "oracle.jdbc.OracleDriver" url="jdbc:oracle:thin:@cngd" user = "citosapp" password = "${decryptedPassword}" / > "

    A variable in the Java code is not available as magically as a variable JSTL. You will need to add it to the requestScope for example (request.addParameter ()).

    Your confusion is proof enough that it is a very bad idea to put the Java code in your JSP pages. It leads to unreadable code. You should learn how to combine JSPs & servlets to separate the logic of the other Java and JSP code model.

  • How to create the variable diagonal line pattern in CS6?

    Hi guys

    I'm at the edge of madness with the creation of my pattern of diagonal lines. I've tried everything I can think of, but the boss is an absolute mess! I want to create a pattern of diagonal lines, but I want the lines to not be uniform. Basically, I had a group of 3 lines and then a separate line on its own, then repeating this like the image below. I used the function of distributing the distances between the lines is the same everywhere. I then turned the all exactly 45 degrees and aligned with the lines to fit in the bounding box in the mode 'as the motive"as shown. Yet, the resulting model is just a mess of the ugliness of overlap. Can all that I want is the model literally watch as it does in the picture on the left, someone you please tell me how to sucessfully this in CS6? Would be eternally grateful!

    Desired design: pattern problem.png result:ugly pattern.png

    Never create a line pattern obliquely. It is not necessary.

    Create the model at 90 ° angle and then use object > transform > Rotate and check the option "Transform Patterns" and enter the angle you are after...

    Try to get the slanted lines to match a pattern can take a lot of effort. Where as with this method you can create the pattern and turn it in a few minutes. Let the Illustrator to work for you rather than against you. And, you can rotate to any angle, so the model will work in many ways.

  • How to create random variable of XML

    Hi guys,.

    Need your help.

    I want to create random objects on the plate and the xml.

    If you are referring to the attached picture. Each circle represents XML data.

    test.jpg

    I want to get generated on the screen randomly to the animation of acceleration.

    Note: circles should have random colors 3-4 as mentioned.

    alorsx in advance.

    -Rigorous

    This isn't all of the AS3, AS2 code.  You must republish in AS3 forum... and understand what you have tried and describe what does not work for you.

  • How to create a variables nested within ODI?

    Dear all,

    I am facing problems by assigning a value to the variable value in ODI.

    I try to use the Variable nested... Lets say I have a RootFolder variable, which has a value of c:\ODIIntegration.

    Now, I want to use this value in another ArchiveFolder variable that must be set to RootFolder\Archive (c:\ODIIntegration\Archive).

    When you declare the variable I the value assigned to the variable ArchiveFolder as below, but it doesn't work and I get no error.

    #RootFolder\Archive

    Please guide me to use the variable correctly.

    Pointers would be much appreciated.

    Kind regards

    Manmohan Sharma

    Hello

    Enter your PROJECT CODE when calling the variable.

    In your case
    Variable ArchiveFolder = #. RootFolder\Archive

    If variable RootFolder is a GLOBAL variable then
    Variable ArchiveFolder = #GLOBAL. RootFolder\Archive

    Thank you
    Fati

  • How to create a variable that gets + 1 or - 1 according to clicks?

    I don't know what to look for.  Is there a way to define an invisible flash variable so as to keep the score?

    The best way I can describe it comes from the BASE language I used to use back in the day, where you can click on x = x + 1 or x = x-3, or what function of the button click you.  And then it would display the score (i.e., just what is the current value of x) in the corner?

    I guess the simplest way that could help me to give me a link or the actual code you EF to a single button that will add or subtract a score displayed in the corner.

    My knowledge of ActionScript is very limited... I know that what I have copy - paste for my purposes of line.

    Thank you!

    However, whenever you plan to display the value you can use...

    textFieldName.text = String (someVariable);

    where textFieldName is any instance name assign you to the TextField object

    Please mark this ad as answered if you can.

  • How to create a Global Variable through the Project Explorer

    Hello world!

    I know how to create a global variable (in a vi through the range of functions...).

    but I'm missing a way to create one via the Project Explorer.

    It's a missing feature or just this documentation (and the intuition of myself) are missing?

    It would be very convenient.

    THX for your time and hope that answers.

    jwscs

    Right click on my computer > new > new... > select Global Variable.

    EDIT: although I agree with Gerd (he probably wondering why you need so we can recommend a better way ), I rarely use them in easy to write once - read many applications such as security levels overall program at initialization (VER) to read later, but NOT modified.  I know it would be better to make a good class, functional Global Variable (FGV) or a motor Action (AE) but globals ARE practical and safe IF used wisely.

  • How to create a global variable?

    I want to create a global variable start button to control programs in the structure of the sequence. But I do not know how to creat it. Thanks for responding.


  • How to create a file name variable with the County and the date?

    Objective: Create a file name variable with the County and the date

    Error: get a lot of error. Do you know how to change my code?

    Question: how to create a file name variable with the County and the date?

    Mini code:

    std::string * rawfilepath;
    std::string * rawfilename;

    rawfilepath = "./shared/documents/";
    RawFileName = rawfilepath + 'rawlog -' + 0 + '-.txt ';
    QFile file (rawfilename);
    If (file.exists ()) {}
    rawfilenamecount ++;
    RawFileName = "./shared/documents/rawlog-" + rawfilenamecount + "-.txt ';
    }

    Thank you for your attention,

    Thank tzander reminding me the idea. Method of cascades is not good for me because all of the kernel code is written by Native. If I change the channel to QString, I need to change a lot of codes.

    Solution is below.

    While (access (rawfilename, F_OK)! = - 1) {}
    rawfilenamecount ++;
    sprintf (format, RawFileName, rawfilenamecount);
    fprintf (stderr, "file exists");
    }

    Rawlog = fopen (rawfilename, "w"); Save the file in a specific path.
    fprintf (rawlog, "System Time (ms)" "");

Maybe you are looking for