我有带MovieClip的HintMenu.swf库:
public class PopupMenuItem extends MovieClip {
[Embed(source="HintMenu.swf", symbol="ExternalMovie")]
private var woodButtonClass:Class;
public var activeItemSkin:MovieClip;
public function PopupMenuItem(
activeItemSkin = new woodButtonClass();
)
但是一开始,我收到以下错误:
[Fault] exception, information=TypeError: Error #1034: Type Coercion failed:
cannot convert energy.ui.alts.component.popup::PopupMenuItem_woodButtonClass@a7c0e19 to
flash.display.MovieClip.
稍后我需要将它用作MovieClip。任何解决方案?
答案 0 :(得分:1)
使用as MovieClip
。
activeItemSkin = new woodButtonClass() as MovieClip;
您需要确保woodButtonClass
实际上是MovieClip
。如果不是,则activeItemSkin
将为空。
答案 1 :(得分:0)
实际上你不能将1帧的嵌入MovieClip转换为MovieClip。 优化原因Flash IDE将其转换为Sprite:
package {
import flash.display.DisplayObjectContainer;
import flash.display.MovieClip;
import flash.display.Sprite;
[SWF(backgroundColor="0x333333")]
public class Test_MultipleSwfEmbed extends Sprite{
[Embed(source="swf/HintMenu.swf", symbol="button1")]
private var oneFrameMovieClip:Class;
[Embed(source="swf/HintMenu.swf", symbol="button2")]
private var twoFramesMovieClip:Class;
public function Test_MultipleSwfEmbed() {
//"is MovieClip" = true, when > 1 frame
traceType(new oneFrameMovieClip()); // false, true, true
traceType(new twoFramesMovieClip()); // true, true, true
}
private function traceType(mc:*):void {
trace(mc is MovieClip, mc is Sprite, mc is DisplayObjectContainer);
}
}
}