克隆嵌入式swf类

时间:2011-03-08 16:33:03

标签: actionscript-3 flash embedded-resource

有没有办法克隆嵌入式类?因为否则,我不能直接使用我的自定义方法。

从课堂内嵌入不起作用。

package  {
 import flash.display.Sprite;

 public class Player {
     public var player:Sprite;
     [Embed(source = '../lib/player.swf')] private var swf:Class;
     public function Player() {
         this = new swf(); // doesnt work
     }
     public function method1():void {
         return;
     }
 }
}

从课外嵌入,也不起作用。

package  {
 import flash.display.Sprite;

 public class Main {
     public var player:Player;
     [Embed(source = '../lib/player.swf')] private var swf:Class;
     public function Main() {
         player = Player(new swf()); // doesn't work
         player = new swf() as Player; // doesn't work
     }
 }
}

或许有一种方法可以从嵌入中实例化一个类并将其转换为另一个类?感谢。

1 个答案:

答案 0 :(得分:2)

我认为您正在寻找的是:

[Embed(source = '../lib/player.swf', symbol='Player')]
public class Player extends MovieClip
{
    // Continue with class code as before

如果您导入的MovieClip只有1帧,则可能需要将其更改为Player extends Sprite。这个片段当然假定您已经为ActionScript导出了MovieClip,并在Flash IDE中为其指定了类名“Player”。如果您遇到问题,可以查看here一步一步的演练。