Search code examples
actionscript-3flashhaxe

Creating a class for a Flash symbol in Haxe?


I am having trouble incorporating graphical assets created in Flash with my Haxe code.

In the Flash IDE, I've created a symbol with the linkage name "MySprite". I compile this into assets.swf. I know that to use symbols in this .swf from my Haxe code, I need to add the following option when using the Haxe compiler:

-swf-lib assets.swf

I'd now like to write a class called "MySprite" which is associated with this symbol, like so:

class MySprite extends Sprite {
    public function new() {
        // ...
    }
}

Basically, I'd like to achieve something similar to the technique presented in this tutorial:

package {
    import flash.display.*;

    [Embed(source="assets.swf", symbol="MySprite")]
    public class MySprite extends Sprite {
         public function MySprite() {
             // ...
         }
    }
}

It's unclear from the Haxe documentation whether this can be done, or what the syntax is for doing it.


Solution

  • I think so, but I'm not sure, Haxe doesn't override classes from assets.swf with the classes you declared. There was a discussion about it on the mailing list (the old one, not in the Google groups), and this was the decision... I don't know why this decision was made.

    You could still do it with SamHaxe. At least back in the days I was able to. Unfortunately, SamHaxe was abandoned, and if there are bugs or something not working as you need it - you are pretty much on your own. The good thing about Sam is that it's relatively small project. It's written in Haxe and I was able to build it from sources.

    You could also try: http://code.google.com/p/hxswfml/ The project seems to be functional and the author used to reply to users. It might be a tad more complex though. I'm quite sure it was possible to do, but you will probably need to ask the author / figure it out yourself.