2013-02-01 113 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"); 
     } 
    }