• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

How to reference a file inside a flex library project?

New Here ,
Dec 16, 2010 Dec 16, 2010

Copy link to clipboard

Copied

Hello,

I'm desperately trying to solve a "little" problem. I have a flex  library project and would like to add an image to  "project_root/files/myimage.png". Now I would like to retrieve the url  to this file. I need this as a string in order to pass it on. I have  tried to return something like "app://files/myimage.png" (with 2 or 3  slashes after app:), but the file could not be found.
Then I used the Embed annotation and therefore copied the file into a  package under the source folder.

...
[Embed(source="/mypackage/myimage.png")]
private var myImageStr:String;
[Embed(source="/mypackage/myimage.png")]
private var myImageClass:Class;
...
var myImg:Bitmap = new MyImageClass();
...

If I now print myImageStr it shows "NameOfCurrentClass_NameOfVariable"  (i.e. DemoClass_myImageStr). myImg is an empty object of type  "DemoClass_NameOfVariable". It has no height and width and no data in it.

Does anyone know how to get the url of an internal (inside a project)  file? Is this even possible?

Regards.

Views

686

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Dec 17, 2010 Dec 17, 2010

Copy link to clipboard

Copied

Hi,

Unless you embed the asset, I don't think you can refer to the image in a library project with a URL.

Try moving the image to the project from which you are building the AIR file (I'm assuming you are using AIR because of the app:// reference) and make sure it is checked in the third step of export release build. Then your app:// reference should work.

Also, if  you choose to embed it rather than move it, a binary representation of the image becomes part of the SWF. So the reference to the image is only via that class object. In your library project, define an ActionScript class which has a public variable (your myImageClass). You can refer to this public variable from your referenced project. Also, try using:

var myImg:BitmapAsset = new MyImageClass() as BitmapAsset;

instead of the equivalent line in your sample.

(See http://livedocs.adobe.com/flex/3/html/help.html?content=embed_4.html for a full sample)

Thanks,

Anirudh

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 17, 2010 Dec 17, 2010

Copy link to clipboard

Copied

Hi Anirudh.


Your embed example works, but there I have a BitmapAsset. How can I get the url to this image? Is that possible?

If not, then I only need an external file for the desktop version of my application, because your idea with moving the file to the application project worked. If I move them into the "main" project, I can reference them using app:///files/myimage.png.

Thanks a lot.

Regards.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Dec 17, 2010 Dec 17, 2010

Copy link to clipboard

Copied

If the asset is embedded, then there's no URL for that image. The variable under the Embed directive is your only reference to the image.

What do you want to do with that image? If the requirement is to display it, you can set the variable you create as a source to mx:Image. If you want to manipulate it, you can access the BitmapData from the BitmapAsset and then use mx:Image to show it.

Thanks,

Anirudh

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 17, 2010 Dec 17, 2010

Copy link to clipboard

Copied

LATEST

Hi,

I actually need the url to this image in order to pass it on. Since the code I pass it to is not my own, I can't change the return value to "image".

If it is not possible to get the url of an embedded image, I just have to stick to the app:// url for the mobile version and an external file for the desktop version.

Thanks again.

Regards.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines