有关自定义分派事件类的解说
自定义分派事件类:(文档类Test.as 事件类Events.as 按钮类Buttons.as)
文档类Test.as
package {
import fl.controls.*;
import fl.managers.*;
import flash.display.*;
import flash.text.*;
import flash.events.*;
import fl.transitions.*;
import fl.transitions.easing.*;
import Events;
public class Test extends MovieClip {
private var _dispatcher=Events.dispatcher;
public function Test() {
var buttons:Buttons=new Buttons();
addChild(buttons);
_dispatcher.addEventListener(Events.ONE,patch1);
_dispatcher.addEventListener(Events.TWO,patch2);
}
private function patch1(evt:Events){
trace("绑定1实现了");
}
private function patch2(evt:Events){
trace("绑定2实现了");
}
}
}
事件类Events.as
package{
import flash.events.Event;
import flash.events.EventDispatcher;
public class Events extends Event{
public static var dispatcher:EventDispatcher=new EventDispatcher();
public static const ONE:String="one";
public static const TWO:String="two";
public function Events(str:String){
super(str);
}
}
}
按钮类Buttons.as
package {
import fl.controls.*;
import fl.managers.*;
import flash.display.*;
import flash.text.*;
import flash.events.*;
import fl.transitions.*;
import fl.transitions.easing.*;
import Events;
public class Buttons extends MovieClip {
private var _dispatcher=Events.dispatcher;
public function Buttons() {
var button1:Button=new Button();
button1.label="绑定1";
button1.addEventListener(MouseEvent.CLICK,send1);
addChild(button1);
var button2:Button=new Button();
button2.label="绑定2";
button2.x=200;
button2.addEventListener(MouseEvent.CLICK,send2);
addChild(button2 );
}
private function send1(evt:MouseEvent){
_dispatcher.dispatchEvent(new Events(Events.ONE));
}
private function send2(evt:MouseEvent){
_dispatcher.dispatchEvent(new Events(Events.TWO));
}
}
}
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |