真才实料才是最真

Dream have no limit

统计

积分与排名

good link

最新评论

flex 父窗口和子窗口之间互相传值

main.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="this.contextMenu.hideBuiltInItems();" creationComplete="init()">
 
 <mx:RemoteObject id="myhhr"  destination="idis" fault="faultHandler(event)" showBusyCursor="true">
        <mx:method name="returnIdis" result="returnMsgHandler(event)" fault="faultHandler(event)" />
    </mx:RemoteObject>
   
   
    <mx:Script>
     <![CDATA[
      import component.test4;
      
      import component.test;
      import mx.managers.PopUpManager;
      
      import mx.containers.TitleWindow;
      import mx.events.ItemClickEvent;
      import mx.controls.LinkButton;
      import mx.core.UIComponent;
      import mx.utils.ArrayUtil;
            import hhridisVo;
            import mx.collections.ArrayCollection;
            import mx.rpc.events.ResultEvent;
            import mx.controls.Alert;
            import mx.rpc.events.FaultEvent;          
            import mx.controls.LinkButton
           
           
            [Bindable] private var dp:ArrayCollection;          
            [Bindable] private var ldp:ArrayCollection;
           
             public static var testarray:Array;  
             public var secondwindow:test4;  
            
            //设置LinkBar的Button引用
            private function init():void{  
                      
             myhhr.returnIdis.send();           
            }
                       
            private function returnMsgHandler(e:ResultEvent):void{
             
             dp = new ArrayCollection(ArrayUtil.toArray(e.result));             
             var i:int;             
             for(i=0; i<dp.length; i++) 
             {
              if(dp[i].id_dependent_id == dp[i].id_item_id )
              {
               var cb:LinkButton = new LinkButton();
               cb.label = dp[i].id_item_name; 
               cb.id = dp[i].id_item_id; 
               cb.document = dp[i].id_description;                                                    
               cb.setStyle("color","#ff00ff");
               cb.addEventListener(MouseEvent.CLICK,controlfunction);
               panel.addChild(cb);      
              }      
              
             }           
            }
           
            private function controlfunction(e:Event):void
            {
             var k:int;
             var q:int;
             var m:int = 0;
             for(k=0; k<dp.length; k++)
             {
              if(e.currentTarget.id == dp[k].id_dependent_id)
              {
               m++;
              }
             }
             //Alert.show("m size is ===" + m);
             //Alert.show("e.currentTarget.id =" + e.currentTarget.id);
             if(m == 1)
             {
              var titleWindowInstance:test =
           test(PopUpManager.createPopUp(this,
                    test,
                    false));     //instantiate and show the title window
   
      PopUpManager.centerPopUp(titleWindowInstance);
      titleWindowInstance.title = "Non-Modal Title Window Data";//built-in property
      titleWindowInstance.width = 400;                 //built-in property
      titleWindowInstance.height = 450;                 //built-in property  
      //titleWindowInstance.x = 100;
      //titleWindowInstance.y = 100;
      //titleWindowInstance.mainApp = this;                      //Reference to the main app scope
      //titleWindowInstance.gnMyNumber = parseFloat(tiMyNumber.text);  //Pass a simple value to the popup
      titleWindowInstance.itemid = e.currentTarget.id;
      titleWindowInstance.itemname = e.currentTarget.label;
      titleWindowInstance.description = e.currentTarget.document;
             }
             if(m > 1)
             {
              testarray = new Array;
              secondwindow = test4(PopUpManager.createPopUp(this, test4, false));
              //PopUpManager.centerPopUp(secondwindow);
              secondwindow.title = "this is test4---->";
              secondwindow.width = 700;
              secondwindow.height = 500;
              
              for(q=0; q<dp.length; q++)
              {
               //Alert.show("first");
               if( e.currentTarget.id == dp[q].id_dependent_id)
               {
                //Alert.show("dp[q].id_item_id==========================>" + dp[q].id_item_id);                    
                testarray.push({id_item_id:dp[q].id_item_id, id_item_name:dp[q].id_item_name, id_file_name:dp[q].id_file_name, id_description:dp[q].id_description});                
                //Alert.show("second");
                //secondwindow.itemid = dp[q].id_item_id;
                //Alert.show("secondwindow.itemid = " + secondwindow.itemid);
                //Alert.show("dp[q].id_item_id = " + dp[q].id_item_id);
                //secondwindow.itemname = dp[q].id_item_name;
                //secondwindow.description = dp[q].id_description;    
               }
               //Alert.show("third");               
               
              }
              //Alert.show("testarray.length ==============>" + testarray.length);                   
     PopUpManager.centerPopUp(secondwindow);
     
              /*
        for (var i:int = 0; i < testarray.length; ++i)
        {
         //secondwindow.testarray.push({id_item_id:testarray[i].id_item_id, id_item_name:testarray[i].id_item_name, id_file_name:testarray[i].id_file_name, id_description:testarray[i].id_description});
         //Alert.show("testarray id_item_id is ===>" + testarray[i].id_item_id);
         //Alert.show("testarray id_item_name is ===>" + testarray[i].id_item_name);
         //Alert.show("testarray id_file_name is ===>" + testarray[i].id_file_name);
         //Alert.show("testarray id_description is ===>" + testarray[i].id_description);
     } 
     */
                 
             }
             
            }
          
            private function faultHandler(e:Event):void{
             Alert.show("留言本暂时无法使用!\n请稍后再试!");
            }
           
         private function changeSkin():void {
    toggleBtnBySelected.selected = toggleBtnBySelected.selected ? false : true;
   }
   
    private function controlURL(e:Event):void
    {  
     //Alert.show("---->" +e.currentTarget.data);     
     var u:URLRequest = new URLRequest("control.mxml?item_id="+e.currentTarget.data);       
          navigateToURL(u,"_blank");
    } 
   
    private function showTitleWindow(e:Event):void
   {
     var titleWindowInstance:test =
           test(PopUpManager.createPopUp(this,
                    test,
                    false));     //instantiate and show the title window
   
     PopUpManager.centerPopUp(titleWindowInstance);
     titleWindowInstance.title = "Non-Modal Title Window Data";//built-in property
     titleWindowInstance.width = 400;                 //built-in property
     titleWindowInstance.height = 450;                 //built-in property  
     titleWindowInstance.x = 100;
     titleWindowInstance.y = 100;
     //titleWindowInstance.mainApp = this;                      //Reference to the main app scope
     //titleWindowInstance.gnMyNumber = parseFloat(tiMyNumber.text);  //Pass a simple value to the popup
     titleWindowInstance.itemid = e.currentTarget.data;
     titleWindowInstance.itemname = e.currentTarget.label;
     titleWindowInstance.description = e.currentTarget.document;
     //ResizeManager.enableResize(titleWindowInstance, 500);
   } 
   
   
                  
     ]]>
    </mx:Script>       


 <mx:VBox x="50" y="50" id="panel">
  <mx:Button label="Add LinkButton"/>  
 </mx:VBox>
 
 <mx:Button id="toggleBtnByToggle" label="toggleControl" icon="@Embed('12.jpg')" toggle="true" x="500" y="100"/>
 <mx:Button id="toggleBtnBySelected" label="selectedControl" click="changeSkin()" x="300" y="100"/>


</mx:Application>


test4.mxml (component)

<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" backgroundColor="#FFFFFF"
 showCloseButton="true" close="close()" creationComplete="init()" layout="absolute" width="700" height="500">
 
 <mx:RemoteObject id="myhhrisast"  destination="hhrisast" fault="faultHandler(event)" showBusyCursor="true">
        <mx:method name="insertHhrisast" result="insertHhrisast(event)" fault="faultHandler(event)" />
    </mx:RemoteObject>
   
 <mx:Script>
  <![CDATA[
   import mx.controls.CheckBox;
   import mx.controls.LinkButton;
   import mx.controls.Text;
   //import mx.collections.ArrayCollection;
   import mx.managers.PopUpManager;
   import mx.controls.Alert;
   
   public var desc:Text;
   public var down_file:LinkButton;
   public var check:CheckBox;
   public var storeInfo:Array = new Array;

   public function init():void
   {
    //Alert.show("--------->>>>" + index.testarray.length);
    var i:int;
       
    for(i=0; i<main.testarray.length; i++)
    {
     desc = new Text();
     desc.text = main.testarray[i].id_description;    //就这样可以直接访问. parent 还没用过.
     desc.width = 300;
     vbox.addChild(desc);
         
     down_file = new LinkButton();
     down_file.label = main.testarray[i].id_file_name;
     down_file.setStyle("color","#EE1000");
     ibox.addChild(down_file);
     
     check = new CheckBox();
     check.id = main.testarray[i].id_item_id;    
     check.addEventListener(MouseEvent.CLICK, store);
     mbox.addChild(check);
     
    }   
    
   }
   private function store(e:Event):void
   {
    //Alert.show("you clicked the " + e.currentTarget.id);
    //Alert.show("storeInfo 1 ---->" + storeInfo.length);
    if(storeInfo.length == 0)
    {    
     storeInfo.push({id:e.currentTarget.id});
    }
    else if(storeInfo.length > 0)
    {
     var i:int;
     var k:int = 0;
     for(i=0; i<storeInfo.length; i++)
     {
      if(storeInfo[i].id == e.currentTarget.id)
      {
       //Alert.show("^&^");       
       storeInfo[i].id = "";            
       k++;
      }
     }
     if(k == 0)
     {
      //Alert.show("^0^");
      storeInfo.push({id:e.currentTarget.id});
     }
    }
    //Alert.show("storeInfo 2 ---->" + storeInfo.length);
   }
   
   private function close():void
   {
    PopUpManager.removePopUp(this);    
   }
   
   private function submit():void
   {
    //Alert.show("storeInfo size ===>" + storeInfo.length);
    var i:int;
    if(storeInfo.length == 0 )
    {
     Alert.show("Please check and then click confirm button!!!");
    }
    else
    {
     
     for(i=0; i<storeInfo.length; i++)
     {
      Alert.show("storeInfo ===" + storeInfo[i].id);
      if(storeInfo[i].id != "")
      { 
       Alert.show("^)^"); 
       var hhrisast:hhrisastVo = new hhrisastVo();  
       hhrisast.comui_id = "111111";
       hhrisast.item_id =  storeInfo[i].id;
       hhrisast.priview_id = "over";
       hhrisast.status = "Y";  
       myhhrisast.insertHhrisast.send(hhrisast);
      }
     }
     
    }
    
   }
   
   private function faultHandler(e:Event):void
   {
           
            Alert.show("happened the error!\n please try again!");           
      }  
   private function insertHhrisast(e:Event):void
      {
       Alert.show("insert successful~");
      }
     
     
  ]]>
 </mx:Script> 
 
  <mx:VBox x="10" y="10" id="vbox">  
 </mx:VBox> 
 <mx:VBox x="340" y="18" id="ibox" verticalGap="8"> 
  <mx:Label fontSize="16" text="Download Document" color="#00FFFF" x="340" y="18"/>
 </mx:VBox> 
 <mx:VBox x="531" y="18" id="mbox" verticalGap="13" horizontalAlign="center"> 
  <mx:Label fontSize="16" text="Please Confirm" color="#00FF00" x="531" y="18"/>
 </mx:VBox> 
 <mx:Button x="411" y="381" label="Submit" click="submit()"/>
 <mx:Button x="519" y="381" label="Cancel" click="close()"/>

</mx:TitleWindow>

我用红色标的地方重要.

posted on 2007-09-05 20:26 gavinkin555 阅读(4015) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。