AS3中Event的target和currentTarget的區別

真正的事件dispatch者是event.target,監聽事件(addEventListner)的對象是event.currentTarget,Flex skd中有言曰:

"Event objects also have target properties that reference the actual object which dispatched the event. In some cases, the target may not be the object for which you have registered a listener. This can occur when the object for which you have registered a listener contains a child component that also dispatches the same event (and
the event bubbles). If you want to ensure that you are getting a reference to the object for which the listener is registered to listen for the event, use the currentTarget property"

例:如爲容器mc1創建了一個同類型(或者說擁有相同事件)的子容器mc2,再爲mc1註冊click事件監聽器,當單擊子容器mc2時,則event.target指事件dispatch者mc2,而event.currentTarget指當前的事件處理者mc1,因此在使用時如果是要獲取被註冊事件監聽器的對象(一般都是如此)則用event.currentTarget,currentTarget屬性應具備兩條件,一是它註冊了偵聽器,二是正在處理事件。 
發佈了24 篇原創文章 · 獲贊 0 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章