EventDispatcherでイベントをカスタマイズする

1240 ワード

// EventDispatcher 
import mx.events.EventDispatcher; 

class testEvent extends MovieClip{ 
  function testEvent(){ 
//  
    EventDispatcher.initialize(this); 
  } 
//  
 function dispatchEvent(){} 
 function addEventListener(){} 
 function removeEventListener(){} 
 function sendOK(){ 
// onSend 
    var eventObj1:Object = {target:this,type:"onSend"}; 
    dispatchEvent(eventObj1); 
    trace("OK"); 
// onComplete 
    var eventObj2:Object = {target:this,type:"onComplete"}; 
    dispatchEvent(eventObj2); 
  } 
}
 ? !
 FLA, :
 UI , UI , addEventListener removoeEventListener。
var testObj:testEvent = new testEvent(); 
var eventObj1:Object = new Object(); 
eventObj1.onSend = function(obj){ 
  trace("type:"+obj.type); 
} 
var eventObj2:Object = new Object(); 
eventObj2.onComplete = function(obj){ 
  trace("type:"+obj.type); 
} 
testObj.addEventListener("onSend",eventObj1); 
testObj.addEventListener("onComplete",eventObj2); 
testObj.sendOK();

ok! 。