论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > Flash AS教程
Tag:2.0,3.0菜鸟,游戏,,cs,技巧,源码,,文本,文字,函数,音乐,随机,拖拽,asp,access,xml,mc,视频教程

有关自定义分派事件类的解说

文章类别:Flash AS | 发表日期:2009-8-9 12:20:53

有关自定义分派事件类的解说

自定义分派事件类:(文档类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));
              }

       }
}

视频教程列表
文章教程搜索
 
Flash AS推荐教程
Flash AS热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058