views:

82

answers:

5

Im doing an app that runs both in the web and on AIR, to avoid copying code arround, I figured I should do 3 kinds of proyects on flex builder: Library, Web and AIR proyects.

So all my code is on the Library proyect.

I have accessData.as that extends EventDispatcher to fetch web services and return them as an event, I plan on using this class to also fetch SQLite data for the desktop version, but to do so I need it to decide from wich source to get the data depending on if its Web or AIR.

anyone know how to do this?

A: 

umm... I just found out a way

var appName:String = Application.application.name;

this works since the web version is called "" and the desktop version is called " desktop"

but if anyone has a better way please go ahead.

thanks.

sergiogx
+1  A: 

You may find something useful under System or Capabilities in the docs.

Jasconius
+3  A: 

You really should have two build targets, one for Web and one for AIR. And your code should be designed in a way that the rest of the system doesnt care what the implementing part is doing, only that it conforms to a certain interface. This way, each build simply replaces the implementing code for each desired platform.

geowa4
mmm, how is that diferent from what im doing? could you give an example? I just finished doing the architecture, im just in time to do changes, thanks :).
sergiogx
you are trying to figure out what you are running on at...well...runtime. I'm saying that you make two different distributions, one for AIR and one for Web. So when you build you swf for Web, you don't include the code for AIR.
geowa4
+4  A: 

Please refer to this link http://stackoverflow.com/questions/461923/detect-air-versus-flash-player-from-an-actionscript-library Its more detailed.

arunpon
+1  A: 

Create 2 projects Air and Standalone and create 2 conditional compilation variables for example "standalone" and "air". (more here).

Go to Project->Properties->Flex Compiler and add

For air project:

-define=CONFIG::standalone,false -define=CONFIG::air,true

and for stanalone:

-define=CONFIG::debugging,true -define=CONFIG::air,false

In your code set:

CONFIG::standalone { 
    trace("this code will be compiled only when air=false and standalone=true");
}


CONFIG::air { 
    trace("this code will be compiled only when air=true and standalone=false");
}
zdmytriv