ActionScript 3.0 :: Declaring And Naming Arrays In A Loop Possible?
May 12, 2009
Is there a way to do this somehow?
Code:
var someVariable:int = 3;
for(var i:int = 0; i< someVariable; i++){
var mainArr[i]:Array = new Array();//I get an error if I try this
[Code]....
View 6 Replies
Similar Posts:
Oct 26, 2009
I'm trying to declare arrays inside a for loop, then access them later as if they were declared publicly/globally. This doesn't work:
Code:
playlist = addChild(new MovieClip());
playlist.header = new Array();
for (i=0; i<3; i++) {
playlist.header[i] = playlist.addChild(new MovieClip());
or (j=0; j<6; j++) {
[Code] .....
How would I declare the arrays within the for loop, but still access them later without them becoming undefined?
View 2 Replies
Aug 1, 2009
I am wanting to create an array. 10 values in it (couting from 0 index to 9). Each 'place holder' will have a corresponding value to it;s index i.e.
myArray[0]=0
myArray[1]=1 etc...
I can do that in a for loop. But then I want to attach each value to a single variable name. I then want to change that each variable to a string. I then want access to all the variables outside of the for loop.
var i:Number;
var aArray:Array = new Array();
for (i=0; i<10; i++) {
[code]....
The output error is 1084: expecting identifier before aArray.
View 1 Replies
Nov 9, 2010
Should I declare the _mcContainer var before the loop or no? (performance increase?)
for(var i:uint = _startIndex; i <= _endIndex; ++i){
var _mcContainer:MovieClip = _mcParent["i_" + _position];
}
[Code]....
View 1 Replies
Nov 21, 2010
I want to declare 8 variables at the class level like this:
Code:
private var graphicDesign1:Sprite;
private var graphicDesign2:Sprite;
private var graphicDesign3:Sprite;
private var graphicDesign4:Sprite;
[code]....
But I would like to do it with a for loop. Is that possible? If so i'm doing it wrong this is what I have.
Code:
for(var i = 1; i < 9; i++){
private var +"graphicDesign"+i:Sprite;
}
View 1 Replies
Aug 8, 2011
is it possible to add variables and name them according to position in a loop? for example how can I do something like this:
[Code]...
View 5 Replies
Mar 25, 2007
Whats the correct syntax for declaring a variable within a loop? Something like this:[code]
View 1 Replies
Feb 22, 2011
I have an object which is assigned a number of properties:
var project_array:Array = [];
var slideObject:Object = {
project_title : myXML.projects.project[i].title.toUpperCase(),
[Code].....
but I'm not quite sure where to place this. If I place it outside of the object constructor, I get "term is undefined", I guess because it doesn't know what project_clips_array is - but if I declare project_clips_array in the constructor, it appears to need to be defined, i.e. I can't create a blank property. But I can't place it in the constructor either, because it doesn't seem to allow me to run a function within an object constructor. What is the proper syntax or arrangement of code for executing this function to get the array within the object?
View 2 Replies
Oct 5, 2010
k say i wanted to create a bunch of movieclips in a for loop but wanted to name them something different each time, how would i dynamically name them?
View 1 Replies
Jan 17, 2011
what is the syntax for assigning names to textfields created dynamically using a loop.
Code:
for (var i:uint=0; i<10; i++) {
var myText:TextField = new TextField();
myText.defaultTextFormat = textFormat;[code]....
As expected, this code gives me a warning "Duplicate variable definition".How can I assign names dynamically (myText1, myText2, myText3...)?
View 3 Replies
Nov 29, 2011
basically I need a loop within a loop to compare two different arrays in my actionscript3 lottery game. I have attempted the loop but I cannot seem to get it to work ...
[Code]....
So basically within this code check_win is a button. Once the button is clicked it runs the loop. It is meant to take an instance of matches which contains 6 properties and loop until index is greater than matches. According to my output this is happening but the second loop doesn't appear to do anything.
View 1 Replies
Aug 25, 2010
How do i word a for loop to make it loop through multiple arrays?I want 1 for loop to loop through multiple arrays in order to move/alter objects.I want to keep the arrays separate.
ActionScript Code:
characters = new Array();
characters[0] = male;
[code]........
View 3 Replies
Apr 18, 2009
I need to assing two dimensional with random numbers so i just try to do it in a loop, but it can not be done the way I show You below.[code]trying to run that code I just get an error...
View 1 Replies
Feb 9, 2012
I have a problem to use each code in for loop. I create 2 Circles in my stage with addChild code. And I gave them function ( mc.x += 2; ) and the time they get to the end of stage I gave the function ( mc.x -= 2; ) but my problem is when one of the circles get to end and wants to move to the right the other circle move with him to the right. and I think the each code in for loop helps me. but I don't Know how to use it in my actions.
my code is:
ActionScript Code:
var mc1:Circle = new Circle();
var mc2:Circle = new Circle();
[code]....
What should I change in this code to use each for loop..?
View 9 Replies
Jun 15, 2005
creating multiple arrays in a for loop? This doesn't work :
for (i=0; i<catNum; i++) {
var arr(i):Array = new Array ()
}
[Code].,...
View 7 Replies
Nov 15, 2008
Is it possible to have a for loop and create a new array for every loop
for
(i=0; i<5; i++){
myArray+i:array=new Array;
}
I know this doesen't work it just illustrates what im after.
View 6 Replies
Mar 16, 2010
I wanted to know if there's a way to add more options to a for loop regarding arrays. Say the current position in the loop is 1 (thats where my block is) then i want it to check the array if current position -1, +1,-3,+3. if any of these are null (thus, empty spot.) Because the block moves across a board i need the script to be adaptable.
View 3 Replies
Jun 7, 2011
I'm trying to display strings stored in arrays with a for loop, i could just write out each array like:[code]but it only displays the last one, is there a way to display it from 1-10, or 1-any number?
View 4 Replies
May 23, 2007
I have two arrays - one for movieclip buttons and one for images. The idea is - rollover a button and it loads it's respective image. I have a loop for the button array that pretty much loads each button and creates a rollover state for it. At the moment it just traces what button the mouse is over. The problem is trying to load the correct image based on that button. The way it is now - it will only load the same image for all the buttons.
Code:
tagPosition = 0;
viciousImgs = new Array("vaI1_mc", "vaI2_mc", "vaI3_mc", "vaI4_mc", "vaI5_mc");
viciousButs = new Array("va1_mc", "va2_mc", "va3_mc", "va4_mc", "va5_mc");
vicious = new Array("vicious_mc", "uTitle_mc", "uTxt_mc", "uButs_mc", viciousImgs, viciousButs);
[code]....
View 2 Replies
Mar 1, 2011
So im recreating my ear training program with more effective coding so i can add on to it. original i did.
//88 C8
var mp3Req88:URLRequest = new URLRequest("88.mp3");
var mp3_88:Sound = new Sound();
mp3_88.load(mp3Req88);
I basically got 88 sound files (each note of the piano) doing this code 88 times for each sound. with mathamatical equations made my ear training program.
Is there a simpler way to import these sounds in a loop of some sort so i dont have to do this 88x for the piano and however many times for the other instruments i will be including?
thus var i have tried things along the lines of below with failure
var i:int;
for (i = 0; i < 5; i++)
{
var pianoMP3Req+i:URLRequest=new URLRequest("piano/"i+"mp3");
[Code].....
View 1 Replies
Mar 24, 2012
I hope I am clear enough. My data set is populated I have
comment:CommentVO;
comment.replies=[comment:CommentVO,comment:CommentVO,comment:CommentVO];
_comments:Array = [comment:CommentVO,comment:CommentVO,comment:CommentVO]
I've correctly populated my _comments Array and the replies array in my CommentVO Obj.
[Code]...
View 3 Replies
Jun 9, 2006
[code]In my real application, I've actually created a named array with element1 as key...so that I can address it directly by it's name.The problem is that - in my real application - the array2 element doesn't share a name in common with element1 (so I could address it by its name..as just told you,using named array) but with element5.
View 1 Replies
Mar 23, 2009
I have a array of categories, for e.g.
var categoryArray = new Array('value1', 'value2', 'value3');
I would like to loop and create new arrays from each of the values in the categoryArray I tried...
for(var i=0;i<=categoryArray.length-1;i++){
this[categoryArray[i]] = new Array();
}
value1[0] = "dsfsdf";
trace(value1[0]);
It doesn't seem to work.
View 3 Replies
Jul 3, 2006
i am trying to create a loop that will put a list of names from external sources into a number of Arrays .so what i did is :
Code:
for (i=0; i<4; i++) {
this["loadVarsText"+i] = new LoadVars();
this["loadVarsText"+i].onLoad = function(success) {
[code].....
and i dont understand why it is not working, and how can i fix it?
View 3 Replies
Jan 21, 2011
I am running into some trouble adding an array into another array to create a multi-dimensional array.The code appears as below:
var slideDataArray:Array = new Array();
var slideShowDataArray:Array = new Array();
slideDataArray[0] = xmlData.SlideShowParameters.SlideShowImagesDirectory;[code]........
I am looking for a means of placing the slideDataArray into a 'slot' or value of slideShowDataArray so that I can in the end pass the slideShowDataArray as a parameter to another function.As of now, the last slideDataArray appears 11 times (the loop runs 11 times) in slideShowDataArray and the way the code is written the slideDataArray is unique every iteration of the loop.
View 1 Replies
Aug 26, 2009
I've got a bit that loads a big chunk of xml data about products.I push product info into an array(e.g. productArray), then add that array to another array (e.g. allProductsArray)How do I sort those arrays? For instance, if I want to sort the allProductsArray based on the info in productArray[0]?Alternatively, would something other tha an array of arrays be a better route?This loader loads the same sort of info for many different clients, so the bit to sort on will change.
View 5 Replies
Sep 26, 2011
I'm trying to write a function where I can specify any amount of array, and the return value will be an array containing the contents of all of the specified arrays.I've done this, but it seems like a really slow and ugly way of doing it:
var ar1:Array = [1,2,3,4,5,6,7,8,9];
var ar2:Array = ['a','b','c','d','e','f','g','h'];
function merge(...multi):Array[code].....
Is there an inbuilt and more efficient / nice way of achieving this? The result does not need to be in the same order as the input - completely unsorted is fine.
View 3 Replies
Feb 17, 2009
A little explanation: Im making a random arranging number Array. So instead of using a loop and assigning 0 to first array element, 1 to second, etc.I need to make it totally random but without repeating any numbers. To do that I made a second Array that will have the same number of children to serve as a reference.Each of them will be an Object with a property "num" , wich will be its actual number, and a property "called" wich defaults to false.Like this:
ActionScript Code:
for(var i:int=0;i<vQuantity;i++){
ranArray.push( new Object() );
[code].......
View 8 Replies
Dec 27, 2009
I've had a problem for awhile that was really odd. After some intense debugging, I realized the problem lied in setting an array equal to another array.[code] When setting one array equal to another, the values aren't copied over, but a reference to that memory is stored. So no matter which variable you change, they are both references to the same memory and thus both will reflect the changes.With other data types, this doesn't happen.I could fix it by looping through t1 and using push() to add each index from t1 into t2, but that seems a little messy.
View 7 Replies
Jun 25, 2004
correct syntax for pushing variables to arrays within arrays? I have searched many threads but found nothing that exactly answers my query.I have a class (Brigade) which amongst other variables contains an array (BrigadeUnits) This is the third element.. My Brigades are stored in an array called AllBrigades. I now need to fill the BrigadeUnits array with objects of my Units class.The hierarchy I want to create is as follows:
AllBrigades (array of Brigades)
Brigade (object)
BrigadeUnits (array within Brigade object)
Unit (Object to be stored in BrigadeUnits array)
I have tried various approaches including the following, assuming that I am addressing the first Brigade in the array:
AllBrigades [0] [2].push (MyUnit);
But when I trace this I just get undefined.
View 14 Replies