Using SWF assets

Hi all!

at the moment I’m toying with the idea of porting some old FlashDevelop AS3 projects to
OpenFL - mainly for deploying to HTML5.
For these projects I always create a library .swf file (created in another application and exported as an AVM1 movie) which holds assets like buttons and stuff which are then imported using:

[Embed(source="../assets.swf",symbol='backgroundGradient')]
private var backgroundGradientTemplate:Class;

and instantiated using:

var tempBack:Sprite = new backgroundGradientTemplate();

for example.

After some research I realized I can do almost the same with OpenFl! At least in theory.
Reality is a bit different though.
If I embedd my library and try to use a symbol, e.g.

var test = Assets.getMovieClip ("lib:texBox");

and try to run (targeting flash) the debugger complains:
[openfl.Assets] There is no MovieClip asset with an ID of "lib:texBox"

Well, what should I say, it IS there. :wink:
It’s a MovieClip containing a rounded rectangle as well as a dynamic TextField.
Okay, after some more experiments, changing the instantiation to this

var test = Assets.getMovieClip ("lib:");

and targeting HTML5 I can finally see my symbol.

The text is a bit blurry though and the debugger throws the following errors:
[openfl.text.TextField] WARNING: Could not find required font “Aria”, it has not been embedded
Error: WebGL: texImage2D: Conversion requires pixel reformatting.

So basically this seems to work! What can I do to make it really work?
I’m using OpenFL 4.7.3 and Lime 3.7.2.
You can grab the sample project here: Link

I looked at your sample project and edited it. This works for me no problems and since we have same Openfl&Lime versions (latest) so should work for you (?) :slight_smile:

Link

Hi Flixxel!

Thanks for taking the time!
Unfortunately this doesn’t solve my problem. In your code you’re using another swf
to import assets from. Yours was exported using Flash CS5.5 as an AVM2 movie.
Problem is, I’m not using Flash CSx to create my assets and my application just can
export up to swf8.
I stumbled across this thread: Link
The user seems to have the same problem and it could be solved
by forcing type “swflite” on all targets as @singmajesty pointed out.
I just don’t know what this means. :wink:
I tried:

<library path="assets/lib.swf" generate="true" preload="true" target="swflite" />

but this didn’t change anything either.

It sounds like you have it working

We can read fonts in our decoder, but we don’t have our own webfont generator, only a converter that supports most TTF and some OTF fonts. As a result, you’ll need to include the font you want as a separate asset. That’s what the “Could not find required font” message is about :wink:

Hey singmajesty!

Long time no talk. :wink:
Actually the problem still persists - trying to instantiate the whole swf by

var test = Assets.getMovieClip ("lib:");

was just a little test to see if it’s able to load the swf at all.
There’s no practical use and if I try to do the same targeting flash, I get a
cannot convert flash.display::AVM1Movie@4c63f31 to flash.display.MovieClip.
which completely makes sense.
I don’t have problems importing assets from an AVM2 movie by the way. It’s really
just AVM1 movies, swf7 in this case. Could you have a look at the sample project
in my initial post?
Or can you recall what you mean by forcing type “swflite” on all targets in this topic:
Link

Thanks for the insight about font handling - I have a problem with it too but will start
a new thread for it. :wink:

Ah, I haven’t tried an AVM1 SWF :blush:

I just made a workaround on the Flash target, try this

Hey singmajesty!

Sorry for this late reply. I’ve been pretty busy and we decided to redo most of our
assets as AVM2Movies meanwhile to be able to move on with the project.
The problem remains though. I don’t want to attach the whole movie to the stage.
It was just a test to see if it’s loaded at all.
It’s still unable to find the assets inside the AVM1Movie (which are marked as export
for actionscript of course).
[openfl.Assets] There is no MovieClip asset with an ID of “lib:texBox”

Do you have an idea what’s going on? =)

Yes! If you target anything except for Flash, we can get the individual symbol names. However, on Flash Player, an AVM1Movie is an opaque type that can only play, you cannot access individual “Export for ActionScript” classes :smile: