构建第一个Flex的Mobile APP
生活随笔
收集整理的這篇文章主要介紹了
构建第一个Flex的Mobile APP
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Flash Builder 4.5已經支持直接創建Flex Mobile Project,寫一個最簡單的例子
1、建立工程
右擊--》新建--》輸入工程名“MyFirstMobileApp”
?
點擊“Next”進入下一步
修改初始化的標題文本信息為“Home”(默認為HomeView),勾選“Google Android”、“Automatically reorient”(默認這些已經都勾選了),然后點擊“Finish”
?
系統將自動生成一個views包,如下圖所示:
2、編寫代碼
雙擊“MyFirstMobileAppHomeView.mxml”,拖拽一個VGroup組件,然后刪除x、y屬性,修改width、height均為100%,添加horizontalAlign=”center” verticalAlign=”middle”,讓其內容水平、垂直居中
在里面放置一個Label和一個Button,然后再給Button添加一個事件,完整的代碼:
<?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="HomeView">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
private function button1_clickHandler(evt:MouseEvent):void {
navigator.pushView(MyNewView);
}
]]>
</fx:Script>
<s:VGroup width="100%" height="100%" horizontalAlign="center" verticalAlign="middle">
<s:Label text="Hello,World!"/>
<s:Button label="Continue" click="button1_clickHandler(event)" />
</s:VGroup>
</s:View>
事件中navigator.pushView的參數MyNewView為接下來準備創建的Component(組件) 在views包中添加一個組件,命名為“MyNewView”
同MyFirstMobileAppHomeView.mxml一樣,在MyNewView.mxml也同樣放置一個Label和一個Button組件,然后給它的Button添加一個事件,點擊后讓它回到Home(主頁),完整的代碼: <?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="SecondScreen">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
protected function button1_clickHandler(event:MouseEvent):void
{
navigator.popView();
}
]]>
</fx:Script>
<s:VGroup width="100%" height="100%" horizontalAlign="center" verticalAlign="middle">
<s:Label text="Success!"/>
<s:Button label="Back" click="button1_clickHandler(event)"/>
</s:VGroup>
</s:View>
現在工程的目錄結構: 右擊工程,選擇Debug AS –> Mobile Application
在彈出的面板中,選中“Launch method”的第一項“On deskop”,然后在下拉框中選擇“HTC Desire” 應用并調試(Debug),這里因為沒有應用任何的樣式所以外觀看上去有些粗糙 :( 應用樣式后,看上去就不一樣了,看上去很Nice..
轉載于:https://www.cnblogs.com/meteoric_cry/archive/2011/07/06/2099612.html
總結
以上是生活随笔為你收集整理的构建第一个Flex的Mobile APP的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 梦到失火又被自己浇灭了啥意思
- 下一篇: cmb