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];

}

}

}

}

Tags: Adobe Animate

Similar Questions

  • 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
    

  • 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 a login for PHP users

    How to create a login for users to access their data, currently, I don't see the first user each time I connect with a different user name. I know that I need session stuff but don't know how to use, add or where to put them.
    Thanks in advance.

    Hello

    Find this in your login page:

    session_register ("MM_Username");

    and then you add a session variable in MX called it:

    MM_Username

    then on any of your pages that calls the base to make sure that you use the = MM_Username and then you're all set; Make sure that the tables have a field to reference the session MM_Username variable.

    See you soon
    Let me know if you just come!

  • How to create an ERD for the vista sp2 x 64?

    How to create an ERD for the vista sp2 x 64?

    How to create an ERD for the vista sp2 x 64?

    If you do not have a Microsoft Vista DVD, make a repair disc to do a Startup Repair:

    Download the ISO on the link provided and make a record of repair time it starts.

    Go to your Bios/Setup, or the Boot Menu at startup and change the Boot order to make the DVD/CD drive 1st in the boot order, then reboot with the disk in the drive.

    At the startup/power on you should see at the bottom of the screen either F2 or DELETE, go to Setup/Bios or F12 for the Boot Menu.

    When you have changed that, insert the Bootable disk you did in the drive and reboot.

    http://www.bleepingcomputer.com/tutorials/tutorial148.html

    Link above shows what the process looks like and a manual, it load the repair options.

    NeoSmart containing the content of the Windows Vista DVD 'Recovery Centre', as we refer to him. It cannot be used to install or reinstall Windows Vista, and is just a Windows PE interface to recovering your PC. Technically, we could re-create this installation with downloadable media media freely from Microsoft (namely the Microsoft WAIK, several gigabyte download); but it is pretty darn decent of Microsoft to present Windows users who might not be able to create such a thing on their own.

    Read all the info on the website on how to create and use:

    http://NeoSmart.net/blog/2008/Windows-Vista-recovery-disc-download/

    ISO Burner: http://www.snapfiles.com/get/active-isoburner.html

    It's a very good Vista startup repair disk.

    You can do a system restart tool, system, etc it restore.

    It is NOT a disc of resettlement.

    Make sure you get the 64 bit version.

    See you soon. Mick Murphy - Microsoft partner

  • How to create a password for the user account for my child?

    How to create a password for the user account for my child?

    You can create the user with the parental control account. This will act as a protection for the child's account.

    You can take a look at the following links on setting up parental controls:

    http://Windows.Microsoft.com/en-us/Windows/set-up-family-safety#set-up-family-safety=Windows-7

    http://Windows.Microsoft.com/en-us/Windows/set-parental-controls#1TC=Windows-7

    http://www.howtogeek.com/HOWTO/10524/how-to-use-parental-controls-in-Windows-7/

  • How to create the ADC for first name

    Hello

    I have the situation here, I need display the default in the e-mail (Dear) when the value in the first name field is less than 2 characters long or it is empty. Otherwise, I need to insert the value of the field name (Dear John).

    Please let me know how to create an ADC for this.

    Thank you

    Rama

    Use wildcards for searching.

    ? = any 1 character

    * = 0 or any number of characters

    In order to find people with more than 2 characters in this area?: *

    Then, build your default rule to merge the content in case they encounter more rule of character 2.

  • How to create a shortcut for all users during installation

    Hi people,

    We have a desktop application that is distributed with Java Webstart and works on Win7 machines. Initially, users all connected using a connection by default, so creating shortcuts was not a problem. Now, because of new networking strategies, each user has his own connection.

    The problem is that the shortcut to the application is created in the user profile (for example "C:\Users\JohnDoe\", so that other users in the same machine can not run the application unless he or she installs the application again.)

    Is there a way to create this shortcut for all users using JNLP API or configuration in the xml file?

    If anyone has need of the solution: during installation I save the jnlp file in a directory accessible to all the world and then start the application using "javaws path\to\file.jnlp". More details in How to create a shortcut for java webstart available for all users on Windows 7?-stack overflow

  • How to create a password for the pdf file

    The Adore Acrobat XI, how to create a password for the file? Aid says going to the Tools Menu and clicking on the Protection tab - but there is no option. In the security file - properties - screen, it shows the security details but doesn't allow for no change.

    I think you can be mixing two different products: (free) Adobe Reader and Acrobat ($$).

  • How to create a card for After Effects?

    How to create a card for After Effects?

    After effects Developer Center

  • How to create a jar for icons

    Hi all


    How to create a jar for icons? Please help me thanks in advance.


    Sarah

    Hi Sarah!

    To do this, you use at best the jdk (java development kit) which is already
    installed on your pc in forms is installed.

    Copy all your gif icons in a folder
    Open the command prompt and in this folder.

    If we assume that you have installed forms in the default directory, call the jar.exe like this:

     x:\DevSuiteHome_1\jdk\bin\jar -cfv your_icons.jar *.gif
    

    This will create a jar file in the same directory.
    Copy the jar file into your x:\DevSuiteHome_1\forms\java folder.

    Then open your formsweb.cfg x:\DevSuiteHome_1\forms\server and change your configuration entry under the

    archive_jini=frmall_jinit.jar
    

    TO

    archive_jini=frmall_jinit.jar, your_icons.jar
    

    Please check if in your formsweb.cfg so the imagebase is set to the code base.
    If this isn't the case, create a parameter in your config entry:

    imagebase=codebase
    

    Now the jar file is loaded when you start your application and the icons are
    turns red from the jar file.

    Concerning

  • How to create the presentation for the columns variable and use it in the story?

    Hi all

    Someone knows how to create variable presentation for a column (that is, I need to create it in edit section formula itself). And then, I should use it in the Narrative section to display the value of this column. Is this possible? Or do I need to use any other variable for this requirement? If Yes please let me know, how to create it? This is a very urgent requirement.

    Thanks in advance
    Stephanie

    Hello
    You can have any number of columns in the narrative view, he will accept... Just mention the numbers of the columns in the view body narrative...

    check if useful/correct...

    Thank you
    prassu

  • How to create a type for an enumeration definition

    Sorry for this question of newbe, but I'm working on cleaning up my Act by using types of producer/consumer for event driven state machines.  To do this, it is convenient to create a type definition for the control of the enumeration that defines the possible States of the loop of the consumer.  I don't understand all of the discussion in the books I read.  I just placed an enumeration of control on the front and edited the State names, using them to define the queue for the loop of the consumer.  However, when I use the other functions of the queue and create a constant for the State to put it on the queue, a constant gets shot at the time of its creation.  If the list of States is modified, the item queue using the defined constant previously shows a symbol of constraint (red dot) and the constant does contain not the new State potential... is what the type definition is to propagate this definition to the constants so that they keep up with additions to the list of enumeration...?

    I've been playing with a short example to see how it works.  If someone could help me with something of definition, I would appretiate it.

    Thank you

    Hummer1

    Hi Hummer1,

    Follow these steps:

    1. under the 'file' menu, select 'new '.... »

    2. a dialog box will appear.  Select "custom control" and click "ok".

    3. a new façade will pop up, called "control1.ctl".  Put your constant listed on this new façade.  Add all your statements for your state machine, the way that you did.

    4. under the menu on your new custom control, you will see a field called 'control '.  Click on it and choose 'type definition' (or 'type strict definition').

    5. save your new control custom as "states.ctl" or "enum.ctl" or any name strikes your fancy.

    Now, go back to your main VI.  In the palette "orders", click on "select control".   Choose the typedef, that you just created.  Put it on the front panel.  Right-click on it and select "search terminal.  Your block diagram will jump upward and terminal control will be highlights.  Right-click on it and select "change constant.  Now, you can wire this constant in your queue.  Do the same for any other subVIs that use the same queue, so that they you are referencing the typedef.

    When you want to make changes to your control, open it in the same way you would open a VI and make the changes.  Then, under the "file" menu, select "apply changes".  Changes will propagate through all your screws

    I have attached a small example of a typedef for you.

    Diane

  • How to create a checksum for screw 264

    Hello

    How do I create a "Checksum" for 264 Vis.These 264 screws are related between them if I change the code for any .vi checksum should be updated. This control appears in the main window.

    Concerning

    Jeancel

    You can refer to "MD5Checksum File.vi"

    Essentially, it calculates the MD5 of a file by reading the complete file (in a block of 512 KB of data at a time)...!

    You can keep it in a loop and run for all your files...!

    Don't forget the files should not go to rename or well instead of the paths of files that you can spend it to sort with size last modified data...!

  • How to create the purge for binding spiral &amp; tabs settings?

    Hello

    I am designing a brochure for a client and it is the first I did with a spiral Binder and the tab page (as in the catalogs, where you can easily access to specific sections)

    I was hoping that someone could show me how to set up a document in the picture here:

    dimensions-copy-small.png

    It would be much appreciated!

    P.s. I use InDesign CC.

    Kind regards

    James

    James,

    Above all, talking to anyone will be print and make the cut to shape. They will tell you the page sizes, you need, which all depends on their shape cutting. Will / should give you dimensions for the tabs, they will also streams to work with what you have on these tabs. They will also tell you how much area unobstructed to the backbone they need.

    Then, it's pretty simple. You simply define the size of the page as needed, with the necessary margins. Your thumb tab positions are partly will depend on the degree of verbiage, you need for them. And you'll probably adjustments as you go. I created master pages for each section with the "tabs" (really just a block of text that has a rotation) positioned correctly. I add the text in them, but you can also use variables if you wish. I'm not in general.

    That's about it on the top of my head. I am sure that I left a little. All dimensions play come the people doing the printing and cutting. Communication with them is all. It is part of what you all for pay.

    Mike

Maybe you are looking for