0

I'm trying to create a very simple 2d array in ActionScript 3.0

var arr:Array = new Array();

arr[0][0] = "Hello";
arr[0][1] = "Ali";

trace(arr[0][0]);
trace(arr[0][1]);

But below error has comes up :

A term is undefined and has no properties.

Please tell me what am i doing wrong.

2 Answers 2

4

You have to add an extra array for the first dimension:

arr[0] = [];
arr[0][0] = "Hello";
arr[0][1] = "Ali";
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you. It works like a charm. Please explain about this part arr[0] = [] i can't understand it.
@HamedKamrava, at position 0, the array now contains another array ([] is similar to new Array()). So you have an array of arrays.
A multidimensional array is an array of arrays, a nested structure. You need to create intermittent layer objects to make a multidimensional array.
Take a look at : "ActionScript 3 fundamentals: Arrays" on Adobe website adobe.com/devnet/actionscript/learning/as3-fundamentals/… Hope it will be helpful.
2

This line:

 var arr:Array = new Array([3], [3]);

Is creating an array containing two arrays, each of which has one element containing the number 3. That means that when you get to the third iteration multiArr[i] is undefined. This is clearly a misunderstanding of how to define arrays in AS31

SO YOU JUST REFER THIS LINK

Problem with 2d Array in AS3

Comments

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.