开发者

In Flex, is it posible to identify if the code is runing on Web or AIR?

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

So all 开发者_如何学编程my code is on the Library project.

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?


Please refer to this link Detect AIR versus Flash Player from an actionscript library Its more detailed.


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.


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


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");
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜