how to create a AS3 dynamic class and how to use it?

↘锁芯ラ 提交于 2020-01-03 02:39:09

问题


What is a dynamic class and what are its uses and how to create and use a dynamic class?

Can anyone guide me to a good tutorial please?


回答1:


Here You can find basic info : http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/statements.html#dynamic

Dynamic class allow You to add additional dynamic params to object in run-time .

For example : Sprite isnt dynamic , so You cannot do thing like :

var sprite:Sprite = new Sprite ();
sprite["value"] = 10; // this will throw ReferenceError

But MovieClip is dynamic instance that allow You to add dynamic params :

var mclip:MovieClip = new MovieClip();
mclip["value"] = 10;

To make class instance dynamic , You have to add 'dynamic' key word to declaration :

public dynamic class MyClass { ...



回答2:


A dynamic class is basically one that can be modified at runtime. One of the main uses of this feature is when extending the Proxy class.

A couple of good examples:

http://manishjethani.com/archives/2008/08/25/jsonobject-for-reading-and-writing-json-in-actionscript http://manishjethani.com/archives/2008/12/19/guaranteeing-enumeration-order-in-for-in-loops



来源:https://stackoverflow.com/questions/9514479/how-to-create-a-as3-dynamic-class-and-how-to-use-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!