2012-11-09 42 views
0

我正在開發一個發票系統。我需要通過的addChild如下方法提到如何指向或引用動態創建的項目

1.select產品(組合框)動態地添加發票項目 - Quandity(文本框) - 普萊斯(文本框) - 共(文本框)

2.select產品(組合框) - Quandity(文本框) - 普萊斯(文本框) - 共(文本框)

我的問題是我不能讓所有的總金額爲個總文本框每個子元素的..

如何點或refernece動態創建的項目????

回答

1

您可以將所有創建的項目存儲在數組(或矢量)中,然後通過循環訪問它們中的每一個。

例如:

var allPrices:Array = [15.50, 20.24, 36.12]; 

var allElements:Array = new Array(); 

for (price in prices) { 

     // PriceText class is, for example, a movieclip with a textbox inside 
     var obj:PriceText = new PriceText(price); 

     addChild(obj); 

     allElements.push(obj); 

} 

allElements陣列現在你已經添加的所有元素。

1

,或者可以創建參考對象,如:

class Bind { 
    public var target:Object; 
    public var key:String; 

    public function Bind(t:Object , k:String){ 
     target = t; 
     key = k; 
    } 
    public function get value():* { 
     return target[key]; 
    } 
} 

var myItem:SomeClass; 
myItem.param = 100; 
var bind:Bind = new Bind(myItem,"param"); 

trace("get myItem value:", bind.value); 
+0

非常感謝你much..Its不錯.. – Naju