1
var array1:Array = new Array();
var array2:Array = new Array();

var obj1:Object = new Object();

array1.push(obj1);
array2.push(obj1);

How can I do this what command should I use?

//obj1's position in array1
//result: 0
//obj1's position in array2
//result: 0

1 Answer 1

3

If you want to find the object position in the array stack,

You can use indexOf

http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/Array.html#indexOf()

For proof of concept

array1.push(obj1);

array1.push(obj2);

array1.push(obj3);

array1.push(obj4);

array1.push(obj5);

trace(array1.indexOf(obj5)); // Should return 4 [ 0 Ob1, 1, Obj2 ... etc]

trace(array1.indexOf(obj1)); // Should return 0
Sign up to request clarification or add additional context in comments.

1 Comment

Keep in mind that this is a costly procedure if your array is very large. Consider using dictionary instead of an array if you need to do this kind of lookup a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.