`
zeebly
  • 浏览: 1411 次
  • 性别: Icon_minigender_1
  • 来自: 广州
最近访客 更多访客>>
社区版块
存档分类
最新评论

【AS3】关于Event.ADDED_TO_STAGE

阅读更多
我们都知道Event.ADDED_TO_STAGE在使用  addChild()函数,将显示对象添加到舞台时触发:addChild(my_mc);  触发该事件

var my_obj:a_class= new a_class();
addChild(my_obj)
上面的代码中,是先触发a_class里的函数,然后因为addChild()而触发Event.ADDED_TO_STAGE事件

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

主文档类:


package {
import flash.display.Sprite;
import flash.events.Event;
public class ats_example extends Sprite {
  public function ats_example() {
   var child:a_child = new a_child();
   addChild(child);
  }
}
}a_child类:


package {
import flash.display.Sprite;
import flash.events.Event;
public class a_child extends Sprite {
  public function a_child() {
   trace("this is the stage: "+stage);
   trace("this is my parent: "+this.parent);
  }
}
}  会发现输出结果为:     this is the stage: null   this is my parent: null  当我使用Event.ADDED_TO_STAGE事件来修改一下a_child类:  package {
import flash.display.Sprite;
import flash.events.Event;
public class a_child extends Sprite {
  public function a_child() {
   addEventListener(Event.ADDED_TO_STAGE, init);
  }
  function init(e:Event):void {
   trace("this is the stage: "+stage);
   trace("this is my parent: "+this.parent);
  }
}
}


会发现输出的结果是:
   this is the stage: [object Stage]this is my parent: [object ats_example]//上述表明虽然执行了a_Child里的构造函数  但是由于不存在addChild()函数的触发  所以init函数并没有触发   而是在文档类中将其添加进舞台,而返回去a_child构造函数类的init()函数**************************************************  上面的方法给我提供另一种途径去延缓某个类 相关方法的执行

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/hu36978/archive/2009/12/31/5113465.as
分享到:
评论

相关推荐

    Flex面试.pdfFlex面试.pdf

    this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage); drawCircle(100, 100, 50, 0xFF0000); } public function drawCircle(x:uint, y:uint, radius:uint, color:uint):void { var circle:Sprite...

    javascript_to_flash_as3.0.rar

    在AS3.0中,可以通过`Event.ADDED_TO_STAGE`或`Event.COMPLETE`事件来监听加载状态。 5. **优化技巧**:为了提高性能,应该避免频繁的JavaScript与Flash通信。可以考虑批量处理数据,或者使用缓存机制减少不必要的...

    一个简单的as3例子

    stage.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage); } private function onAddedToStage(event:Event):void { // 在这里执行添加到舞台后的操作 } } } ``` 2. **组件(Components)**:Flex...

    Flash Develop安装与配置

    else addEventListener(Event.ADDED_TO_STAGE, init); } private function init(e:Event = null):void { removeEventListener(Event.ADDED_TO_STAGE, init); trace("Hello, World!"); } } } ``` 当你运行...

    用as3写的加载进度条

    在AS3中,我们可能在`EnterFrame`事件或`Event.ADDED_TO_STAGE`事件的监听器中执行初始化代码。对于进度条,这可能包括设置其初始位置和大小,以及绑定加载事件的监听器。 6. **代码示例** 创建进度条的简单步骤...

    ActionScript3.0语言和组件参考API chm

    而`flash.events.Event`类则定义了所有事件的基础结构,包括常见的如`Event.ENTER_FRAME`,`Event.ADDED_TO_STAGE`等,开发者可以通过监听这些事件来控制程序的流程。 CHM(Compiled Help Manual)是一种由...

    ActionScript.3.0.Cookbook.Oct.2006.chm

    stage.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage); function onAddedToStage(event:Event):void { trace("Stage is added to the display list."); } ``` - **作用:** 响应用户的交互行为,如...

    BURNINTEST--硬件检测工具

    will need to be sent to Microsoft as per the normal process. However, a log entry will be added to the normal BurnInTest log. - Changes to trace logging to reduce activity when trace logging is not...

    AS3 横向-竖向 滚动条 带源码

    - 添加事件监听器,如ADDED_TO_STAGE事件,用于在组件被添加到舞台时初始化滚动条。 4. **响应式设计**: - 滚动条应具有响应式设计,能根据内容的大小和窗口的尺寸自动调整自身。 - 可以通过添加Resize事件监听...

    flex快速上手(中文)

    this.addEventListener(Event.ADDED_TO_STAGE, init); } private function init(event:Event):void { var label:Label = new Label(); label.text = "Hello, World!"; this.addChild(label); } } ``` 这段...

    LCTF软件备份VariSpec™ Liquid Crystal Tunable Filters

    although they can be called in an asynchronous mode where the function returns as soon as all commands have been sent to the VariSpec, without waiting for them to run to completion. Another option ...

    UMAP Journal 38.2 2017 ICM Contest

    It's a chance to challenge your brain, solve a real world math problem, and get recognition for it on an international stage. It's an excellent opportunity to develop your interpersonal skills ...

    深入FLEX组件生命周期

    this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage); } } ``` ##### 2. Configuration(配置) **定义**:配置阶段用于完成组件的详细配置,包括设置组件的属性、事件回调函数、样式以及效果定义等。...

Global site tag (gtag.js) - Google Analytics