Clone embedded swf class

安稳与你 提交于 2019-12-12 04:09:19

问题


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.


回答1:


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

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.



来源:https://stackoverflow.com/questions/5235342/clone-embedded-swf-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!