2013-07-02 79 views
0

我在庫中有一個符號,而在階段中,我有十二個符號對象。 每個符號有一個實例名,從人如何將字符串轉換爲as3中的實例名稱

另外我有十二對象(圖像)與實例名,從1-12

我點擊了圖像I可以提取的對象中的一個名稱對象(al)從數組而不是訪問while。

我如何將字符串轉換爲實例名稱在AS3

var abc:Array = ["0","a","b","c","d","e","f","g","h","i","j","k","l"]; 


    function item_onMouseUp(event:MouseEvent):void 
    { 

     var clip:Sprite = Sprite(event.currentTarget); 
     var c:int = int(clip.name); 
     trace("abc[c]=" +[abc[c]]); 

//The problem here 
     if (clip.hitTestObject([abc[c]])) 
     { 
       trace("==="); 
      } 

     clip.stopDrag(); 
    } 

爲了例如在跟蹤贏了,我得到

abc[c]=d 
TypeError: Error #1034: Type Coercion failed: cannot convert "d" to flash.display.DisplayObject. 
    at gamewitoutserver_fla::MainTimeline/item_onMouseUp() 

回答

0
if (clip.hitTestObject(this[abc[c]])) 
    { 
      trace("==="); 
    } 

爲了解決一個對象屬性(即您的命名顯示對象,您在設計時添加實例名稱)通過字符串,使用this[string]

相關問題