2011-02-07 68 views
0

我試圖通過控制欄按鈕(id = btn)在主...中更改組件狀態...所以我添加了一個事件監聽器...代碼如下Flex - 通過主要更改組件狀態

import flash.events.EventDispatcher; 
      import flash.events.MouseEvent; 
      import mx.core.FlexGlobals; 

FlexGlobals.topLevelApplication.btn.addEventListener 
       (MouseEvent.MOUSE_DOWN, change_state, true, 0, false); 

public function change_state(e:MouseEvent):void{this.currentState="wait";} 

但我得到了「1120-未定義的屬性change_state」錯誤...有人可以幫助我!

+0

我嘗試了一些與此代碼非常相似的東西,它似乎對我有用。這似乎是一個範圍問題,仔細檢查它們。特別是在與國家合作時。 – 2011-02-07 19:10:42

回答

0

我有一種感覺,change_state下劃線是導致問題,我覺得可能有一個範圍問題,當你引用它。嘗試像這樣重寫代碼:

import flash.events.EventDispatcher; 
import flash.events.MouseEvent;    
import mx.core.FlexGlobals; 

FlexGlobals.topLevelApplication.btn.addEventListener(MouseEvent.MOUSE_DOWN,this.changeState, true, 0, false); 

public function changeState(e:MouseEvent):void{this.currentState="wait";} 

這是否會產生很大的差異?