ActionScript 3.0 :: What Are "[]" Square Brackets Used For Access Array Index
Oct 19, 2011
I am kinda new to as3 and I have seen [] the square brackets used when trying to access array index but I have also seen some people use it in other places. I was just wondering what its exact function was.
View 1 Replies
Similar Posts:
Jun 20, 2011
I'm trying to do that trick where you make a variable name with square brackets. I think I don't fully understand what I'm doing though...
Code:
var cursorDirection1:Point = pt.subtract(rootpos1);
var cursorDirection2:Point = pt.subtract(rootpos2);
var farShoulder:int = 1;//1 = left 2 = right
[Code]....
I'm trying to avoid having to do a conditional to choose between cursorDirection1 or cursorDirection2. My last line there isn't working, I'm not entirely sure why. Assuming farShoulder is 1, the code should be interpreted as
Code:
cursorDirection1.normalize(findNormVar(cursorDirection1));
but I'm getting errors about the input being undefined.
View 9 Replies
Jun 20, 2006
I'm stuck with trying to target a movieclip dynamically from a loop. I'm using the square brackket syntax but I can't figure out why it's not working. Here's what I'm trying to do:
Code:
this.t1.t1._alpha=20;
And here's how I'm trying to do it:
Code:
this["t"+1+".t"+1]._alpha= 20;
View 3 Replies
Aug 10, 2007
I'm reading a book on ActionScript and I'm in the section on controlling movie clips. I'm reading about the basic methods, and I'm starting to realize I still don't fully understand the significance of square brackets.[code]Obviously, this is the prototype form of the lineStyle() method. What I don't get is why "thickness" is the only parameter without square brackets. I know that square brackets are used for retrieving data from an array or object, but either my book doesn't cover why they're used like this in a method, or I just completely blanked it out.
View 2 Replies
Oct 13, 2010
I have some classes stored in a swc which I would like to instantiate using data pulled in by xml - using a string to reference the classname.So where I would normally use
ActionScript Code:
var tagline:Sprite = new Tagline1();
I would now like to do something like
ActionScript Code:
var tagname:String = "Tagline1"; // really the string comes from XML
var tagline:Sprite = new [tagname]();
I have a vague idea this is possible using square brackets, but I don't seem to be able to find out anything about it.
View 5 Replies
Aug 16, 2011
I think it would be simplest to explain it like this:
[Code]...
View 1 Replies
Jan 17, 2010
I'd really like to be able to make Flash's array access syntax 'wrap' over the array's bounds.
Lengthy explanation -
var array:Array = ['a','b','c','d','e','f'];
To keep things simple, the first index is 0, and its value is the first letter, 'a'. To get that value, we'd do this -
array[0]; // returns 'a'
As long as the index you're using to access the array is between 0 and array.length (6 in our example,) everything works fine - but if you use an index outside of those bounds, you're shut down.
array[-3];
array[9]; // both return 'undefined'
Sometimes that's a good thing - sometimes you expect that to happen, and you're fine with it. Other times, you find yourself wishing (or at least I find myself wishing) that it'd behave a bit more like this -
array[-3];
array[9]; // both return 'd'
(e.g. a photo gallery that jumps back to the beginning when you click 'next' on the last photo)There's a little chunk of code I use over and over for this sort of thing, but it's always to alter the index before passing it into the array:
var index = -3;
while(index < 0){index += array.length}
array[index % array.length]; // returns 'd'
... and that's fine, but what I really want to do is extend the Array object itself so that it'll automatically 'wrap' index values that go out of bounds.TL;DR - Is index-wrapping possible by extending Flash AS3's Array object?
View 2 Replies
Jul 28, 2011
How to format JSON data without using brackets for an array?[code]...
View 3 Replies
Jun 22, 2011
So, for sending to individual streams we have to reference the connected netStream we want to send to in some way like this:
sendStream.peerStreams[0].send("MyFunction",param1,param2);
and I have to determine which peer I'm sending to by their ID such as "peerID1234"
I know that you can check the peerID of the stream by doing:
sendStream.peerStreams[0]["farID"]
how can I make my send stream function know to use the array index where the peerID is?
so basically it could be like:
sendStream.peerStreams[where peerStreams[]["farID"] == peerID].send("MyFunction",param1,param2);
View 1 Replies
Feb 15, 2011
I have used a method to shuffle a part of a Array, but i noticed that it does not work very well.When i run this method I sometimes get empty array values.So if you would try the example below and test it out some times you would get a right result but sometimes a wrong result.For example when i run this i get in my trace output:
a,b,c,d,g,,e,f (here after the g it goes wrong)
a,b,c,f,g,d,e (here it goes right)
a,b,c,d,,g,f,e (here it goes wrong)[code]...
View 8 Replies
Dec 2, 2010
when creating a dynamic square with the api. 400 by 400. I am not sure why it wont draw the object
[Code]...
View 2 Replies
Jan 15, 2010
I have this game, and some levels have a moving square as the player, you move the square with your arrow keys.... I want to have an enemy square that chases the player square.... They only chased mario when you didn't look at them? Kinda like that...... but in this regards:
I only want the enemy square to chase the player square when the player square moves.... soo say the player square moves 5 pixels per movement (know how to do all that), I want the enemy square to move when the player square moves..... towards the player square at like 7 pixels per movement..... so eventually you won't be able to avoid the enemy square....
View 4 Replies
Dec 13, 2011
I am adding movieclips (myBall) to the stage by the click of a button. There is a base class applied to myBall which allows it (and its children) to be dragged and dropped. Within the base class on mouse down, along with startDrag, the movieclip is being brought to the top index. I would like to be able to refer to this movieclip in my document class. The point of doing this would be to apply a function to the last clicked movieclip (finding what movieclip was last clicked would happen by applying the function to the movieclip (myBall) with the highest index).[code]...
View 7 Replies
Feb 2, 2011
Say I had this array[code]...
This adds five new instances of the Thing class through the main timeline. In the Actionscript code for the Thing class I want to be able to reference the index of the given instance for identification purposes.
View 6 Replies
Sep 20, 2010
I would like to edit a cell by the row and column indexes so essentially do the following:
advDataGrid[2][3] = "Dogs"
so that I am setting the data grid row 2 and column 3 to Dogs. I cannot for the life of me figure out how to do this!
Side note: I need this because I am trying to allow the user to copy a section of an excel file to a section of an AdvancedDataGrid like Google Docs does. I am using this idea to do it: [URL]
View 3 Replies
Nov 30, 2010
Upon the stage of my flash movie, I have several symbols (movie clips) which I need to address dynamically using a loop. The symbols that I want to address all have instance names beginning with the string "lamp_", they then each have a different number concatenated on the end to distinguish between them (e.g. lamp_1, lamp_2, lamp_3.....).
The following noobish effort I have devised is totally useless, and I am hoping someone can show me how I might get this working[code]...
View 4 Replies
Sep 25, 2009
Is there a way to get the index of an array?
For instance, if I have an array:
buttons = Array("abc","def","ghi");
If I wanted to get the index dynamically of the string "ghi", could I do that with a certain function or piece of code?
View 1 Replies
Mar 11, 2010
I thought that there was a way to be able to name array indexes. Like instead of myArray[0], it could be myArray["tileFour"]. I thought that instead of using index numbers one could use index words.
View 1 Replies
Sep 25, 2009
Is there a way to get the index of an array?
For instance, if I have an array:
buttons = Array("abc","def","ghi");
If I wanted to get the index dynamically of the string "ghi", could I do that with a certain function or piece of code?
View 0 Replies
Jan 18, 2011
I have a game map made of tiles, each tile is stored in an array called _tiles.The very each tile has a "plantable" parameter, which determines whether or not something can be placed on it.Then i loop through the array and check the position of each its elements against the mosue cursor, so I know which tile am I hovering with my mouse.
And it works pretty good. The problem is that even though I know what is the position of the tile I'm having the cursor on, I still lack the knowledge of what index is that tile. I simply can't tell where exactly in the array is placed this tile. I just know its position. The reason why I want to know the index of it, is because it's the only way for me to set a proper flag, namely whether it's plantable or not. Here's the code:
ActionScript Code:
for(var j:int = 0; j < _tiles.length; j++)
{
[code]...
View 1 Replies
May 18, 2005
Is there a way I could specify the index of a array using this short code:[code]How would I go about giving a custom index name instead of it being myArray[0]? I could do it the long way like posted below, but I was wondering the there was a way to shorten this:[code]
View 2 Replies
Jan 18, 2007
i have an array of names that looks like this. var aNames:Array =new Array("jack","mike","Scott")
i have a text field called names which displays index 1 of the array.
and i have a button,when the button is pressed i want it to go to the next index of the array.
View 6 Replies
May 18, 2005
Is there a way I could specify the index of a array using this short code:
Code:
var myArray = new Array("teste");
How would I go about giving a custom index name instead of it being myArray[0]? I could do it the long way like posted below, but I was wondering the there was a way to shorten this:
Code:
var myArray = new Array();
myArray[myCustomIndex] = "testing";
View 2 Replies
Jan 29, 2009
Consider an array with x number of elements (of type Object) where some of the elements might be undefined.I use a for-each loop to access all the elements of the array that is not undefined (since it simply skips the undefined elements).But I also want the index of that particular element.The only option I can see is to use indexOf(). But it feels a bit like looking for water on the other side of the river so to speak.
When looping through long arrays each frame, is there a change indexOf() might slow it down? or does the for-each loop somehow know what index it's dealing with?
View 19 Replies
Oct 30, 2009
I am working with a set of external XML data, and putting it into arrays. I have set up images and text on a page using XML data, which, when clicked on, will populate a popup window with XML data from the same index. For some reason, when I trace the index of the array, it comes up as -1.
stop();
itemNameTops1_txt.text = nme_array[0];
itemPriceTops1_txt.text = price_array[0];
[code]....
View 4 Replies
Jun 15, 2011
I have a tricky problem in that I have an array that has been populated with strings ("item1", "item2", etc). However, at a certain point I need to pull one randomly out of the group, via a random number function. The issue is I cannot reference the items in the array by a number, I get an error. So when I try to get myArray(5) it doesn't work.
How can I work around this so I can grab a random item in my string array?
View 6 Replies
Jan 18, 2012
I am creating a row which have 8 thumbnails in it, I save these in a array, When user drag row right to left then first Movieclip shift to last position, then i splice array 0 index and push to last position.. it works fine but when i drag it left to right then I need to cut last index of array and i need to push on first position, but it is overwrite the last value of array and after push the value(myrow[0]=thumb) array showing it's length 7 before it was 8. What is the right way to push value at 0 index value
View 2 Replies
Apr 10, 2012
I have an array 'cat', 'dog', 'budgie'
and want to remove the item by index.
At the moment I have
function removeit(myindex) {
animals[myindex] = animals.pop()
}
View 1 Replies
Feb 1, 2010
I got a problem with processing an array in actionScript. I removed the last element of an array through array.pop(). After that I would like to put this removed display-object back to the beginning of the array: array.unshift(object). The object is now the first element of the array but it got still its old label (number of the last element). Therefor I can't update the position (graphically) of the display object. Is it possible to "reindex" the array?
View 1 Replies
Mar 30, 2010
var arr1:Array = new Array();
arr1.push(item1);
arr1.push(item2);
arr1.push(item3);
then arr1 and its elements get passed to other functions is there a way to know the index of an item in the array?
GetParentArrayIndex(item2) would give me 1;
View 2 Replies