views:

832

answers:

3

As I am building a Flex framework for minigames, I plan to bundle a bunch of graphic assets (movieclip symbols) into a single swf file, which I will load into my Flex application, before extracting the symbols from the swf file for use in my application. My question is this: how do I do this through actionscript?

Thanks!

A: 

I'd try to create an asset/icon library AS file.

something along the lines of

package 
{

public class IconLibrary
{

 /*
 *  Framework Icons
 */

 [Embed (source="../assets/fof_graphics.swf", symbol="clapperboard_icon")]
 public static const clapperBoardIcon:Class;
 [Embed (source="../assets/fof_graphics.swf", symbol="clapperboard_over_icon")]
 public static const clapperBoardOverIcon:Class;
 [Embed (source="../assets/fof_graphics.swf", symbol="close_button")]
 public static const closeButton:Class;
 [Embed (source="../assets/fof_graphics.swf", symbol="close_over")]
 public static const closeOverButton:Class;

    public function IconLibrary()
 {
 }

  }

}

Then all you need to do is

source="{IconLibrary.clapperBoardIcon}"

or whatever the name of the asset you wish to show.

kenneth
+1  A: 

If you don't want to use EMBED and you don't want to load the assets on runtime I reccomend you exporting the swf as an SWC.

This way, you can browse SWC files from actionscript. You can event check on compile time that a sub-movieclip inside anotehr movieclip exists.

If you are using flex compiler then remember adding this when you compile:

-library-path C:\path\to\your\file.swc

If you're using FDT you have an option to auto add the SWC as arguments.

Here's a demo on how to do it with FDT. Not sure which tool are you using. If it's the commercial Flex Builder the process should be similar.

I think that's what you're looking for.

ozke
+1 for recommending the SWC approach -- I actually hadn't thought of that one. Not having to the ship the extra SWF could be an advantage in some cases, although for Web-based apps it could also result in a much bigger SWF. Nonetheless depending on the circumstances it's nice to be reminded it's an option.
Christian Nunciato
Thanks. Is A solution, not THE solution. Is very useful for those cases in which the assets don't change often and file size is not essential "E.g. interactive app".I strongly reccomend use runtime assets at the same time you use SWC for those files that might need to be changed. We don't want to re/compile everything just to change an image, right? :)
ozke
You can also compile against a RSL (runtime shared library, basicly a swc loaded at runtime), that way you can still updated the swc later and write it strong typed.
Lillemanden
A: 

Hi,

Lot's of good solutions here, here's one for if you are loading the swf at runtime and want to extract assets, you can do the following in your loader complete event listener:

var c:Class = Class(LoaderInfo(e.target).applicationDomain.getDefinition("myClassDefinitionName"));

This will store the asset from the swf as a Class object so you can create instances of it like so:

var asset:MovieClip = new c();
Tyler Egeto