OS:windows7
IDE:flashBuider 4.6
Flex SDK: 4.6.0
ActionScript3的for ... in
特性:
- 對Array會取回index。
- 對Object取回key(即屬性名稱)。
範例程式碼:
//建立一個陣列,內含三個元素
private var array:Array = ["one" , "two" , "three"];
//建立一個物件,內有三個屬性name , age , gender.
private var object:Object = {name:"小米" , age:"20" , gender:"男"};
protected function applicationCompleteHandler(event:FlexEvent):void
{
testArray();
trace("----------------------------");
testObject();
}
protected function testArray():void
{
//注意這裡取回的值會是字串型態
for (var index:String in array)
{
trace(index);
}
}
protected function testObject():void
{
for(var key:String in object)
{
trace(key);
}
}