`
steely816
  • 浏览: 130078 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

AS3的dynamic类

    博客分类:
  • as3
 
阅读更多
  1. dynamic  class  Person{  
  2.   public   var  firstName:String =  "Joe" ;  
  3.   public   var  lastName:String =  "Doe" ;  

 

我们可以创建Person的实例,动态的增加属性,还可以覆盖其原有的方法,比如覆盖toString()方法:
var p:Person = new Person();
p.age = 25;//动态增加属性
p.toString = function():String{//覆盖原有方法
  return p.lastName + "," + p.firstName + "-" + age;
}

trace(p);//输出结果:Doe,Joe-25

应该注意动态的增加属性或覆盖原有方法时,该dynamic类的属性是private的,我们便不能访问到该属性。例如:
假设我们使Person这个对象的lastName是private,而不是public,那么我们的输出结果就是:Undefined,Joe-25.

给对象增加或覆盖原有方法其实与给对象增加属性一样,其实一个function的添加等同于给对象添加了一个类型为
Function的属性.

  1. public   class  JavaProgrammer{  
  2.   public   var  lastName:String =  "Mr.Interface" ;  
  3.   public   function  learnFlex(): void {  
  4.    trace(lastName + "is ready for RIA work!" );  
  5.  }  

接下来Person的一个实例对象便可以通过如下方式来访问learnFlex()方法:

  1. var  p:Person =  new  Person();  
  2. var  jp:JavaProgrammer =  new  JavaProgrammer();  
  3. p.boostCareer = jp.learnFlex; 

 

接下来,调用这个方法:
p.boostCareer();//输出结果:Mr. Interface is ready for RIA work!

还有一个值得注意的地方就是,我们动态的添加属性或方法,或覆盖原有方法,都需要该类是dynamic类型的。

分享到:
评论

相关推荐

    AS3的BASE64编码与解码类

    今天在国外网站上淘到一个很好用的AS3的BASE64类 感觉写得简洁而强大。很好,赶快放上来。 调用代码: import com . dynamicflash . utils . Base64 ; //编码和解码字符串 var source : String = "Hello, world" ...

    FLASH As3_basic 入门源码

    【描述】提到"类源码",意味着压缩包中的代码主要基于AS3的类结构。在AS3中,类是创建对象的蓝图,支持面向对象编程(OOP)特性,如封装、继承和多态。通过分析这些类源码,学习者可以了解如何定义类、创建实例、...

    Dynamic Noncooperative Game Theory

    The first edition was fully revised in 1995, adding new topics such as randomized strategies, finite games with integrated decisions, and refinements of Nash equilibrium. Readers can now look forward ...

    Dynamic SQL(Apress,2016)

    Executing dynamic SQL is at the heart of applications such as business intelligence dashboards that need to be fluid and respond instantly to changing user needs as those users explore their data and ...

    Dynamic Positioning Systems

    A positioning system, such as dynamic positioning (DP) and joystick, is the ‘enduser’ of other equipment on a vessel and plays also the role as an integrating factor for the vessel operation. Rolls-...

    SAE AS6944 -2023 Dynamic Seal Test Fixture.pdf

    SAE AS6944 -2023 Dynamic Seal Test Fixture.pdf

    as3审计模式

    ### 关于AS3审计模式与设计模式的理解 #### 标题理解:“AS3审计模式” 在软件工程领域,“审计模式”并非一个常见的术语,尤其是在ActionScript 3.0(简称AS3)这样的上下文中。然而,结合上下文及提供的部分信息...

    Dynamic Tracing Guide PDF

    3,PDF格式。4,带目录。 Preface DTrace is a comprehensive dynamic tracing framework for the illumos™ Operating System. DTrace provides a powerful infrastructure to permit administrators, developers, ...

    as3 textfild动态文本滚动条模型

    在ActionScript 3 (AS3)中,`TextField` 是一个重要的显示对象,用于在舞台上显示文本。在处理大量文本时,特别是在用户界面设计中,动态文本滚动条模型是必不可少的功能,它允许用户查看超出舞台可视区域的文本内容...

    Superpixel Soup_ Monocular Dense 3D Reconstruction of a Complex Dynamic Scene

    标题《Superpixel Soup: Monocular Dense 3D Reconstruction of a Complex Dynamic Scene》中提出的技术挑战,是当前计算机视觉领域的研究热点之一,涉及到从单一视角图像中实现复杂动态场景的密集三维重建。...

    PHP and MySQL for Dynamic Web Sites Visual QuickPro Guide 5th Edition (2018)

    Dynamic web sites are flexible and potent creatures, more accurately described as applications than merely sites. Dynamic web sites : - Respond to different parameters (for example, the time of day ...

    nape as3.0 api文档

    Nape是一个高效、强大的物理引擎,专为ActionScript 3.0(AS3)设计。这个API文档是开发者深入理解和使用Nape引擎的关键资源,尤其对于那些希望在Flash平台或者Flex项目中实现复杂的物理模拟效果的开发者来说,它...

    flash as3 加载外部swf jpg gif png loader urlloader的通用代码

    通过以上介绍,我们可以了解到如何在Flash AS3中使用Loader 和 URLLoader 类来加载外部SWF、JPG、GIF 和 PNG 文件的方法。这对于制作复杂的Flash应用和游戏来说是非常有用的技能。掌握了这些知识点后,开发者就能够...

Global site tag (gtag.js) - Google Analytics