zoukankan      html  css  js  c++  java
  • 关于Event.ADDED_TO_STAGE

    一. Event.ADDED_TO_STAGE的作用和使用方法

    Event.ADDED_TO_STAGE在使用  addChild()函数,将显示对象添加到舞台时触发。

    例如:addChild(my_mc);  该方法add完成后会触发该事件

    var my_obj:a_class= new a_class();
    addChild(my_obj);

    上面的代码中会先触发a_class里的函数,然后因为addChild() 而触发Event.ADDED_TO_STAGE事件。

    我们看两组不同的例子   来验证Event.ADDED_TO_STAGE

    主文档类:

     1 package {
     2     import flash.display.Sprite;
     3     import flash.events.Event;
     4     public class ats_example extends Sprite {
     5         public function ats_example() {
     6             var child:a_child = new a_child();
     7             addChild(child);
     8         }
     9     }
    10 }
    a_child类:
     1 package {
     2     import flash.display.Sprite;
     3     import flash.events.Event;
     4     public class a_child extends Sprite {
     5         public function a_child() {
     6             trace("this is the stage: "+stage);
     7             trace("this is my parent: "+this.parent);
     8         }
     9     }
    10 }

    会发现输出结果为:  

    this is the stage: null
    this is my parent: null

    当我使用Event.ADDED_TO_STAGE事件来修改一下a_child类:

     1 package {
     2     import flash.display.Sprite;
     3     import flash.events.Event;
     4     public class a_child extends Sprite {
     5         public function a_child() {
     6             addEventListener(Event.ADDED_TO_STAGE, init);
     7         }
     8         function init(e:Event):void {
     9             trace("this is the stage: "+stage);
    10             trace("this is my parent: "+this.parent);
    11         }
    12     }
    13 }

    会发现输出的结果是:

    this is the stage: [object Stage]
    this is my parent: [object ats_example]

    //上述表明虽然执行了a_Child里的构造函数 但是由于不存在addChild()函数的触发 所以init函数并没有触发 而是在文档类中将其添加进舞台,而返回去a_child构造函数类的

    init()函数

    **************************************************

    上面的方法给我提供另一种途径去延缓某个类相关方法的执行

  • 相关阅读:
    用Bootstrap框架弹出iframe页面 在弹出的模态框中载人iframe页面,bootstrapiframe
    Jquery Ajax表单提交插件jquery form用法
    ASP.NET MVC 在控制器中接收视图表单POST过来的数据方法
    RabbitMQ用户管理+VirtualHost管理
    Linux 查看Oracle 信息
    页面元素的坐标位置
    Selenium之Action Chains类
    测试管理:用量化的思想管理工作
    Python selenium ---父子,兄弟,相邻节点定位方式详解
    webdriver 清空input元素的值
  • 原文地址:https://www.cnblogs.com/hisiqi/p/2714900.html
Copyright © 2011-2022 走看看