Chinaunix首页 | 论坛 | 博客
  • 博客访问: 488297
  • 博文数量: 111
  • 博客积分: 3146
  • 博客等级: 中校
  • 技术积分: 939
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-07 11:23
个人简介

Nathing

文章分类

全部博文(111)

文章存档

2016年(2)

2015年(1)

2014年(31)

2012年(2)

2011年(9)

2010年(36)

2009年(30)

我的朋友

分类:

2011-07-27 23:21:54

使用组件对象打开弹出式窗口的最大好处是可以重用组件并保持所以的状态值.
对于不是组件对象生成的窗口,每当窗口打开时,弹出式窗口都会重新创建并初始化.
数据的交互:
① 给弹出窗口传递数据
   通过调用弹出窗口的公有属性或方法
② 从弹出窗口中取得数据
   监听弹出窗口派发的事件,在接收到事件后,即可访问弹出窗口的公共属性及公共函数.
 
主应用代码:src/Interactive.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="" layout="absolute">
    <mx:Script>
        <![CDATA[
            import mx.core.IFlexDisplayObject;
            import mx.managers.PopUpManager;
            import mx.controls.Alert;
            import windows.FirstWindow;
            public var firstWindow:FirstWindow = new FirstWindow();
            //使用组件对象打开弹出式窗口的最大好处是可以重用组件并保持所以的状态值.
            private function init():void
            {
                firstWindow.addEventListener("pop",getWindowData);
                PopUpManager.addPopUp(firstWindow, this, false);
                PopUpManager.centerPopUp(firstWindow);
                firstWindow.setData(new Array("bobo", "huhu", "coco"));
                
            }
            private function getWindowData(e:Event):void
            {
                Alert.show(firstWindow.logs);
                Alert.show(firstWindow.labelPosition.selectedItem.toString());
                Alert.show("color:" + firstWindow.labelColor.selectedColor);
            }
            //不是通过组建对象生成窗口:每当窗口打开时,弹出式窗口都会重新创建并初始化.
            private var openner:Object;
            private function init2():void
            {
                openner = PopUpManager.createPopUp(this, FirstWindow, false);
                PopUpManager.centerPopUp(openner as IFlexDisplayObject);
                openner.setData(new Array("bobo", "huhu", "coco"));
                
                openner.addEventListener("pop",getWindowData2);
            }
            private function getWindowData2(e:Event):void
            {
                Alert.show(openner.logs);
                Alert.show(openner.labelPosition.selectedItem.toString());
                Alert.show("color:" + openner.labelColor.selectedColor);
            }
        ]]>
    </mx:Script>
    
    <mx:Button label="openWindow" click="init2()">
        
    </mx:Button>
</mx:Application>

 
弹出组件代码:src/windows/FirstWindow.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow
    xmlns:mx=""
    layout="absolute" width="400" height="300"
    close="close()" showCloseButton="true">
    <mx:Script>
        <![CDATA[
            import mx.managers.PopUpManager;
            [Bindable]
            public var myPopUpvar:Array = new Array();
            public var logs:String = "";
            private function close():void
            {
                PopUpManager.removePopUp(this);    
            }
            private function sendMessage():void
            {
                var outgoingEvent:Event = new Event("pop", false);
                logs = labelPosition.selectedItem.toString();
                dispatchEvent(outgoingEvent);
                close();
            }
            public function setData(str:Array):void
            {
                myPopUpvar = str;
            }
        ]]>
    </mx:Script>
    
    <mx:Form cornerRadius="5" indicatorGap="5" paddingBottom="5"
        paddingLeft="5" paddingRight="5" paddingTop="5" id="basicPropertyPane" width="100%" >
        <mx:Label text="Label Properties" fontStyle="italic" width="100%" fontWeight="bold"/>
        <mx:FormItem label="Name:">
            <mx:TextInput width="90%" id="labelName"/>
        </mx:FormItem>
        <mx:FormItem label="Color:">
            <mx:ColorPicker id="labelColor"/>
        </mx:FormItem>
        <mx:FormItem id="locationForm" label="Location(X,Y):">
            <mx:NumericStepper minimum="0" maximum="1000" id="locationX" />
            <mx:NumericStepper minimum="0" maximum="1000" id="locationY"/>
        </mx:FormItem>
        <mx:FormItem label="Position:">
            <mx:ComboBox id="labelPosition" dataProvider="{myPopUpvar}" />
        </mx:FormItem>
        <mx:FormItem label="Offset(X,Y):">
            <mx:NumericStepper minimum="-200" maximum="200" id="labelOffsetX" />
            <mx:NumericStepper minimum="-200" maximum="200" id="labelOffsetY"/>
        </mx:FormItem>
        <mx:Button label="send" right="10" bottom="10" click="sendMessage()"/>
    </mx:Form>
</mx:TitleWindow>


阅读(5577) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~