AS Flex如何迴圈呼叫乙個物件的屬性 方法

2021-05-27 19:25:56 字數 891 閱讀 4638

當乙個類有很多名稱相似的屬性(如prop1,prop2,prop3……),或是有很多名稱相似的方法(如fun1,fun2,func3……),那麼如何用乙個for()迴圈迴圈呼叫這些屬性和方法呢?

可以用如下的方法實現:

package   

for (var j:int=1; j<3; j++)  

}  private function fun1(i:int, str:string):void

private function fun2(i:int, str:string):void

}  }  

輸出結果:

foobarfun1被呼叫!

1字串1

fun2被呼叫!

2字串2

如果要迴圈呼叫其它類物件的屬性、方法,比如在類test中迴圈呼叫類test2例項物件的屬性、方法。可以用下面的方法實現:

test.as

package   

for (var j:int=1; j<3; j++)  

}  }  }  

test2.as

package

public function fun1(i:int, str:string):void

public function fun2(i:int, str:string):void

}  }  

輸出結果:

test2中的foo

test2中的bar

test2中的fun1被呼叫!

1字串1

test2中的fun2被呼叫!

2字串2

如何實現重複呼叫乙個函式,非迴圈

在很多時候我們會有這麼乙個需求 define dup call func,param,ntimes 比如我呼叫 dup call puts,hello,world 3 編譯器將會自動生成 puts hello,world puts hello,world puts hello,world 那麼我們如...

乙個驅動如何去呼叫乙個驅動?

這個是入門級問題,以前我剛搞wince的時候也很糾結,不知道怎麼去弄。後來看了wince6.0 6410 s5pv210的 攝像頭驅動就發現原來驅動和驅動之間呼叫和應用程式呼叫驅動是一樣的 一點都沒區別。createfile 開啟另外乙個驅動 deviceiocontrol 去操作另外乙個驅動 go...

如何實現乙個迴圈佇列

下面是乙個迴圈佇列的完整實現,歡迎讀者朋友參考和指正 template class cyclicqueue cyclicqueue cyclicqueue const cyclicqueue copy m poppos 0 m count 0 cyclicqueue operator const c...