PDA

View Full Version : Embedding assets from .swf vs .swc


abeall
10-27-2009, 02:47 PM
Right now I've created a Flash skin and exported as skin.swc. The .swc is included in the build and I skin various components using the skinClass method:
skin: Embed(skinClass="Button_skin");

I'm also including an asset for the background image, and following tutorials I came up with this working code:

backgroundImage: Embed(source="skin.swf",symbol="BackgroundImage");

That .swf is the same as the .swc, ie they are both rendered from Flash at the same time.

I'd like to reference that BackgroundImage in the .swc rather than the .swf so that I don't have to depend on both. However my various attempts have thrown errors or simply not worked:

backgroundImage: Embed(source="skin.swc",symbol="BackgroundImage");

backgroundImage: ClassReference("BackgroundImage");


What am I doing wrong?

wvxvw
10-27-2009, 05:32 PM
Symbol and Class are 2 different things. Symbol is the resource, and Class is the ABC code. But, I don't think you'll get it to work with ClassReference, because it wants a Class, not a symbol as an input. Generally, you cannot manipulate symbols from AS code... So, I don't think it will be at all possible, unless you're going to patch the compiler to make it look for both Symbols and Classes once you use ClassReference...

abeall
10-27-2009, 06:44 PM
Well, the symbol is set to export as a class. The class name is BackgroundImage (same as the symbol name.)

So is there a way I can reference that in a .swc? Why won't the embed() work with a .swc?

wvxvw
10-27-2009, 07:47 PM
Again... Symbol is the resource, class is the ABC code... those are 2 different things. If you import class (which may be linked to the symbol), then the linked symbol will be imported along with that class, but if you only import the symbol (i.e. graphics), then there's no class (no ABC, no script) attached to it, it's the same as if you ware importing a picture or a sound.
Now, ClassFactory needs a class (the class may or may not be linked to the symbol), but it doesn't expect to have an image or sound, or video or just a chunk of binary data instead... This is how compiler works, if you need to change that - you'll need to patch the compiler, really no other way...

abeall
10-27-2009, 10:26 PM
Ok. I'm just trying to figure out if I can get that symbol+class resource from the .swc to be used as the app background. ClassReference was a random guess, but embed() did not work either. Why?

wvxvw
10-28-2009, 01:24 AM
OK, so you could better understand the concept.

32755

Left to right in the picture:
1. Complete self-contained SWF. It has a bunch of classes and only one symbol (resource). This symbol is used by the document class (the document class is linked to this symbol). There are no other symbols in that SWF (pretty small SWF with almost no graphics / sounds etc).
2. The repository of classes, this is a part of SWF, it cannot be used on it's own, only as a reference. (You can use it only as class repository when compiling, or as RSL).
3. The repository of classes and symbols (compiled from Flash CS#). Flash makes linking simple (almost invisible for you), you never know and have no influence on what would be the symbol name, the symbol name will be generated following the class name. This is probably what confuses you. This isn't mandatory for SWF format to have classes and symbols with the same name, this is just the way Flash compiler works. However, it is definitely possible for several classes to share the same symbol and for symbols to have absolutely unique names.

So, what happens when you use [Embed()] or @Embed():
The linker of the Flex compiler extracts the symbol and either create a new class that subclasses an *Asset (* = Bitmap | Sound | MovieClip), or links this symbol to the class you specified (this happens if you put [Embed] meta before the class declaration).
[Embed(source="some.swf", symbol="SomeSymbol")]
public class MySprite extends Sprite {
...
If you have a class that Flash has linked to this symbol, the linker will drop it.

However, if you use ClassReference(MyClass) the linker links the class into SWF. Occasionally the class it links may have a symbol reference, in which case both the class and the referenced symbol will be linked into resulting SWF. But it is not necessary for the class to link to any symbol at all...

PS. There's one case when you cannot assign a symbol to the class - if this class is a frame factory class (your document class or any other class that is used for frame generation). These classes will receive new symbols when they are compiled and if you tried to assign a symbol to them, it will be discarded.

abeall
10-28-2009, 02:17 AM
Honestly, I'm not sure what you are trying to explain, sorry. I understand that my .swc has both classes and symbols linked to each other in them, I'm just trying to embed a symbol (don't need the class) from the .swc for use in the background image. It works fine if I use .swf, but when I try .swc it tells me it doesn't recognize the .swc extension, which is what's confusing.

Does embed not work with .swc files? Been googling that past few minutes and all examples of embed use .swf files...

Peter Cowling
10-28-2009, 10:45 AM
The .swc will be compiled into the application, and be made avaiable to reference as a class. Import the class, and use it as a reference for your image.

Looked at another way, you do not need to embed the image, because its not in a seperate .swf, you just need to create the link...

EDIT:
Ah, should have read back re. symbol...

wvxvw
10-28-2009, 11:11 AM
I'm just trying to embed a symbol (don't need the class) from the .swc
Extract the SWC with the ZIP, grab the library.swf file that you will have there, use it as a target for embed. The linker at the moment cannot link in symbols from the SWC.

abeall
10-28-2009, 03:09 PM
grab the library.swf file that you will have there, use it as a target for embed.

Ah, I think that's what I missed from your previous explanation. I thought a .swc was just a compressed .swf itself and I figured Flex Builder could manipulate it like a .swf.

The linker at the moment cannot link in symbols from the SWC.
Well, I guess I can just continue to have Flash publish both .swf and .swc and use .swf for embed() and the .swc for skin classes. I was just hoping I could consolidate and just use the .swc since it does contain everything I need.