zoukankan      html  css  js  c++  java
  • FLEX (actionscript3) 设计回调函数范例

     1 package inc
     2 {
     3     public class EventNotifier
     4     {
     5         private var ie:InterestingEvent;
     6                 private var yesNo:Boolean;
     7         public function EventNotifier(event:InterestingEvent)
     8         {
     9             ie = event;
    10                         yesNo = false;
    11         }
    12         public function readyDoWork():void
    13         {
    14             trace("哈哈,设定条件");
    15                         trace("完成一些任务后,把某个条件设为true");
    16                         trace("这样,doWork()就可以工作了");
    17                         this.yesNo = true;
    18         }
    19         public function doWork():void
    20         {
    21             if (yesNo)
    22                         {
    23                             //通知interestingEvent说,可以做它该做的事情了
    24                             ie.interestingEvent();
    25                         }
    26             }
    27     }
    28 }
     1 <?xml version="1.0"?>
     2 <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:local="*" creationComplete="init();">
     3     <mx:Script>
     4         <![CDATA[
     5             import inc.*;
     6             private function init():void{
     7                 var callme:CallMe=new CallMe();
     8                 callme.en.readyDoWork();
     9                 callme.en.doWork();
    10                 trace("done~");
    11             }
    12         ]]>
    13     </mx:Script>
    14 </mx:Application>
    1 package inc
    2 {
    3     public interface InterestingEvent
    4     {
    5         function interestingEvent():void;
    6     }
    7 }

     1 package inc
     2 {
     3     public class CallMe implements InterestingEvent
     4     {
     5         public var en:EventNotifier;
     6         public function CallMe()
     7         {
     8              //创建事件通知对象
     9                      //因为稍候要回调它的interestingEvent()方法,所以要把自身传递出去
    10                      en = new EventNotifier (this);
    11         }
    12         
    13         //当某件事发生后,要让这个方法做的事情
    14         public function interestingEvent():void
    15         {
    16             trace("在这里完成一系列需要回调函数完成的任务");
    17         }    
    18     }
    19 }

  • 相关阅读:
    谈谈年度最佳代码“不管你们信不信,反正我信了”
    如何:用对称密钥对 XML 元素进行加密
    WPF 线程间访问控件
    xml和模型对象之间的序列化和反序列化
    [转]汇编语言的准备知识给初次接触汇编者 3
    asp.net mvc 自定义路由 【asp.net mvc 自学笔记】
    [转]汇编语言的准备知识给初次接触汇编者 2
    sftpd 启动 报错: vsftpd:500 OOPS: bad bool value in config file for: anonymous_enable
    Linux iptables配置FTP的主动和被动模式
    cacti安装完后就停留在登陆界面,输入默认的用户名密码登陆不进去!
  • 原文地址:https://www.cnblogs.com/zack/p/1439421.html
Copyright © 2011-2022 走看看