- Flash Development for Android Cookbook
- Joseph Labrecque
- 626字
- 2021-04-02 19:15:17
Converting a standard Flex project to a Flex Mobile project
There is currently no workflow within Flash Builder (or FDT) to convert an existing application to a mobile Android application. Depending upon the complexity of the application being converted and the version of Flex, it may be undergoing conversion from this task can range from the very simple to one that is inordinately complex. In this recipe, we will demonstrate a simpler example using basic Flex structures.
How to do it…
Create a new mobile project and copy all of the necessary files into it, retaining those portions of code which are used for mobile projects and modifying any unsupported components.
For this example, we'll use a simple Flex project targeting AIR for desktop consisting of nothing but a button component at this stage:
<?xml version="1.0" encoding="utf-8"?> <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx"> <s:Button x="10" y="10" width="300" height="200" label="Button"/> </s:WindowedApplication>
To convert this to a new Flex Mobile project, take the following steps:
- Go to the menu and choose File | New | Flex Mobile Project.
- Provide the project setup dialog with information about the new mobile project.
Note
The project cannot have the same name as any existing project within your environment.
- Copy all of your files from the project folder in your original project into this new mobile project excluding your project descriptor file
({myApp }.xml)
andDefault Application
files. - Now, copy everything within your old
Default Application
file and paste it into theDefault Application
file that was created along with your mobile project. Once everything has been copied over, right-click on the main application file and choose Set as Default Application. - Change all instances of
<s:WindowedApplication>
to<s:ViewNavigatorApplication>
(alternatively,<s:TabbedViewNavigatorApplication>
).Note
Just as with a standard AIR
<s:WindowedApplication>
, only one instance of<s:ViewNavigatorApplication>
or<s:TabbedViewNavigatorApplication>
can exist within a project. - Look within your Problems panel to see whether or not any further modifications need to be made.
- If you are not using any of the old Halo components (mx namespace) it is a good idea to remove the namespace declaration for your opening
<s:ViewNavigatorApplication>
tag. - Add a
firstView
attribute to the<s:ViewNavigatorApplication>
tag. This should point to theView
automatically created when you set up the mobile project. - Since visual UI elements cannot reside directly within a <s:ViewNavigatorApplication /> node, we must wrap the <s:Button /> instance within a <fx:Declarations> </fx:Declarations> tag set, or move it to a specific View.
Tip
Downloading the example code
You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.
Your Default Application
file should now read as follows:
<?xml version="1.0" encoding="utf-8"?> <s:ViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" firstView="views.MobileFlexProjectHomeView"> <fx:Declarations> <s:Button x="10" y="10" width="447" height="106" label="Button"/> </fx:Declarations> </s:ViewNavigatorApplication>
Additionally, a view for this application could appear as such:
<?xml version="1.0" encoding="utf-8"?> <s:View xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" title="MobileFlexProjectHomeView "> </s:View>
For more information about how Flex Mobile projects are structured, have a look at the following resource: http://opensource.adobe.com/wiki/display/flexsdk/Developer+Documentation.
How it works…
When using Flex, the root tag of your application determines largely what APIs and structures are available to you throughout the project. Making sure that we choose the correct root tag is very important in regard to the target platform and capabilities of our project. For AIR on Android, we will want to use either ViewNavigatorApplication
or TabbedViewNavigatorApplication
. Desktop applications would use the Application or WindowedApplication
tags. Chances are, if you are building Flash content with Flex that is to be deployed to Flash Player in the browser, on both mobile and desktop you will use a straight Application
tag for your project.
There's more…
If you don't want to deal with a lot of conversion, and are just starting out with a new project that will share the same codebase across desktop and mobile, you might consider using a Flex Library project to allow different projects to share the same underlying codebase.
Read the documentation on Flex 4 Library usage at: http://help.adobe.com/en_US/flashbuilder/using/WS6f97d7caa66ef6eb1e63e3d11b6c4d0d21-7fe6.html.
- JasperReports for Java Developers
- 從零開始:AutoCAD 2015中文版機械制圖基礎培訓教程
- AI繪畫教程:Midjourney關鍵詞靈感手冊
- SolidWorks 2021中文版機械設計從入門到精通
- BPEL Cookbook: Best Practices for SOA/based integration and composite applications development
- 中文版CorelDRAW X8基礎培訓教程(全彩版)
- Mastering phpMyAdmin 3.3.x for Effective MySQL Management
- AI繪畫:Stable Diffusion從入門到精通
- ABAQUS有限元分析從入門到精通(第3版)
- Instant Testing with QUnit
- AutoCAD 2022中文版建筑設計從入門到精通
- 高等院校電腦美術教材:CorelDRAW X7中文版基礎教程
- AutoCAD 2022中文版從入門到精通(標準版)
- 中文版3ds Max 2016/VRay效果圖制作技術大全
- 修片有道:PHOTOSHOP攝影后期專業技法