我有2類,顯示保持當前選擇的組件訪問的對象的靜態變量的屬性:AS3 - 從另一個對象
public class Display
{
public static var selectedComponent:Component;
}
元器件具有ID串和selectedComponent變量設置上點擊:
public class Component extends MovieClip
{
public var id:String;
addEventListener(MouseEvent.CLICK, function() {
Display.selectedComponent = this;
});
}
我現在希望能夠使用Display.selectedComponent.id =「測試」來設置ID;
我的問題是轉換錯誤:
TypeError: Error #1034: Type Coercion failed: cannot convert [email protected] to Component.
卸下selectedComponent變量類型,所以它讀取公共靜態無功selectedComponent;消除了轉換錯誤,似乎改變了ID變量,但它似乎只是對象的副本。
有什麼建議嗎?
感謝
或可能是,你可以做 「Display.selectedComponent =組件(e.target);」我認爲這是更清潔的方法。 – bhups 2009-11-08 06:05:41
不是我不同意,但爲什麼它會更清潔與e.target? (如何「昂貴」鑄造?) – Les 2009-11-08 12:32:06