Flash defines a two-dimensional array

Source: Internet
Author: User

A method for defining two-dimensional arrays

Suppose that the two-dimensional array is [5][7]
var xn:number = 5;
var yn:number = 7;
Define a numeric variable
var temp:number = 0;

Define our two-dimensional array
var myarray:array = new Array ();

Populating a two-dimensional array
for (Var i=0;i<xn;i++) {
Myarray[i] = new Array ();
for (Var j=0;j<yn;j++) {
MYARRAY[I][J] = temp++;
};
};

Outputs the value of a two-dimensional array at the output polygon edge
for (Var i=0;i<xn;i++) {
for (Var j=0;j<yn;j++) {
var st:string = "myarray[" + i + "[" + J + "]:" + myarray[i][j];
Trace (ST);
};
};


Output panel output is as follows:
Myarray[0][0]: 0
MYARRAY[0][1]: 1
MYARRAY[0][2]: 2
MYARRAY[0][3]: 3
MYARRAY[0][4]: 4
MYARRAY[0][5]: 5
MYARRAY[0][6]: 6
Myarray[1][0]: 7
MYARRAY[1][1]: 8
MYARRAY[1][2]: 9
MYARRAY[1][3]: 10
MYARRAY[1][4]: 11
MYARRAY[1][5]: 12
MYARRAY[1][6]: 13
Myarray[2][0]: 14
MYARRAY[2][1]: 15
MYARRAY[2][2]: 16
MYARRAY[2][3]: 17
MYARRAY[2][4]: 18
MYARRAY[2][5]: 19
MYARRAY[2][6]: 20
Myarray[3][0]: 21
MYARRAY[3][1]: 22
MYARRAY[3][2]: 23
MYARRAY[3][3]: 24
MYARRAY[3][4]: 25
MYARRAY[3][5]: 26
MYARRAY[3][6]: 27
Myarray[4][0]: 28
MYARRAY[4][1]: 29
MYARRAY[4][2]: 30
MYARRAY[4][3]: 31
MYARRAY[4][4]: 32
MYARRAY[4][5]: 33
MYARRAY[4][6]: 34

Another way to define a two-dimensional array is to use the object definition. I've seen it before in the Flash Empire, here's a quick tip:

var myarr:array = new Array ();
Myarr.push ({x:1,y:1});
Myarr.push ({x:1,y:2});
Trace (myarr[0].x);
Trace (MYARR[0].Y);

The output is as follows:
1
1

Flash defines a two-dimensional array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.