1 Reply Latest reply on Feb 4, 2010 2:56 AM by earl.is.name.my

    Problem with catching an Event

    earl.is.name.my

      Hi There,

      hi have a Problem to catc han Event from a PopUp.

       

      I have the folowing Structure:

       

      Main.mxml

      • SelectKunde.mxml (Called in Main with ViewStack/Canvas Element)
        • ConfirmCluster.mxml (Called in SelectKunde with PopUpManager from DataGrid Data)

       

      I can't catch the dispatchEvent(new Event("selected")); from ConfirmCluster in SelectKunde.

      I tried to catch in function getAllClusters (by creationComplete). Here i use the id from my DataGrid.

      I tried too, to catch by popUp.addEventListener, as i create the PopUp.

       

      What is wrong?

       

      Code from SelectKunde.mxml

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="90%" height="90%" creationComplete="getAllCluster(event)">
           <mx:Script>
                <![CDATA[
                
                import mx.managers.PopUpManager;
                import mx.controls.Alert; 
                   import mx.rpc.events.FaultEvent;
                   import mx.rpc.events.ResultEvent;
                import mx.events.ListEvent;
                   import mx.collections.ArrayCollection;
                
                [Bindable]
                public var userName:String = '';
           
                [Bindable]
                public var userCluster:String = '';
                     
                [Bindable]
                public var userTyp:String = '';
                     
                [Bindable]
                   public var cluster:ArrayCollection = new ArrayCollection();
                        
                   [Bindable] 
                   public var httpurl:String ='';
                   
                [Bindable] 
                public var kunde:String ='';
                     
                [Bindable] 
                public var returnString:String = '';
                     
                     
                        
                      private function getAllCluster(event:Event):void
                {
                
                     //clusterData.addEventListener("selected",testit);
      
                     var getCluster:Object = new Object();
                     
                     getCluster.methode = 'getAllCluster';
                          
                     receiveCluster.send(getCluster)
                }     
                
                private function testit (event:Event):void
                {
                     //trace("PopUp retruns:"+clusterData);
                     
                }
                        
                      private function getClusterData(clusterEvent:ResultEvent):void
                {                    
                     if ( clusterEvent.result.cluster.status == '0' )
                     {
                          Alert.show( clusterEvent.result.cluster.errorcode);
                     }
                     else
                     {
                          userName = clusterEvent.result.cluster.name;
                          userCluster = clusterEvent.result.cluster.cluster;
                          userTyp = clusterEvent.result.cluster.typ;
                          
                     }
                }
                
                private function selectCluster(SelectEvent:ListEvent):void
                {
                       kunde = SelectEvent.itemRenderer.data.name;          
                       
                       var popUp:ConfirmCluster = PopUpManager.createPopUp(this, ConfirmCluster, true) as ConfirmCluster;
                     popUp.kunde = kunde;
                     popUp.addEventListener("selected",testit);
      
                }
              ]]>
           </mx:Script>
           
           <mx:HTTPService id="receiveCluster" fault="Alert.show('Database login error','Fehler')" result="getClusterData(event)" showBusyCursor="true" url="{httpurl}" method="POST"/>
           <mx:Label x="246" y="296" id="newlabel" text="{cluster.toString()}"/>
           
           <mx:DataGrid id="clusterData" x="0" y="0" width="100%" height="100%" dataProvider="{receiveCluster.lastResult.cluster.node}" itemClick="selectCluster(event)">
                <mx:columns>
                     <mx:DataGridColumn headerText="Cluster ID" dataField="id" />
                     <mx:DataGridColumn headerText="Kunde" dataField="name"/>
                     <mx:DataGridColumn headerText="Typ" dataField="typ"/>
                     <mx:DataGridColumn headerText="Mapicon" dataField="mapicons"/>
                </mx:columns>
           </mx:DataGrid>
           
      </mx:Canvas>
      

       

       

      Code from ConfirmCluster.mxml

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="222" height="176" title="Hinweis" showCloseButton="true" close="PopUpManager.removePopUp(this)">
      <mx:Script>
           <![CDATA[
           
           import mx.managers.PopUpManager;
           import mx.controls.Alert;
           import flash.events.*;
           
           [Bindable] public var kunde:String ="";
                
           [Bindable] public var returnString:String = '';
      
              public function returnSelectionJa():void
              {
                   returnString = "ja";
                  dispatchEvent(new Event("selected"));
                     
              }
              
              public function returnSelectionNein():void
              {
                   returnString = "nein";
                      dispatchEvent(new Event("selected"));
                  
              }
           ]]>
      </mx:Script>
           <mx:Label x="31.5" y="35" text="Kunde {kunde} wählen?"/>
           <mx:Button x="118.75" y="77" label="Ja" id="ja" click="returnSelectionJa()"/>
           <mx:Button x="43.25" y="77" label="Nein" id="nein" click="returnSelectionNein()"/>
           
      </mx:TitleWindow>