avatar
Today is 星期六
2010 年 09 月 04 日

2009 年 07 月 03 日

getDefinitionByName+Embed使用,未定义错误

by fireyang — Categories: actionscript, flex — 标签:, , 评论暂缺

getDefinitionByName的用处是可以通过字符串映射的取到相应的类。
但是如果你在一个类中,embed一个图片,将这个图片声明为一个class 。这样用getDefinitionByName来调用,就会出现“未定义错误”。

package
{
	import flash.display.Bitmap;
	import flash.display.MovieClip;
	import flash.utils.getDefinitionByName;

	/**
	 * ...
	 * @author FireYang
	 */
	public class embedTest extends MovieClip
	{
		[Embed(source="tile1.png")]
		private var tile1:Class;

		public function embedTest()
		{
			var string:String = "embedTest_tile1";//所在类名+"_"+embed的类名
			var c:Class = getDefinitionByName(string) as  Class;
			var b:Bitmap = new c();
			b.x = 100;
			b.y = 100;
			trace(b);
			addChild(b);
		}
	}
}

采用上面的形式,红色部分是重点,就没问题了!原因还没找到,呵呵,但是测试了没错!

评论暂缺 »

还没有任何评论。

发表评论

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

© 2010 fireyang’blog All rights reserved - Wallow theme by TwoBeers Crew - Powered by WordPress - Have fun!浙ICP备07033342号