Cyrill Zadra
Cyrill Zadra

Reputation: 172

Flex Image Source Server Side Flash and Air

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

Upvotes: 0

Views: 148

Answers (1)

RIAstar
RIAstar

Reputation: 11912

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.

Upvotes: 1

Related Questions