ActionScript 3 : Get a Class Reference by Class Name

本文介绍如何在ActionScript 3中通过类名动态获取类的引用,利用`getDefinitionByName`方法实例化指定路径的类。这对于需要动态加载类的情况非常有用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ActionScript 3 : Get a Class Reference by Class Name

with 37 comments

If you need to get a reference to a class in ActionScript 3, but only know the class name, then you can use the flash.utils.getDefinitionByName to create an instance of the class.

For example:

package
{
	import flash.display.Sprite;
	import flash.utils.getDefinitionByName;

	public class DynamicCall extends Sprite
	{
		public function DynamicCall()
		{
            var ClassReference:Class = getDefinitionByName("String") as Class;
            var s:String = (new ClassReference("foo=") as String);
            trace(s);
		}
	}
}

This basically creates an instance of the String class, from the class name “String”. getDefinitionByName takes the entire class path, so if you wanted to create an instance of MovieClip, you would provide the entire path:

            var ClassReference:Class = getDefinitionByName("flash.display.MovieClip") as Class;

Anyways, pretty simple stuff, but can come in useful.

http://www.mikechambers.com/blog/2006/06/22/actionscript-3-get-a-class-reference-by-class-name/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值