5
votes

I'm trying to add assets into a flex library .swc file with no success.

The assets folder in the library project contains a gif file. The project also contains a Spark Group componnent that displays the image.

When i try to use this componnent in a different project the image is not visible. If i copy the assets folder from the library project to the main project the image is visible.

I added the assets folder in the Flex Library Build Path

Why aren't the assets contained by the swc?

Thank you!

Attached screenshots: enter image description hereenter image description here

2
I suspect that the image is included in the SWC; but is not included in the SWF that uses the SWC. A SWC is a zip file so you can unzip it to see if your image is in there. If you aren't embedding the asset; I suspect the Flex compiler won't put it in your resulting SWF. - JeffryHouser
Did you found answer? Alternative would be to add assets source folder as one of project sources, so you can pick files in 'Package Contents', right? - Nemi

2 Answers

2
votes

Create class in library project

package resources
{
    public final class IconResource
    {
        //list embedded items - you can embed any files, mp3 etc

        [Embed (source="../assets/facebook.gif" )]
        public static const icon_facebook:Class;    

        public function IconResource()
        {}
    }
}

Using in production projects:

import resources.IconResource;

var img:Image = new Image();
img.source = IconResource.icon_facebook;

or

<fx:Script>
  <![CDATA[
    import resources.IconResource;
  ]]>
</fx:Script>

<s:Image source="{IconResource.icon_facebook}"/>
0
votes

It depends on how you're trying to access the image from the library.

For it to work, you need to use @Embed("facebook.gif") in your case - no "assets" folder used in path. So, you won't be able to access it from your application unless you embed it, and you only use the name of the file for embedding.