Actionscript 3 :: After Shuffling Array - Variable = Array[index] Gives 0, Trace(array[index]) Gives Correct Number
Aug 16, 2011I think it would be simplest to explain it like this:
[Code]...
I think it would be simplest to explain it like this:
[Code]...
The Action script code below takes the strings in the array (pgtit) and creates a dynamic navigation bar I am trying to trace the index number of the array being click I just seem to get -1.
var pgtit:Array=["link1","link2","link3","link4"];
var xPos = 0;
var menuHolder:MovieClip = new MovieClip;
addChild(menuHolder);
[code]....
I copied some code over to a similar function, which traces out the array index number using indexof(e.target).For some reason I'm getting the usual undefined property errors, but it is tracing other properties in the array using e.target?[code]
View 9 RepliesI'm using addChild(new nmonster()) to populate an on stage MC from my Library.
Instead of specifying the Symbol, I want to add it using an Array reference, like addChild(new monsterArray[0]()). I've tried a number of variations, but AS3.0 is unforgiving.
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);
I am trying to trace an index number from an array.
I know this must be about as simple as it gets, but I just cant figure it out.
I know the contents of the array are all asighned a number begining with 0.
I need to find out the index number of a thumbnail when you click on it.
Code:
function whenThumbsLoad(event:Event):void{
var thisThumbsLink:String = clipPathList[ c ];
var thisThumbsTitle:String = clipTitleList[ c ];
[Code].....
I know I can trace the thisThumbsLink and get that, but all I need is it's index number. Also I trace(c); and I get how many there are, but I just don't know what to trace to find the index number.
i used a for loop to addChild of a class object(movieclip) to the stage and at the end line of for loop after addChild i push it into an array and i add eventlistener to it , such as
for (var i:Number = 0; i < 9; i++) {
.....
clip = new CLIP;
......
[Code]....
and if i want to get the array number which currently accessing how can i do that ? for example, i drag one of the mc class from the array which has already added eventlistener above.
how can i get the number of the array which im accessing ? evt.target..... etc ?
I have a Array. I dont know how large the array is. How can I get index of the smallest number in the array? I know array contains only numbers.
View 5 RepliesFor instance:
PHP Code:
my_Array = new Array();
my_Array.push("one", "two", "three", "four")
Here's the catch: another variable (for instance) called "three" is loaded. I want to look up "three" in my_Array and retrieve the index-number (should be 2 of course). How can I accomplish that?
Say you have a class Parent, which has a property childArray:Array. In this array, we will register several instances of the class Child. Is there an easy way for a child to know which position in the array it currently has? I know I could just pass the index number into the child as I register them, but if a child were to be deleted from the array, all children past the deleted childs index would need to have their indexes updatedl. While this is of course not a huge task, I just have this feeling it should be a better and more dynamic solution.
View 6 RepliesI have this Array
Code:
var shoprubriken:Array = new Array();
shoprubriken[0] = "43";
shoprubriken[1] = "44";
[Code]....
Now I wanted to check on which Index Position maybe the 47 is
How can I archive this on a Button or Function?
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]...
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?
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 RepliesIs 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?
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]...
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 Repliesi 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.
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";
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?
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]....
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?
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 RepliesI 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()
}
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 Repliesvar 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;
I'm building a plugin and I'm using actionscript to save the selection of an object in an illustrator document and then reference it later.
var arrObj:Array=new Array();
arrObj.push(app.activeDocument.selection[0]);
If I select now the same object in the document and check if its in the array it returns a -1 for the index value.
var id:int=arrObj.indexOf(app.activeDocument.selection[0]);
trace (id); //-1
Why is the selection not considered the same object as in that of the array?
I have my grid-array in my flash game that has a set sized index in it, and through some code it sometimes checks outside of the Array index. Is there a way I can check to see if a index slot is undefined/existent
Gives me a TypeError #1010
public function fnPopulate(X:int, Y:int, Grid:Array){
if (Grid[ X + 1 ][ Y + 1 ] != null || Grid[ X + 1 ][ Y + 1 ] != undefined ) {
[code]......
I have an MD array:
var fitb:Array = new Array("question1","question2",[["answer1","t1"],["answer2","t2"],["answer3","t3"],["answer1","t4"]]);
It's for a quiz program. Question1 is the first part of the sentence, the answers words that are shuffled and question2 is the last part. So basically they have to align parts of a sentence in the correct order.
Everything is groovy, but I can't figure out how to check if the words are in the correct order. The current [2][0][1] position is my test for embedding the answers, but when it's shuffled it seems to ruin everything.[code]...
How can I add to an array without creating empty values.. the indexes are id'
So I cannot use push..
Or is there a way to remove associative array indexes? I cannot get it to work with splice...
ActionScript Code:
var test:Array = new Array(1,2,3);
trace('before splice:' + test.length);
[Code]....