連想配列のテスト
♥0 |
Line 45 |
Modified 2011-02-19 14:44:33 |
MIT License
archived:2017-03-30 03:08:38
ActionScript3 source code
/**
* Copyright tepe ( http://wonderfl.net/user/tepe )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/hZcr
*/
package {
import flash.text.*;
import flash.display.*;
public class FlashTest extends Sprite {
public function FlashTest() {
var text1:TextField = new TextField();
text1.x = 10;
text1.y = 20;
text1.height = 340.0;
text1.width =200.0;
text1.wordWrap = true;
text1.border = true;
addChild(text1);
var map:Object = new Object();
//連想配列での代入1
map["aaa"] = 3;//文字をキーとする
map["bbb"] = 13;
map[17] = "abc";//値をキーとする
map[18] = "aaa";
//連想配列での代入2
map.ccc = 7;
map["ccc"] = "ddddd";
// キー列挙
for(var s:String in map){
text1.appendText( String(s) );//キー
text1.appendText(':');
text1.appendText( String(map[s]) ); //値
text1.appendText('\n');
}
text1.appendText("-----------------\n");
// キーと値を列挙して初期化
var map2:Object = {six:6 , seven:7, eight:8};
for (var key:String in map2){
text1.appendText(map2[key]);//値
text1.appendText(" ");
}
var map3:Object = new Object();
var n:String = "5 ff";
map3.obj = map;
text1.appendText(map3["obj"]);
if(map3["obj"] == "[object Object]"){
var obj3:Object = map3["obj"];
for(var key2:String in map3["obj"]){
text1.appendText("\n"+obj3[key2]);
}
}
}
}
}