Extending Haxe class in Flash/Animate (SWF lib)

I’m trying to integrate some animations made in Flash/Animate in a OpenFL app.
To do so I’m using the OpenFL SWF library. In my project.xml I have this:

<haxelib name="swf" />
<library path="assets/library.swf" prefix="View" generate="true" preload="true" />

So far, so good.
The problem is that I can’t control the animation with stop(); (or any other kind of timeline script) in my swf, because the SWF lib doesn’t support it just yet.

My current solution involves frame labels.
To put it simply, I just add special values in labels in the main timeline and read them in Haxe.
This works but isn’t automated (I have to parse each class in the swf manually) and, to use the classes the way I want, I have to do some composition.
I think that inheritance is a better approach, and to do this I need to make every exported movieclip extend a class that does the label parsing, but than again, I can’t use AS3.

Looking the Haxe generated code I see that before compiling the target code (e.g. HTML5), because I set the generate="true" property, the OpenFL creates the classes that is set to be exported from the swf.
If I change the files to extend some other class than openfl.display.MovieClip and send this to Haxe compiler instead I get the intended behavior.

The final “wall” is how to automate this without having to change every generated file by hand (which would destroy the sole purpose of automation)?
If not, what are the alternatives (if any)?

Is this the line you mean?


This will only apply to the Flash target, you currently need to use format.swf.instance.MovieClip as the base class, but there are ideas to move the needed functionality into OpenFL core, so that OpenFL MovieClips include the functionality needed to make it work

Ahn, I don’t think so. I’m compiling to JS, so, no “flash only” code…

To better illustrate my workaround, look at the following.
This is how I configured my movieclip in Flash/Animate:

And here is my hx project:

As you can see I’ve changed the (automatically) generated ViewTestAnim class to extend my TestBase class, which in turn extends from format.swf.lite.MovieClip (originally, ViewTestAnim extended from format.swf.lite.MovieClip directly).

After this, I just compile the project again. Since the class exists in the bin folder, the compiler doesn’t generate it again, thus preserving my modification.
This works as expected and the console traces the “Hello World” correctly.

But it’s a manual hack that relies on a behavior that may change in future. Besides, if I clean the project I have to modify every exported class again.

To automate the process the compiler should just copy&paste the value under “Base Class” (on Flash/Animate) to the generated class… Basically a “fire and forget” process.

Am I wrong and that isn’t as simples as it looks?

For now, I think your cleanest solution is to have your own format.swf.lite.MovieClip class in a classpath you include after the SWF library. Make the modifications you need there, then that will apply your core render logic.

Hopefully we can come up with a better solution long-term, if we merge the SWFLite support into OpenFL core, then we could allow custom base classes

Thank you, Granick! =]

I just copied the format.swf.lite.MovieClip class to my source path and changed it to extend my base MovieClip (that, in turn, extends the openfl.display.MovieClip class).
That worked better than I expected… ;D

And there is a bonus (or a downside, depends on how you look at it): Every movieclip exported from Flash/Animate now extends my base class (can be a downside because there is no “opt-out”).

Hope to see this lib integrated into core soon enough!!

1 Like

Hi ,this topic is similar to my requirement
instead of custom base class , I want to “edit” the generated class file (after openfl test … generated class will be rewritten )
If write my own (instead of editing) ,error: Type name XXX is redefined from module XXX
So if there is a way to “disable" the generated class if there is a custom class(the same name) , use custom-class for compiling
Or if there a way to add additional script to the generated class file in haxe ?
Or maybe let a script to replace generated class with custom class before compiling ?
Or anyother better way ?