Can I generate a Flex web and Air desktop app from the same source code?

家住魔仙堡 提交于 2019-12-10 13:06:43

问题


I'm new to Air. I've got an existing Flex 2 application which I'm considering bringing into Flexbuilder 3. My question is can I use the same base application (and source code) to make the Air version, or would I have to maintain to separate code trees: one for the Air version and one for the Flex/SWF version?


回答1:


The best approach I've found to creating both Flex and AIR applications from the same source, is to use a core library project for almost all code, with separate small projects for the Flex and AIR applications.

There are two key concepts that make this very powerful and maintainable, allowing for not just two applications, but for many "editions" if you're so inclined.

  1. Modules:- If the core application is actually a module (or a module that loads other modules) you'll be able to easily create stub Flex and AIR applications that are basically there to set project properties, reference classes for cross-module communication, and then simply load the core application module with a ModuleLoader.

  2. Factory Objects:- When there are things you want to do on the AIR desktop application that you can't do in the Flex application, or any case where you want something to work differently across applications, a factory object that creates an instance of a project specific class is a great way to do it. for example, you can call your "save" function, which for AIR saves to the file system, but for Flex calls a web service.

    Have a look at Todd Prekaski's excellent Flex DevNet article on Building Flex and Adobe AIR applications from the same code base on how to do this.

Once you've created a Flex Library project where you're going to create your main module, create your Flex and AIR application projects. In the properties of the two application projects add the library project src directory to the Flex Build Path. While in the project settings you'll also need to add the modules to the Flex Modules section, setting the option to optimise for the project.




回答2:


You can't mix both AIR and Flex in the same Flex Builder project, but you can share code. Here's how...

  1. Create a Flex based project as you normally would.
  2. Create a second AIR based project.
  3. In the second application, go to project->properties.
  4. Select the "Flex build path" option.
  5. Under "Source Path" add the folder that contains the source from your first Flex based project.

Now both projects share the code from the flex project.

You need to be careful not to use AIR only API's in code you intend to share between both apps.




回答3:


You can use the same.




回答4:


One way is to put the bulk of the application in a Group-based component in a library.

Both Flex and AIR applications can embed that component in their Window.

If you need to have custom code, have your Group component accept an Interface object that has all the methods that are specific to a platform (loadFile, saveFile, etc.). Each application injects an object that implements these methods appropriately.

I've worked on a product that injected a whole local-data access layer (to the SQLite database) and the core application had no idea if it was running in a browser or on the desktop (connected or disconnected).

Cheers




回答5:


Create 3 project: Air, Web, and common. from air and web, include common.

http://simplifiedchaos.com/how-to-compile-both-flex-and-air-application



来源:https://stackoverflow.com/questions/93359/can-i-generate-a-flex-web-and-air-desktop-app-from-the-same-source-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!