如何在mxml中手动触发click事件?

时间:2010-12-05 15:22:50

标签: actionscript-3 mxml

我这样做:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application initialize="onLoad()"...>
<mx:Button id="connect_btn" />  
<mx:Script>  
<![CDATA[   
      public function onLoad():void 
      { 
         connect_btn.click();
      } 
      ]]>  
</mx:Script>  
</mx:Application>

但是得到connect_btn未定义的错误......

更新

是的,我正在尝试模拟点击事件。

1 个答案:

答案 0 :(得分:2)

您可以这样发送:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application initialize="onLoad()"...>
<mx:Button id="connect_btn" />  
<mx:Script>  
<![CDATA[   
      public function onLoad():void 
      { 
         var e:MouseEvent = new MouseEvent(MouseEvent.CLICK);
         connect_btn.dispatchEvent(e);
      } 
      ]]>  
</mx:Script>  
</mx:Application>