SWF haxelib does not seem to render the MovieClip

Following up from a discussion that ibilon asked me to create a new thread for this particular issue as apparently it’s unrelated to the topic, which I beg to differ. Whichever the case, I have done a cut and paste and have been encouraged to spam the forums with new threads.

I do have a question regarding the swf library. This page explains that the library works in native, but I can’t seem to get it to work with this code (using the latest OpenFL 3.1 and Lime 2.4.4 with swf version 1.8.7):

class Main extends Sprite 
{
    
    private var clip:MovieClip;
    private var timeLoaded:Date;
    
    public function new() 
    {
        super();
        
        Assets.loadLibrary("game", function(_) {
            clip = Assets.getMovieClip("game:");
            clip.gotoAndStop(0);
            addChild(clip);
        });
        timeLoaded = FileSystem.stat("libraries/game/game.swf").ctime;
        trace(timeLoaded.getTime());
        
        addEventListener(Event.ENTER_FRAME, load);
    }
    
    private function load(e:Event)
    {
        #if sys
        if (FileSystem.exists("libraries/game/game.swf"))
        {
            var fi = FileSystem.stat("libraries/game/game.swf");
            if (fi.ctime.getTime() > timeLoaded.getTime())
            {
                trace("Some time");
                Assets.loadLibrary("game", function(_) {
                    clip = Assets.getMovieClip("game:");
                    addChild(clip);
                });
                timeLoaded = fi.ctime;
            }
        }
        #end
    }
    
}

The swf library I’m loading looks like this, but the result seems to be a white screen for some reason. Does the swf library actually work in native targets, or is there a bug? I have also tried legacy and that seems to also result in a blank screen, which is very odd.

EDIT: After testing in Flash, I have encountered an error using the swf file in 3.1 with the following:

VerifyError: Error #1053: Illegal override of writeByte in haxe.io.BytesOutput.
ReferenceError: Error #1065: Variable boot_1838 is not defined.

Now I’m wondering if the “swf” haxelib library works on Haxe-developed SWF’s or only Flash Pro developed SWF’s… or should it not matter?

What happens if you remove the gotoAndStop()? What happens if you use type="swflite" in your XML?

I removed the gotoAndStop() after realising it didn’t make a blind bit of difference.

http://prntscr.com/7k4oxo is the result when using the type “swflite” which now actually explains the errors, which unfortunately do not provide me with any closer of a solution than before…

Does adding preload="true" to your library tag help?

I’m trying out a lot of different things, with my latest result looking like this:

But I’m assuming that’s because the Main is a class (the entry point for the SWF) and not a Symbol. The preload="true" tag is not very useful in my case as I am trying to experiment with live previewing with my editor, using command-line tools to make that happen, hence experimenting with loading SWF files.

I did do a trace on clip.numChildren and that resulted in 0, so I’m thinking that the entire timeline is loaded as a MovieClip but the Main entry point wasn’t executed. Is there a way to execute it from the SWF resource, or is that what Assets.getMovieClip() does internally? I’m not 100% sure how MovieClip’s work.

Well, let’s get to a point where things work, and work backward.

You can double-check that the SimpleSWFLayout sample works, then you can see if your assets load for you alright using a simple vanilla project, but with different assets, and we can work from there to isolate what might be going on

Ah, okay, so I notice that the library being loaded using the <library> tags also needs <haxelib> tag to work, pointing to that library?

I’ve packaged my StoryDev engine (which was what I was originally testing) and did a haxelib local StoryDev.zip.

Using the SWFLayout project as template, I now have an XML file containing the following:

<?xml version="1.0" encoding="utf-8"?>
<project>
    
    <meta title="Simple SWF Layout" package="org.openfl.samples.simpleswflayout" version="1.0.0" company="OpenFL" />
    <app main="Main" path="Export" file="SimpleSWFLayout" />
    
    <window width="0" height="0" if="web" />
    
    <source path="Source" />
    
    <haxelib name="openfl" />
    <haxelib name="swf" />
    <haxelib name="StoryDev" />
    
    <library path="Assets/StoryDev.swf" preload="true" />
    
    <source path="Assets" />
    <icon path="Assets/openfl.svg" />
    
</project>

and Main.hx containing the following:

//import layout.Layout;
//import layout.LayoutItem;
import openfl.display.MovieClip;
import openfl.display.Sprite;
import openfl.events.Event;
import openfl.utils.ByteArray;
import openfl.Assets;

class Main extends Sprite {
    
    
    private var clip:MovieClip;
    //private var layout:Layout;
    
    
    public function new () {
        
        super ();
        
        var clip = Assets.getMovieClip ("StoryDev:");
        addChild (clip);
        
        //layout = new Layout ();
        //
        //layout.addItem (new LayoutItem (clip.getChildByName ("Background"), STRETCH, STRETCH, false, false));
        //layout.addItem (new LayoutItem (clip.getChildByName ("Header"), TOP, STRETCH, true, false));
        //layout.addItem (new LayoutItem (clip.getChildByName ("Column"), STRETCH, LEFT, false, true));
        //
        //layout.resize (stage.stageWidth, stage.stageHeight);
        //stage.addEventListener (Event.RESIZE, stage_onResize);
        
    }
    
    //
    //private function stage_onResize (event:Event):Void {
        //
        //layout.resize (stage.stageWidth, stage.stageHeight);
        //
    //}
    
}

Now, using just StoryDev: in the Assets.getMovieClip() function results in Flash player preloading being stuck at 0, as if it can’t load the library. And using StoryDev:Main with the function results in a Stack Overflow error, something that looks like this.

Judging by that error, I can tell that Flash can now see what StoryDev is, and it’s instantiating the Main object it’s finding over-and-over again for whatever reason. You can find the code here for the engine I’m using to embed.

Using this same process, but omitting the preload option in XML of my actual live preview project, I am able to get the result of this from neko:

And the final XML in my live preview project looks like this:

<?xml version="1.0" encoding="utf-8"?>
<project>
    <!-- NMML reference: https://gist.github.com/1763850 -->
    
    <!-- metadata, make sure 'package' is at least 3 segments (ie. com.mycompany.myproject) -->
    <meta title="Twinspire" package="Twinspire" version="1.0.0" company="Colour Multimedia Enterprises" />
    
    <!-- output -->
    <app main="Main" file="Twinspire" path="bin" />
    
    <window background="#FFFFFF" fps="60" />
    <window width="800" height="480" unless="mobile" />
    <window orientation="landscape" vsync="false" antialiasing="0" if="cpp" />
    
    <!-- classpath, haxe libs -->
    <source path="src" />
    <haxelib name="openfl" />
    <haxelib name="swf" />
    <haxelib name="StoryDev" />
    
    <library path="assets/lib/game.swf" />
    
    <!-- assets -->
    <icon path="assets/openfl.svg" />
    
    <!--<haxeflag name="-D hscriptPos" /> -->
    <haxeflag name="-dce" value="no" /> 
    
</project>

I think it might just boil down to the fact that the SWF project I’m trying to load has code that even the Flash target doesn’t like embedding. Or I installed the haxelib incorrectly, because whenever I try to use an import to StoryDev, the compiler just tells me that the StoryDev type does not exist, meaning that I can’t use any of its supposed types which would otherwise exist, because I’m pretty sure they do.

The SWF library is currently designed only for SWF assets, no SWF code, so perhaps the issue is that you may be referencing a class, not a symbol. Does it work if you use “StoryDev:MyLinkedSymbol” or something like that?

There are ways to embed SWF assets, classes and all, in the Flash target, but not elsewhere, because there is no AVM elsewhere

Ah okay, so in theory I could encapsulate my entire engine into a MovieClip, the acting symbol, and have all the scenes and such render there?

That’s something I will definitely look into.