연관배열의 선언(making associative array of generic object)
It can be a good coding form to reference a Aarray type data and it also recduce your coding strokes. see below.
contacts = new Array();
contacts.push({first:"john", last:"Doe", age:26});
contacts.push({first:"Tom", last:"York", age:24});
trace(typeof(contacts[0].age));
Above example show as below on your output window.
number
With Loop, U can easily extract elements from array. see below.
contacts = new Array();
contacts.push({first:"john", last:"Doe", age:26});
contacts.push({first:"Tom", last:"York", age:24});
contacts.push({first:"Novak", last:"kim", age:60});
contacts.push({first:"Yoda", last:"", age:685});
for (i=0; i<contacts.length; i++) {
trace("He is "+contacts[i].first+" "+contacts[i].last+". and He's "+contacts[i].age+" years old.");
}
and output is,
He is john Doe. and He's 26 years old. He is Tom York. and He's 24 years old. He is Novak kim. and He's 60 years old. He is Yoda . and He's 685 years old.
Benefits of array,
1. the data for each person is known.(that is, U always need those three attributes)
2. Giving names to those three properties makes them easier to access(as opposed to memorizing the order).
Phllip Kerman, Flash MX 2004 for rich internet applications, 2003, New Riders. pp. 96 ~ 99
++ 하위 슬롯에 접근하기 위한 방법
songs = new Array();
songs.push({artist:"N.EX.T", title:"Here I stand for you", duration:"3:40"});
songs.push({artist:"장사익", title:"찔레꽃", duration:"2:58"});
songs.push({artist:"Pink Floyd", title:"Wish you were here", duration:"4:58"});
total = songs.length;
for (i=0; i<total; i++) {
for (a in songs[i]) {
trace(a+" : "+songs[i][a]);
}
}
About this entry
You’re currently reading “연관배열의 선언(making associative array of generic object),” an entry on multiplicité
- Published:
- Monday, March 29th, 2004 at 10:10 pm
- This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.0 Korea.
- Author:
- vizualizer
- Category:
- techne
No comments
Jump to comment form | comments rss