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 }

  • 相关阅读:
    转:Java 6 JVM参数选项大全(中文版)
    转:Http Get Post put delete
    转:Google MapReduce中文版
    转:java.net.SocketException: Too many open files解决方法
    转:UML类图基础
    转:Maven常用命令
    转:ibatis配置简介
    转:导出 Oracle 数据库中所所有用户表的表结构
    C# 中使用iTextSharp组件修改PDF元数据(title,Keywords等)
    SQL Server跨服务器查询
  • 原文地址:https://www.cnblogs.com/zack/p/1439421.html
Copyright © 2011-2022 走看看