Error when trying to grab MovieClip from swf

Continuing the discussion from How does Assets.loadLibrary() work now?:

Hello,

first of all thank you for great work on the library. It is real pleasure to work in it.
But from time to time (new versions of libraries?) something is wrong.

Now, when I try to load swf assets with this code:

Assets.loadLibrary("assets/library.swf", function (_) {
    var r = Assets.getMovieClip("library:Rect");
    addChild(r);
});

i get this error (flash compilation):

ReferenceError: Error #1065: Zmienna JSON nie została zdefiniowana.
at lime::Assets$/loadLibrary()
at openfl::Assets$/loadLibrary()
at ApplicationMain$/init()
at lime.app::Preloader/start()
at openfl.display::Preloader/display_onComplete()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at NMEPreloader/onLoaded()
at openfl.display::Preloader/start()
at lime.app::Preloader/current_onEnter()

my current setup is:

actuate: [1.7.5]
aether: [1.7.1]
format: [3.1.2]
hxcpp: [3.1.39]
lime-tools: [1.5.7]
lime: [2.0.0]
openfl-samples: [2.1.0]
openfl-tools: [1.0.10]
openfl: [2.1.6]
svg: [1.0.8]
swf: [1.7.0]

and of course in my application.xml i have:

<haxelib name="swf" />
<library id="librarySwf" path="assets/library.swf" type="swf"/>

Any clues what can be wrong?

When you set the library ID, I believe this should be what you pass to loadLibrary:

Assets.loadLibrary ("librarySwf", function (_) trace ("Loaded!"));

I tried your suggestion…

Assets.loadLibrary(“ashLib”, loadedLib (_) trace (“Loaded!”));

but get an ‘Unexpected trace’ error, if remove the trace I get ‘Unknown identifier : _’

Any ideas?

You need to either create a local anonymous function like @singmajesty wrote:
Assets.loadLibrary ("librarySwf", function (_) { /* body here */ });
or pass a function:
Assets.loadLibrary ("librarySwf", myFunction);

Thanks, yeah I eventually figured out the code change and the need to use > function in the first option, not the function name as I had previously used…

The reason for the search was I had already been using the 2nd option, but with the latest lime updates trying to recompile the output was now broken throwing the error…

openfl.AssetLibrary -> Void should be lime._Assets.LimeAssetLibrary -> Void

Is it still possible to pass a function and assign a variable to the call back for later use?

i.e. var library:AssetLibrary;

I would recommend using an underscore _ instead of handling the library value for now, or if you must handle the library, using Dynamic as the type, this is something I’m going to have to look into. You can use <library path="to/file.swf" preload="true" /> now to preload your library, of all choices, that might be the very easiest one – it calls loadLibrary for you :slight_smile:

Just for the record, there’s nothing special about using an underscore as an argument. You know how you can start variable names with an underscore, right? This is just a degenerate case where you start with an underscore and don’t add any more characters.

If you check the inferred type using $type(_);, you’ll get “Unknown<0>,” just like if you named it anything else.

It is real syntax for ignoring a value when you are writing a switch case, and I think maybe in some other places. As its used there clearly for ignoring a value, I think it’s good convention elsewhere :slight_smile: