2013-02-01 64 views
0

我試圖訪問影片剪輯位於一個按鈕,我指這段代碼:AS3:在按鈕Accesing影片剪輯

var buttonObject = this[weaponsPurchased[i]]; 

然後我設置「將mouseEnabled」假(即部分作品)

buttonObject.mouseEnabled = false; 

然後我試圖設置此按鈕unvisible內的影片剪輯(並且不工作)

buttonObject["square"].visible = false; 

我得到這個犯錯或:

ReferenceError: Error #1069: Property square not found on flash.display.SimpleButton and there is no default value. at (...)

我沒有在互聯網上找到任何幫助,所以請幫助我。我究竟做錯了什麼?

+0

您是使用IDE在按鈕中製作MovieClip還是使用'addChild()'? – David

+0

我是用IDE做的。 –

+0

我認爲最好的行動方式是使用'addChild()'來避免併發症。 – David

回答

0

您無法訪問SimpleButton的子元素。 SimpleButtons不是DisplayObjectContainers,但它們可以在從Flash IDE創建時具有子元素。

來源:http://xtyler.com/as3-simple-button-breaking-all-rules/

我只想去一個影片剪輯,而不是用你自己的類來處理鼠標懸停及移出事件。一個很好的教程概述了創建可擴展MovieClip的可重用按鈕類。

http://www.ironcoding.com/2011/02/flash-as3-movieclip-button-tutorial/

+0

現在我得到ReferenceError:錯誤#1069:在flash.display.SimpleButton上找不到屬性getChildByName,並且沒有默認值。 –

+0

這很奇怪.... –

+0

我錯了,SimpleButton是一個DisplayObject;不是DisplayObjectContainer。你在flash IDE中創建了simpleButton嗎? – zachzurn

0

我前一陣子有這個問題。我所做的是在按鈕的每個狀態中搜索DisplayObject。我會在這裏放一些代碼,可以幫助你。你必須認識到,如果你的按鈕在所有四個框架中都有對象,你也可以在所有狀態中找到你的對象。

private var Obj1:DisplayObject, Obj2:DisplayObject, 
    Obj3:DisplayObject, Obj2:DisplayObject; 

    private function searchInChildren(spr:DisplayObject, name:String):void 
    { 
     for (var i:int = 0; i < spr.numChildren; i++) 
     { 
      if(spr.getChildAt(i).name == name) 
      { 
       return spr.getChildAt(i); 
      }   
     } 
     return null; 
    } 

    public function searchControllers(_ref:SimpleButton, name:String):void 
    { 
     try{ 
      Obj1 = searchInChildren(_ref.upState, name); 
      Obj2 = searchInChildren(_ref.overState, name); 
      Obj3 = searchInChildren(_ref.downState, name); 
      Obj4 = searchInChildren(_ref.hitTestState, name); 
     } catch (e:Error) { 
      trace("error: "+e+", when trying to search for controllers"); 
     } 
    }