Friday, September 7, 2012

How to embed assets in Flash Builder 4.7 Actionscript Projects

In Flash builder 4.7, [Embed] metadata tags are handled differently depending on whether you're working on a Flex-based project, or a pure actionscript one.  One difference has to do with how the path in a source attribute is looked up.

In a Flex project if you create a tag like this:
 [ Embed(source="myAsset.png") ]
the compiler will look for a file called myAsset.png in the root project folder.  This is the behavior Flash Builder users are accustomed to.

But in an actionscript project, the compiler will search for it relative to whatever folder the actionscript file is in. So let's say I have an actionscript class in package com.dougmccluer.controls.customList.as.  And in that class, I embed a graphic like so:
[ Embed(source="myAsset.png") ]
I will need to place my graphic file at [project root]/src/com/dougmccluer/controls/myAsset.png

OR, if I want to place my graphics in a folder called "embeds", I can change my metadata tag to look like this:
 [ Embed(source="../../../embeds/myAsset.png") ]
Absolute paths are also acceptable, for example:
/Users/doug/projects/testProject/embeds/myAsset.png
C:/Users/doug/Documents/projects/testProject/embeds/myAsset.png
but keep in mind absolute paths are not very friendly for collaborative projects.

If you use relative paths, you must update the paths any time you move the actionscript file.

Hopefully, by the time this product leaves beta, the actionscript compiler will be brought back in line with the Flex compiler so that they both interpret Embed paths as relative to the project folder.  

No comments:

Post a Comment