转载:http://bbs.9ria.com/thread-96498-1-1.html
我们都知道在在Flex开发Mobile app的时候,Alert组件已经没有了.实现弹出对话框也没有了.对话框的实现只有靠我们自己了:
我们可以自己新建一个Alert组件,叫:MobileAlert,继承自SkinnablePopUpContainer 类,代码如下:
- <?xml version="1.0" encoding="utf-8"?>
- <s:SkinnablePopUpContainer xmlns:fx="http://ns.adobe.com/mxml/2009"
- xmlns:s="library://ns.adobe.com/flex/spark" width="400" backgroundColor="0x999999">
- <s:layout>
- <s:VerticalLayout gap="20" paddingBottom="10" paddingLeft="30" paddingRight="30" paddingTop="30" horizontalAlign="center"/>
- </s:layout>
- <fx:Declarations>
- <!-- Place non-visual elements (e.g., services, value objects) here -->
- </fx:Declarations>
- <fx:Script>
- <![CDATA[
- [Bindable]
- public var message:String;
- private function clickHandler(commit:Boolean):void {
- super.close(commit);
- }
-
- ]]>
- </fx:Script>
- <s:Label text="{message}" width="100%" textAlign="center"/>
- <s:HGroup width="100%">
- <s:Button label="Yes" width="50%" click="clickHandler(true)"/>
- <s:Button label="No" width="50%" click="clickHandler(false)"/>
- </s:HGroup>
- </s:SkinnablePopUpContainer>
- <?xml version="1.0" encoding="utf-8"?>
- <s:TabbedViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
- xmlns:s="library://ns.adobe.com/flex/spark">
-
- <fx:Script>
- <![CDATA[
- import com.coolexp.view.MobileAlert;
-
- import spark.events.PopUpEvent;
- private var a:MobileAlert;
- protected function button1_clickHandler(event:MouseEvent):void
- {
- // TODO Auto-generated method stub
- a = new MobileAlert();
- a.message = "Exit App?";
- a.addEventListener(PopUpEvent.CLOSE, onAlertClose, false, 0, true);
- a.width = this.stage.width - 40;
- a.x = 20;
- a.open(this, true);
- a.y = (this.stage.height - a.height) / 2;
- }
- private function onAlertClose(e:PopUpEvent):void {
- trace(e.commit);
- a = null;
-
- }
- ]]>
- </fx:Script>
-
- <fx:Declarations>
- <!-- Place non-visual elements (e.g., services, value objects) here -->
- </fx:Declarations>
- <s:ViewNavigator label="Tab1" width="100%" height="100%" title="Tab1" >
- <s:navigationContent>
- <s:Button label="back" skinClass="spark.skins.mobile.BeveledBackButtonSkin" click="button1_clickHandler(event)">
- </s:Button>
- </s:navigationContent>
- </s:ViewNavigator>
-
- <s:ViewNavigator label="Tab2" width="100%" height="100%" title="Tab2">
-
- </s:ViewNavigator>
- </s:TabbedViewNavigatorApplication>