Thursday, September 25, 2008

Flash CS4 and Flex Metadata

In previous versions of Flash up to Flash CS3 , Flash did not support many of the Flex Metadata such as :

* Embed
* IconFile
* ResourceBundle
* Style

The most common metadata complained about is Embed metadata. Flash CS4 has added support to many of these metadata which will help developers to write code in Flex and testing it in Flash without worrying about incompatibilities at least in this area. In this post am going to talk about Embed metadata and show some examples.

Users can use embed metadata to embed the following type of assets :
* Image (GIF, JPEG, PNG).
* SVG.
* Sounds.
* SWFs (both AS2 and AS3).
* Symbols extracted from SWFs (not sure if AS2 or AS3 or both supported).
* Fonts from AS2 SWFs only (i think, maybe from AS3 SWFs as well).

Example : in the following example am going to embed GIF using Embed metadata.

1. Launch Flash CS4
2. File > New and select "Actionscript File".
3. Copy and paste the following code

package {
import flash.display.*;
public class GIFEmbed extends Sprite {

[Embed(source="../assets/tala.gif")]
private var theClass:Class;

public function GIFEmbed() {

var displayObj:DisplayObject = new theClass();
addChild(displayObj);

}
}
}

4. Save the AS file and give it a same name as the class name " GIFEmbed.as "

Note : [Embed(source="yourAssets.gif")] this is where you point to the actual assets.Please change the yourAssets.gif with the absolute path or relative path to your assets.
5. Create a Fla file and save it in the same place where the AS file is.
6. Add the GIFEmbed.as file as document class.
7. Test Movie.
8. You will get the following warning message as follow :




9. Click "Update Library path" button to add the path of the Flex.SWC to your library path.

10. Test Movie. Your image should be successfully embedded.

8 comments:

emoveo said...

Is it possible to use RemoteObject and Class Maping same way? I founded nothing in google)

Tareq AlJaber said...

Any Class that is pure AS3 and does not depends on the Flex framework should work just fine. I am working on using Flex RemoteObject component in Flash that will be posted "hopefully" this month.

Benjamin said...

Thanks a lot for this post. After hours of searching about embedded assets and the AS3 compiler, I found your post to be the most helpful.

One important note. If an instance of the GIFEmbed class is created inside a nested movie clip in the .fla, the embedded asset will not display. I do not have an explanation as to why it will not display, but this phenomena is very easy to duplicate through testing.

However, if the nested MovieClip is exported for actionscript, the embedded asset displays correctly.

Can anyone offer an explanation for this behavior?

Tareq AlJaber said...

Thank you, Benjamin!!
Regarding to the problem you're describing, would you please email me a fla file that reproduce the issue or just provide me with steps to reproduce the problem.

Thanks,
Tareq

reyt said...

we provide a power leveling and free wow gold wow power leveling|*|wow power leveling|*|http://www.wotlk-powerleveling.com|*|fdgf51

Dorkbot said...

It appears that all my embedded content is loading before the first frame of my swf. it loads before the stage color loads so all users see is white until my large swf loads. Is there a way to force embedded content to load on a different frame?

thanks!

Anonymous said...

dessicant air dryer pediatric asthma asthma specialist
carpet cleaning dallas tx carpet cleaners dallas carpet cleaning dallas
beach vacations your beach vacations
bob hairstyle
bob haircuts bob layered pob hairstyle
bobbed classic bob Care for Curly Hair
Tips for Curly Hair curly hair 12r 22.5 best price
tires truck bus tires 12r 22.5 washington new house
new house Houston new house san Antonio new house ventura
sealy air beds portable portables air beds
antique doorknobs drying desiccant
air drying desiccantlipitor allergic reactionsApple prodam iphone praha

Anonymous said...

new houston house houston house tx stains removal dye
stains removal clothes stains removal teeth whitening
teeth whiteningbright teeth jennifer grey nose
jennifer nose jobs calebrities nose jobs Women with Big Noses
Women hairstyles Big Nose Women, hairstylesdvd player troubleshootingtroubleshooting with the dvd playercheap beach vacationsnight vision binoculars bargainsflorida headache clinic

Post a Comment