Flex Mobile开发入门
- <?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"
- applicationComplete="appCompleteHandler(event)" applicationDPI="240"
- firstView="views.HomeView"
- splashScreenImage="@Embed('assets/android_icon.jpg')"
- splashScreenMinimumDisplayTime="3000" splashScreenScaleMode="letterbox">
- <fx:Script>
- <![CDATA[
- import mx.events.FlexEvent;
- import mx.formatters.DateFormatter;
- /** 日期格式化对象 */
- protected var df:DateFormatter;
- /** 返回事件监听者 */
- private var onBackListener:OnBackListener;
- /** 应用初始化处理 */
- protected function appCompleteHandler(event:FlexEvent):void
- {
- // 初始化日期格式化对象
- df = new DateFormatter();
- df.formatString = "HH:NN:SS";
- // 注册键盘事件
- stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyboardHanlder);
- }
- /** 键盘键点击 */
- private function onKeyboardHanlder(event:KeyboardEvent):void
- {
- if(event.keyCode == Keyboard.BACK) { // BACK键
- backHandler();
- }
- }
- /** Home键点击处理 */
- protected function homeBtn_clickHandler(event:MouseEvent):void
- {
- navigator.popToFirstView();
- }
- /** Back按钮点击 */
- protected function backBtn_clickHandler(event:MouseEvent):void
- {
- backHandler();
- }
- /** 返回处理 */
- private function backHandler():void
- {
- if (navigator.length > 1) {
- if (onBackListener != null) {
- onBackListener.onBackHandler();
- }
- navigator.popView();
- } else {
- NativeApplication.nativeApplication.exit();
- }
- }
- /** 格式化时间 */
- public function formatTime():String
- {
- return df.format(new Date());
- }
- /** 设置返回事件监听者 */
- public function setOnBackListener(onBackListener:OnBackListener):void
- {
- this.onBackListener = onBackListener;
- }
- ]]>
- </fx:Script>
- <fx:Declarations>
- <!-- Place non-visual elements (e.g., services, value objects) here -->
- </fx:Declarations>
- <s:navigationContent>
- <s:Button id="homeBtn" label="Home" click="homeBtn_clickHandler(event)"/>
- </s:navigationContent>
- <s:actionContent>
- <s:Button id="backBtn" label="Back" click="backBtn_clickHandler(event)"/>
- </s:actionContent>
- </s:ViewNavigatorApplication>
附件:http://down.51cto.com/data/2360817
本文转自winorlose2000 51CTO博客,原文链接:http://blog.51cto.com/vaero/900856,如需转载请自行联系原作者

