Skip to main content
December 20, 2010
Question

AIR for Android, app won't load images (.png)

  • December 20, 2010
  • 2 replies
  • 3159 views

Hello,

I am having trouble loaded images into my air app.  The folder containing the images (.png) is included in the "Included Files" section in the AIR for Android publish settings.  Once the app is installed on the device (i am using a Droid X with Android 2.2), where are would these files be located?  Is there some way to specify where exactly they will go?  I have tried the 2 options below for loading the images and both fail (they both work when testing the movie on my dev machine).

1.  imageFile.exists returns false:

     var imageFile:File = File.applicationDirectory.resolvePath("Images/test.png");
     if (imageFile.exists) {
          imageLoader = new Loader();
           imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onTestImageLoaded, false, 0, true);
           imageLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler, false, 0, true);
           imageLoader.load(new URLRequest(imageFile.url));
     }    

2.  Event.COMPLETE never fires in this scenario:

     imageLoader = new Loader();
     imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onTestImageLoaded, false, 0, true);
     imageLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
     imageLoader.load(new URLRequest("Images/test.png"));

I'm guessing the path to my image is incorrect as far as Android is concerned in my URLRequest param...

Any help would be greatly appreciated!

This topic has been closed for replies.

2 replies

liyo
Participant
October 21, 2014

Hi,

you should write the code like this,

imageLoader.load(new URLRequest("file://" + imageFile.url)); (AIR FOR ANDROID), do add the string "file://" first.


the file's path that really should be  u should take care,

Adobe Flash Platform * Displaying HTML content in mobile appshere,you can find something to konw more.

Participant
December 21, 2010

I solved this by embedding my images, like so:

[Embed(source="views/touchstick_n.png")]
private var touchstickNImage:Class;

internal function doTouchpadOut():void {
    select_touchstick.source=touchstickNImage;
}

Where touchstick_n.png was placed in the views folder alongside my views, and

select_touchstick was a control (with id="select_touchstick") that used an image.

I suspect a spark.components.Image (or <s:Image>), or anything of that nature,

will work the same way.

Of course, this is only good for images that you have at compile time, but that

seems to be what you're going for here.  imageLoader is better used for images

that are loaded during run time, such as images from the Web.

December 23, 2010

Thanks for your reply, A_Tymes,

But I am actually attempting to load these images at run-time.  Based on user-input, any one of hundreds of image files could be loaded (the name of the image file is passed in to where I have test.png).  I think the problem lies in how I specify the path to the image file, but I can't seem to find a solution.  All of the images are included in the .apk package that Flash builds.

Participant
December 23, 2010

If you're including them in the .apk anyway, then one brute force solution - which probably

won't increase the size of your .apk much (since, again, the images are there anyway) -

is to simply make one identifier for each image, then pass this identifier in.  For example,

you could have:

[Embed(source="views/type1/a.png")]
private var type1AImage:Class;

[Embed(source="views/type1/b.png")]
private var type1BImage:Class;

...

[Embed(source="views/type2/a.png")]
private var type2AImage:Class;

...

private var images:Array;

...

images[0] = type1AImage;

images[1] = type1BImage;

...


image_element.source = images[id_of_image_chosen];

Yes, it would be a large array.  As I said, brute force (though you might

want to consider a script to generate the source code, if you know a

scripting language well enough to make this less than 15 minutes' work).

But it would get the job done.