0
votes

I'm trying to run my flex application in the air runtime instead of flash runtime. It seems to work perfectly except the images. Adobe Air runtime tries to load them. Is there a way to change the root adresses for Image to server side? If possible I'd like to use the same code for flash runtime and air runtime .. "single codebase ;-)"

var icon:Image = new Image();
icon.source = "images/test.png";

regards cyrill

1
Did you include the assets when packaging your AIR app? - RIAstar
Nope .. i hoped i could the use the assets deployed on server side. I tried do include them in the project and then it works.. but as soon as i create the exe with the flashbuilder export tool I get a exception... well a not defined exception. I could find any log files according this error. - Cyrill Zadra
there are around 10000 images - Cyrill Zadra
If you use the images on the server, that means they won't show when the application has no internet connection. If the images aren't likely to change, I see no reason why you wouldn't package them. - RIAstar
If your app uses so many images, I guess they're small enough to embed them. They will take long to load even on good connection because of inevitable ping. - alxx

1 Answers

1
votes

Typically I would simply package the assets into the AIR app. That way the relative paths would be valid both in the web app and the desktop app. However, since you pointed out in the comments that we're talking 10000 images you'll have to find another solution.

What you need is a variable that is configurable for each type of project. The final code to access your images should look like:

var icon:Image = new Image();
icon.source = rootUrl + "/images/test.png";

That rootUrl may be "" for the web app, and "http://www.mydomain.com" for the desktop app. Or it could be the absolute path in both cases. It doesn't matter: we don't want to hardcode that URL into our application.

Create a .properties file (or XML, or JSON; whatever configuration file you like) that contains the value for rootUrl and read that into your application model. This configuration file can be packaged into the AIR app.

A .properties file will look like this:

#myapp.properties
rootUrl=http://www.mydomain.com

For reading the file, you could use AIR's file streaming capabilities, but I suggest you load it the old-fashioned way with a URLLoader: this way it'll work both in the web and the desktop app.