• 2012、9、28 听课笔记


                                                                           事件流机制

    首先,建立6个不同的元件,分别起元件名字为m1,m2,m3,m4,m5,m6,然后写下如下代码:

    function childMCTrace(evt:MouseEvent)

    {

              trace("childTrace",'我是:'+evt.currentTarget.name); 

              trace('事件所处阶段:'+evt.eventPhase);

              trace('----------------------------------------------------------');

    }

    function anotherMCTrace(evt:MouseEvent)

    {

             trace("anotherTrace",'我是:'+evt.currentTarget.name); 

             trace('事件所处阶段:'+evt.eventPhase);

             trace('----------------------------------------------------------');

    }

    function parentMCTrace(evt:MouseEvent)

    {

             trace("parentTrace",'我是:'+evt.currentTarget.name); 

             trace('事件所处阶段:'+evt.eventPhase);

             trace('----------------------------------------------------------');

    }

    function captureTrace(evt:MouseEvent)

    {

                trace("captureTrace",'我是:'+evt.currentTarget.name); 

                trace('事件所处阶段:'+evt.eventPhase);

                trace('----------------------------------------------------------');

    }

    function stageTrace(evt:MouseEvent)

    {

                    trace("stageTrace",'我是:'+evt.currentTarget.name); 

                    trace('事件所处阶段:'+evt.eventPhase);

                    trace('----------------------------------------------------------');

    }

    function stageTrace1(evt:MouseEvent)

    {

           trace("stageTrace",'我是:'+evt.currentTarget.name); 

           trace('事件所处阶段:'+evt.eventPhase);

           trace('----------------------------------------------------------');

    }

    function stageTrace2(evt:MouseEvent)

    {

              trace("stageTrace",'我是:'+evt.currentTarget.name); 

              trace('事件所处阶段:'+evt.eventPhase);

              trace('----------------------------------------------------------');

    }

    function stageTrace3(evt:MouseEvent)

    {

               trace("stageTrace",'我是:'+evt.currentTarget.name); 

               trace('事件所处阶段:'+evt.eventPhase);

               trace('----------------------------------------------------------');

    }

    m1.addEventListener(MouseEvent.MOUSE_DOWN,captureTrace,true);//捕获到

    m1.addEventListener(MouseEvent.MOUSE_DOWN,parentMCTrace);

    m1.m2.addEventListener(MouseEvent.MOUSE_DOWN,childMCTrace);

    m1.m2.m3.addEventListener(MouseEvent.MOUSE_DOWN,anotherMCTrace);

    m1.m2.m3.m4.addEventListener(MouseEvent.MOUSE_DOWN,stageTrace);

    m1.m2.m3.m4.m5.addEventListener(MouseEvent.MOUSE_DOWN,stageTrace1);

    m1.m2.m3.m4.m5.m6.addEventListener(MouseEvent.MOUSE_DOWN,stageTrace2);

    stage.addEventListener(MouseEvent.MOUSE_DOWN,stageTrace3);

    (这节课可以上我们懂得事件的触发顺序,以及什么是行为事件、目标事件、冒泡事件。)

                                                        启动上机时间的小程序

    import flash.utils.Timer;

    import flash.events.TimerEvent;

    var timer:Timer=new Timer(50);

    timer.start();

    timer.addEventListener(TimerEvent.TIMER,onTimerHandler);

    function onTimerHandler(e:TimerEvent):void

    {

         var time:int=getTimer();

         var str:String=uint(time/1000/3600)+'小时'+uint(time/1000%3600/60)+'分钟'+time/1000%60+'秒'  txt.text=str

    }

                                   倒计时的制作(以系统时间作为基准)

    package
    {
     import flash.display.Sprite;
     import flash.events.TimerEvent;
     import flash.text.TextField;
     import flash.utils.Timer;
     import flash.display.Loader;
     import flash.net.URLRequest;
     import flash.events.Event;
     import flash.events.MouseEvent;
     
     public class Main2 extends Sprite
     {
      private var timer:Timer;
      private var num:Number;
      private var txt:TextField;
      private var txt1:TextField;
      private var loader:Loader;
      public function Main2()
      {
       num = 0;
       timer = new Timer(1);
       //trace(timer.running);
       timer.start();
       txt = new TextField();
       stage.addChild(txt);
       txt.x = 100;
       txt.y = 50;
       txt.width = 100;
       txt.height = 30;
       txt.border = true;
       txt.selectable = false;
       txt.text = "倒计时";
       loader = new Loader();
       loader.load(new URLRequest("001.jpg"));
       loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoaderInfoHandler);
       
       txt1 = new TextField();
       stage.addChild(txt1);
       txt1.x = 100;
       txt1.y = 100;
       txt1.width = 350;
       txt1.height = 30;
       txt1.border = true;
       txt1.selectable = false;
       txt1.text = "倒计时:";
       timer.addEventListener(TimerEvent.TIMER,onTimerHandler);
       timer.addEventListener(TimerEvent.TIMER_COMPLETE,onTimerCompleteHandler);
      }
      private function onLoaderInfoHandler(event:Event):void
      {
        stage.addChild(loader);
        loader.addEventListener(MouseEvent.CLICK,onLoaderHandler);
      }
      
      private function onLoaderHandler(event:MouseEvent):void
      {
          txt1.appendText(txt.text + "/")
      }
      private function onTimerCompleteHandler(event:TimerEvent):void
      {
         trace("计时完成!");
      }
      protected function onTimerHandler(event:TimerEvent):void
      {
       txt.text = String(timer.currentCount);
              //num++;
        //if (num == 5)
        //{
          // timer.stop();
        //}
        //trace(num);
      }
     }

    }

    我就是我,颜色不一样的烟火。 ----辉。
  • 相关阅读:
    让资源管理器不显示最近常用文件夹
    票房实际是屌丝血
    为什么读了很多书,还是过不好这一生?
    抱怨就像呕吐
    finally关键字小复习
    Java中菜单组件
    Java的GUI窗体出现乱码解决方法
    Java中GUI的默认窗体布局 和 常见的窗体布局方案
    适配器类(便利类)的由来:当你自己写的类中想用某个接口中个别方法的时候(注意:不是所有的方法),肿么办?
    技术管理者工作成效评估表
  • 原文地址:https://www.cnblogs.com/klh5211314/p/2710596.html
Copyright © 2020-2023  润新知