Load external assets

I’d like to load assets instead of embedding them without having to change my entire code at this point.
The customer has to be able to edit our XML files without having to recompile.

I tried Assets.loadText() instead of getText() but that requires a handler which isn’t only undocumented, I presume that it’s asynchronous and will simply lead to way more problems than are reasonable to fix.

EDIT: Well, thanks for the shit documentation. But I think I’ve got it. Basically I implemented a loader class that uses loadText(), then stores that so you can use it later. It counts the files it has to load (because asynchronous code -.-) and if the last file is loaded then it calls a callback function to start the application.

EDIT2: So while looking into adding the documentation myself I found that it’s already been fixed in trunk.

1 Like

If you’re on native, you can use File.getContent to load a local file, you can also use the (longer and asynchronous) URLLoader class to do the same. By default on native platforms, there is a “manifest” file while provides detail about assets (and can be changed after a compile, such as for live asset reloading) and ultimately points to your files, located on disk unless you set “embed” to true in your XML.

What target are you using? If you are targeting Flash, there is no way to synchronously load a file, although I am thinking, it may be nice to have a hybrid system (more similar to the HTML5 target) that preloads content, but does allow it to actually exist on disk instead of stuffing it into the SWF.