gridメインウィンドウとサブウィンドウの情報がインタラクションされます。

9672 ワード

一昨日GRIDをダブルクリックしてサブウィンドウをイジェクトしたと書いていましたが、インタラクティブな情報の内容です。

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  xmlns:title="*"    layout="absolute" creationComplete="init()">
		<mx:Script>
			<![CDATA[
				import mx.core.UIComponent;
				import mx.controls.Alert;
				import flash.events.MouseEvent;
				import mx.events.CloseEvent;
				import mx.events.ListEvent;
				import mx.collections.ArrayCollection;
				import mx.managers.PopUpManager;
				
				private var menuData:ArrayCollection= new ArrayCollection();
				private var canvas:Sprite = new Sprite();
				private var uiComponent:UIComponent;
				
				
				/**
				 *       。 
				 **/
				
				private function init():void{
					menuData=new ArrayCollection([
						{no:"101",name:"    ",address:"21",type:"branch"},
						{no:"102",name:"    ",address:"22",type:"leaf"},
						{no:"103",name:"  ",address:"23",type:"branch"}
					]);	
					
					//             
					var g:Graphics = canvas.graphics;
					g.beginFill(0x000000,0.3);
					g.drawRect(0,0,this.width,this.height);
					g.endFill();
					menuDataGrid.addEventListener(ListEvent.ITEM_DOUBLE_CLICK, doubleClick);  
					this.menuDataGrid.dataProvider=menuData;
				}
				
				
				/**
				 *     ,         ,            .
				 **/
				private function doDel():void{		
					if(menuDataGrid.selectedItem == null){
						Alert.show("          ");	
					}else{
						Alert.show("    ?", "  ", 3, this, delClickHandler);
					}
					
				}
				
				/**
				 *       ,  menuData       
				 **/
			   private function delClickHandler(event:CloseEvent):void {
             	   if (event.detail==Alert.YES){
             	     	menuData.removeItemAt(menuDataGrid.selectedIndex);	
             	    }	
            	}
				
				/**
				 *     ,          
				 **/
				private function doubleClick(event:ListEvent):void{	
					doEdit();					
				}
				
				/**
				 *      
				 **/
				private function doEdit():void{
					if(menuDataGrid.selectedItem == null){
						Alert.show("          ");	
					}else{
						uiComponent= new UIComponent();
						uiComponent.addChild(canvas);
						this.addChild(uiComponent);	
						var menuWindow:MenuTitleWindow = new MenuTitleWindow();
						var obj:Object= {selectIndex:menuDataGrid.selectedIndex,no:menuDataGrid.selectedItem.no,name:menuDataGrid.selectedItem.name,address:menuDataGrid.selectedItem.address
									,type:menuDataGrid.selectedItem.type};							
						if(menuDataGrid.selectedItem.type == "branch"){
							obj.typeSelIndex=0;
						}else{
							obj.typeSelIndex=1;
						}						
						obj.editDo= editMenuData;
						obj.cancleDo=cancleEdit;
						menuWindow.object = obj;
						PopUpManager.addPopUp(menuWindow,this);
						PopUpManager.centerPopUp(menuWindow);
					}
				}
				/**
				 *     
				 **/
				private function doAdd():void{
					if(uiComponent == null){
						uiComponent = new UIComponent();
						uiComponent.addChild(canvas)
					}
					this.addChild(uiComponent);
					var menuWindow:MenuTitleWindow = new MenuTitleWindow();
					var object:Object = {editDo:editMenuData,cancleDo:cancleEdit};
					menuWindow.object= object;
					PopUpManager.addPopUp(menuWindow,this);
					PopUpManager.centerPopUp(menuWindow);
				}	
				
				
				/**
				 *                 ,          
				 *        ,     grid selectIndex,    selectIndex      .
				 *    selectIndex                   .
				 **/
				private function  editMenuData(menuTitle:MenuTitleWindow):void{
					var object:Object = menuTitle.resultObject;
					if(object.hasOwnProperty("selectIndex")){
						menuData.removeItemAt(object.selectIndex);
						menuData.addItemAt(object,object.selectIndex);
					}else{
						menuData.addItem(object);
					}			
					this.menuDataGrid.dataProvider=menuData;
					this.cancleEdit();
				}
				
				/**
				 *    
				 **/
				private function cancleEdit():void{
					this.removeChild(uiComponent);
				}
				
				
			]]>
		</mx:Script>		
		
		<mx:DataGrid id="menuDataGrid" includeInLayout="true" visible="true"  width="100%"  height="90%" 
			editable="false"  y="34" doubleClickEnabled="true" >
   	 		 <mx:columns>
                <mx:DataGridColumn dataField="no"  headerText="  " />
                <mx:DataGridColumn dataField="name" headerText="  "/>
                <mx:DataGridColumn dataField="address"	 headerText="  "/>
               	<mx:DataGridColumn dataField="type"  headerText="  " />
        	</mx:columns>	
   		 </mx:DataGrid>	
   	 <mx:Button id= "delButton"  label="    "  click="doDel()"  x="10" y="10"/>
   	 <mx:Button id= "editButton"  label="    "  click="doEdit()"  x="126" y="10"/>
   	 <mx:Button id= "addButton"  label="    "  click="doAdd()"  x="230" y="10"/>
   	
</mx:Application>


<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="300" title="  " showCloseButton="false" alpha="1.0" fontFamily="Times New Roman" fontSize="12">

	<mx:Script>
		<![CDATA[
			import mx.managers.FocusManager;
            import mx.managers.PopUpManager;
			import mx.collections.ArrayCollection;
			
			[Bindable]
			public var object:Object;
			
			public var resultObject:Object;
			
			private var saveData:Function;	
			private var cancleEdit:Function;
			
			[Bindable]
			public var types:ArrayCollection = new ArrayCollection(
                [ {label:"branch", data:1}, 
                  {label:"leaf", data:2}]);
			
			
			
			/**
			 *         ,    ,                  
			 * saveData     menu.mxml  editMenuData(menuTitle:MenuTitleWindow).
			 *  MenuTitleWindow.mxml        ,         . 
			 **/
			private function doSave():void{
				saveData = object.editDo;
				
				if(object.hasOwnProperty("selectIndex")){
					resultObject={no:this.no.text,name:this.menuName.text,
									address:this.address.text,type: this.typeCombo.selectedItem.label,
									selectIndex:object.selectIndex} ;
				}else{
					resultObject={no:this.no.text,name:this.menuName.text,
									address:this.address.text,type: this.typeCombo.selectedItem.label};
				}
				this.saveData(this);
				PopUpManager.removePopUp(this);
			}
			private function doCancle():void{
				cancleEdit = object.cancleDo;
				PopUpManager.removePopUp(this);
				this.cancleEdit();
			}
		]]>
	</mx:Script>
        <mx:HBox width="100%" y="40">
                <mx:Label text="No:" width="65" textAlign="left"/>
                <mx:TextInput id="no"  text="{object.no}" width="100%" textAlign="left"/>
        </mx:HBox>
         <mx:HBox width="100%" y="161">
                  <mx:Label text="    :" width="65"/>
                <mx:TextInput id="menuName"  text="{object.name}" width="100%" textAlign="left" />
        </mx:HBox>
         <mx:HBox width="100%" y="68">
                  <mx:Label text="  :" width="65"/>
                  <mx:TextInput id="address"  text="{object.address}" width="100%" textAlign="left"/>
        </mx:HBox>
        <mx:HBox width="100%" y="112">
                <mx:Label text="  :" width="65"/>
                <mx:ComboBox id = "typeCombo" dataProvider="{types}"  selectedIndex="{object.typeSelIndex}">
                </mx:ComboBox>
        </mx:HBox>
        <mx:Button label="  " click="doSave()"  x="118" y="228"/>
        <mx:Button label="  " click="doCancle()"  x="201" y="228"/>
</mx:TitleWindow >