克隆嵌入的SWF类SWF

2023-09-08 15:24:39 作者:漂流

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

Is there a way to clone an embedded class? Because otherwise, I can't directly use my custom methods.

这是内部的类不工作嵌入。

Embedding from within the class doesn't work.

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;
     }
 }
}

从类的外部嵌入,也不起作用。

Embedding from outside the class, also doesn't work.

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
     }
 }
}

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

Or maybe there is a way to instantiate a class from an embed and convert it to another class? Thanks.

推荐答案

我想你要找的东西是这样的:

I think what you're looking for is this:

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

如果该影片剪辑要导入只有1帧,则可能需要将其更改为播放器扩展Sprite 。当然,这段代码假设您已经导出的影片剪辑的ActionScript和从Flash IDE内部给它的类名球员。如果你有麻烦,你可以看看这里的一步一步的演练。

If the MovieClip you are importing only has 1 frame, you might need to change it to Player extends Sprite. This snippet of course assumes that you have exported the MovieClip for ActionScript and given it the Class name "Player" from inside the Flash IDE. If you are having trouble you can look here for a step-by-step walkthrough.