13 Replies Latest reply: Mar 14, 2013 8:00 AM by fsoender RSS

    Passing data between views

    fsoender Community Member

      There is not much basic data on this on the net, can someone help me out with this issue?

      I have this spinner list that I want "data" to be sent to a view called "View 2"
      How do I write the code in "View 1", and then the receiving end "View 2"?

       

      Can I write it like this:

       

       

      protected function View 1():void
         {
         navigator.pushView(views.View 2, data);   
         }

       

       

       

      This is a spinner in "View 1" I want the "data" to be sent to "View 2":


      s:SpinnerListContainer x="22" y="85" width="135" height="110">
        <s:SpinnerList id="ToolSpinnerLeft" width="125" change="ToolSpinnerLeft_changeHandler(event)"
              fontWeight="bold" labelField="data" selectedIndex="1">
         <s:dataProvider>   
          <s:ArrayList>
           <fx:Object data="Test 1"></fx:Object>
           <fx:Object data="Test 2"></fx:Object>         
          </s:ArrayList>
         </s:dataProvider>
        </s:SpinnerList>
      </s:SpinnerListContainer>

        • 1. Re: Passing data between views
          Flex harUI Adobe Employee

          IMO, your views should share a model.

          • 2. Re: Passing data between views
            fsoender Community Member

            How you do that?

            • 3. Re: Passing data between views
              fsoender Community Member

              I got it to work with text, but I want to send a object, see below. Any sugestions?

               

               

              View 1:


              protected function handleClick(event:MouseEvent):void
                 
                 {
                  var tmpObj:Object = new Object();
                  tmpObj.firstName = inpBox1.text;
                 
                 
                  navigator.pushView(ToolView, tmpObj);
                 
                 }

              <s:Button id="btnSubmit" x="90" y="-6" label="Submit" click="handleClick(event)"/>
              <s:TextInput id="inpBox1" x="166" y="9" width="120" height="32"/>

               

               

               

              View 2:


              <s:Label id="lblName" x="122" y="42" width="193" height="55" text="{data.firstName}"/>

               

               


              I want to send "data" from the spinner, how can I do that?

               

               

              <s:SpinnerListContainer x="173" y="85" width="135" height="110">
                <s:SpinnerList id="Testing" width="125" height="100%" change="Testing_changeHandler(event)"
                      fontWeight="bold" labelField="data" selectedIndex="1">
                 <s:ArrayList>
                  <fx:Object data="Test 1"></fx:Object>
                  <fx:Object data="Test 2"></fx:Object>
                 </s:ArrayList>
                </s:SpinnerList>
              </s:SpinnerListContainer>

              • 4. Re: Passing data between views
                Flex harUI Adobe Employee

                Well, you can cheat and store it up on your application and get it from there or FlexGlobals.topLevelApplication or use some sort of Singleton.

                • 5. Re: Passing data between views
                  fsoender Community Member

                  I almost got it, this code works:

                   

                   

                   

                  View 1:


                  protected function handleClick(event:MouseEvent):void
                     
                     { 
                     
                      var tmpObj:Object = new Object();   
                       
                      var Testing:String;
                      Testing = "Test3"
                      tmpObj.Test = Testing;
                          
                      navigator.pushView(ToolView, tmpObj);   
                     }

                   

                   

                  View 2:

                   

                  <s:Label id="lblName" x="122" y="42" width="193" height="32" text="{data.Test}"/>

                   

                   

                  Trying to do this, so why cant I use String "ToolSpinnerLeftSelected " when it works with the String "Testing" as above?

                   


                  View 1:

                   

                   

                  public var ToolSpinnerLeftSelected:String;

                   

                   

                  <s:SpinnerListContainer x="173" y="85" width="135" height="110">
                  <s:SpinnerList id="ToolSpinnerLeft" width="125" height="100%" change="ToolSpinnerLeft_changeHandler(event)"
                  fontWeight="bold" labelField="data" selectedIndex="1">
                  <s:ArrayList>
                  <fx:Object data="Tool 1"></fx:Object>
                  <fx:Object data="Tool 2"></fx:Object>
                  </s:ArrayList>
                  </s:SpinnerList>
                  </s:SpinnerListContainer>

                   

                   

                   

                   

                     protected function ToolSpinnerLeft_changeHandler(event:IndexChangeEvent):void
                     {
                      switch(data)
                      {    
                       case "Tool 1":
                        ToolSpinnerLeftSelected = "1";
                       case "Tool 2":
                        ToolSpinnerLeftSelected = "2";
                        
                      }
                     
                     }

                   

                  protected function handleClick(event:MouseEvent):void
                     
                     { 
                     
                      var tmpObj:Object = new Object();     
                     
                      tmpObj.Test = ToolSpinnerLeftSelected;
                          
                      navigator.pushView(ToolView, tmpObj);   
                     }

                   

                   

                   

                  View 2:

                   

                  <s:Label id="lblName" x="122" y="42" width="193" height="32" text="{data.Test}"/>

                  • 6. Re: Passing data between views
                    Flex harUI Adobe Employee

                    Probably because it is a variable and needs binding syntax “

                    • 7. Re: Passing data between views
                      fsoender Community Member

                      That wont work, it will send "ToolSpinnerLeftSelected" as a string and not as a veriable.

                       

                      Im starting to wonder if the spinner "data" is not stored in "ToolSpinnerLeftSelected".

                      Is my spinner code ok, I want the "data" from the spinner list to be stored in "ToolSpinnerLeftSelected".

                       

                       

                       

                      <s:SpinnerListContainer x="22" y="85" width="135" height="110">
                        <s:SpinnerList id="ToolSpinnerLeft" width="125" change="ToolSpinnerLeft_changeHandler(event)"
                              fontWeight="bold" labelField="data" selectedIndex="1">
                         <s:dataProvider>   
                          <s:ArrayList>
                           <fx:Object data="Tool 1"></fx:Object>
                           <fx:Object data="Tool 2"></fx:Object>         
                          </s:ArrayList>
                         </s:dataProvider>
                        </s:SpinnerList>
                      </s:SpinnerListContainer>

                       


                      protected function ToolSpinnerLeft_changeHandler(event:IndexChangeEvent):void
                         {
                          switch(data)
                          {    
                           case "Tool 1":
                            ToolSpinnerLeftSelected = "1";
                           case "Tool 2":
                            ToolSpinnerLeftSelected = "2";
                           
                          }
                         
                         }

                       

                      protected function handleClick(event:MouseEvent):void
                         
                         { 
                         
                          var tmpObj:Object = new Object();   
                           
                          tmpObj.Test = ToolSpinnerLeftSelected;
                              
                          navigator.pushView(ToolView, tmpObj);   
                         }

                       


                      • 8. Re: Passing data between views
                        Flex harUI Adobe Employee

                        Maybe I’m not understanding the problem.  I don’t see any obvious problems.  What error do you get?  Setting breakpoints and examining objects will probably help.

                        • 9. Re: Passing data between views
                          fsoender Community Member

                          I got it to work with this code:

                           

                          ToolSpinnerLeftSelected = ToolSpinnerLeft.selectedItem.data


                          But now I get only value "5" no matter what I select as output. If I comment out selection "5", then I get value "4" out, so it
                          select the last one in the spinner list, why?

                          Any suggestions how to fix this problem?

                           

                           

                           

                             protected function ToolSpinnerLeft_changeHandler(event:IndexChangeEvent):void
                             {
                              ToolSpinnerLeftSelected = ToolSpinnerLeft.selectedItem.data
                              
                              switch(ToolSpinnerLeftSelected)
                              {    
                               case "Tool 1":
                                ToolSpinnerLeftSelected = "1";
                               case "Tool 2":
                                ToolSpinnerLeftSelected = "2";
                               case "Tool 3":
                                ToolSpinnerLeftSelected = "3";
                               case "Tool 4":
                                ToolSpinnerLeftSelected = "4";
                             case "Tool 5":
                                ToolSpinnerLeftSelected = "5";     
                              }   
                             }

                           

                           


                          <s:SpinnerListContainer x="22" y="85" width="135" height="110">
                            <s:SpinnerList id="ToolSpinnerLeft" width="125" change="ToolSpinnerLeft_changeHandler(event)"
                                  fontWeight="bold" labelField="data" selectedIndex="1">
                             <s:dataProvider>   
                              <s:ArrayList>    
                               <fx:Object data="Tool 1"></fx:Object>
                               <fx:Object data="Tool 2"></fx:Object>
                               <fx:Object data="Tool 3"></fx:Object>
                               <fx:Object data="Tool 4"></fx:Object>
                               <fx:Object data="Tool 5"></fx:Object>    
                              </s:ArrayList>
                             </s:dataProvider>
                            </s:SpinnerList>
                          </s:SpinnerListContainer>

                          • 10. Re: Passing data between views
                            pauland Community Member

                            Consider using "break" in conjunction with switch/case ..

                             

                            Read up about the switch statement again!

                            • 11. Re: Passing data between views
                              fsoender Community Member

                              Dah, forgot that Thanks!

                               

                              I have one question, how do I send multiple objects?

                              I want to push all three  tmpObj1, tmpObj2, tmpObj3 at the same time.


                              navigator.pushView(ToolView, tmpObj1);
                              navigator.pushView(ToolView, tmpObj2);

                              navigator.pushView(ToolView, tmpObj3);


                              I have tried these without any luck.


                              navigator.pushView(ToolView, tmpObj1, tmpObj2, tmpObj3);

                              navigator.pushView(ToolView, {tmpObj1, tmpObj2, tmpObj3});


                              • 12. Re: Passing data between views
                                fsoender Community Member

                                Ok, I got It to work.

                                 

                                Now Im wondering how I can use the "data" in a "case" statement in view 2?
                                I currently only use it with "text="{data.Blah blah}"

                                 

                                 

                                View 1:

                                 

                                protected function handleClick(event:MouseEvent):void
                                   
                                   { 
                                       
                                    var tmpObj1:Object = new Object();   
                                   
                                    tmpObj1.Tool1Selected_1 = ToolSpinnerTool1Selected;
                                    tmpObj1.Tool2Selected_2 = ToolSpinnerTool2Selected;
                                    tmpObj1.AntennaSelected_3= AntennaSelected;
                                            
                                    navigator.pushView(ToolView, tmpObj1);
                                   
                                       
                                   }

                                 

                                 

                                View 2:

                                 

                                <s:Label id="lblName" x="191" y="51" width="45" height="22" text="{data.Tool1Selected_1}"/>
                                 
                                <s:Label id="lblName2" x="102" y="46" width="53" height="24" text="{data.Tool2Selected_2}"/>

                                <s:Label id="lblName3" x="102" y="77" width="63" height="32" text="{data.AntennaSelected_3}"/>

                                • 13. Re: Passing data between views
                                  fsoender Community Member

                                  Is there any that can help me how to using "data" in a "if" or "ccase" statement?