9 Replies Latest reply on Jan 23, 2011 6:59 PM by Shongrunden

    pass parameter to new view in air desktop app

    Richard Perrett

       

      Hi Guys,

       

      Have developed a mobile app that uses this code .....

       

      public function generalList_ChangeHandler(event:IndexChangeEvent):void

      {

      navigator.pushView(Detail, list.selectedItem);

      }

       

      .... to pass data from a list item that the user clicks to a new view called Detail

       

      This is a very common requirement. ie  Scroll a list, and then click on an item to go to a new view where the

      details about the item selected are rendered.

       

      ..but, I cannot see how to do this in a classic air desktop app.

       

      It must be pretty simple but it is not im Tour de Flex and I can't find a solution on the web.

       

      What would the equivalent code for an air app please?

       

      Thanks,

       

      Richard

        • 1. Re: pass parameter to new view in air desktop app
          ghess01 Level 1

          Hi Richard,

           

          Your code looks good to me, and I am doing the same and it works in both Android and destop AIR deployments/builds.

           

          Have you debuged your application to ensure:

           

          - The event is being fired and handled by your function

          - The list.selectedItem Class is the same type your Details view is interfacing with (errors casting will result in null and view will not display data)

          - The selectedItem object state is as expected (data model is populated)

          - When the view(Details) is activated does its data property reference the selectedItem passed

           

          Cheers,


          Greg

          • 2. Re: pass parameter to new view in air desktop app
            Richard Perrett Level 1

            Greg,

             

            My air app will not recognise 'navigator' and I didn't expect it to as a thought it was a mobile app class that I could not import and use in an air app.  I am just using standard air desktop classes.  Can I use navigator? And if so do you know what package it is in?

             

            Thanks

             

            Richard

            • 3. Re: pass parameter to new view in air desktop app
              ghess01 Level 1

              Oh, I see.

               

              Your right if I remember correctly you implemented your own version of a ViewNavigator for your AIR application.

               

              If you want to use the mobile components in your AIR application you need to add the swc to your project 'mobilecomponents.swc'.

               

              You do this right click project->propertie, then select Flex Build Path and focus on the Library Path tab. Then click "Add SWC" and browse to 'C:\Program Files (x86)\Adobe\Adobe Flash Builder Burrito\sdks\4.5.0\frameworks\libs\mobile' and select the mobilecomponents.swc.

               

              That should allow you to leverage the ViewNavigator in your AIR application. However, as your AIR app is not a MoblieApplication you will have to instanciate your own instance of ViewNavigator to use and push views to.

               

              Hope that helps.

               

              Greg

              • 4. Re: pass parameter to new view in air desktop app
                Richard Perrett Level 1

                Greg,

                 

                Have added the mobilecomponents.swc and am a bit excited now because I think this means I can revert to the more elegant mobile approach for my desktop app.  Sorry to be really slow, and I have looked so as not to waste your time, but what import statement to I need so that I can instantiate my own ViewNavigator?  Not sure what package the classes that come with mobilecomponents.swc are in.

                 

                Thanks again

                 

                Richard

                • 5. Re: pass parameter to new view in air desktop app
                  ghess01 Level 1

                  Hi Richard,

                   

                  Yes, with no API doc's kinda hard to figure out how to import.

                   

                  import spark.components.ViewNavigator;

                   

                  A trick I have been using to find the imports is to use the code completion when defining a new variable type

                   

                  Cheers,

                   

                  Greg

                  • 6. Re: pass parameter to new view in air desktop app
                    Richard Perrett Level 1

                    Hi Greg,

                     

                    Related issue.  <windowedApplication> has no "firstView=" parameter.  How can I auto switch views to my first view as per mobile app?  I have tried calling a self made function gotoFirstView() on "creationComplete=" but can't get the compiler to recognise nagivator.pushview unless it is in a function associated with a view.

                     

                    Any suggestions,

                     

                    Richard

                    • 7. Re: pass parameter to new view in air desktop app
                      Richard Perrett Level 1

                      Hi Greg,

                       

                      Concerning my additional query below I have now solved this via this useful post ...

                       

                      http://labs.almerblank.com/2010/11/using-flex-hero-mobile-framework-in-flex-web-projects/

                       

                      The only thing now between a successful migration from mobile to air desktop seems to be applying the appropriate skins.

                      Have uploaded new post on this.

                       

                      Thanks again,

                       

                      Richard

                      • 8. Re: pass parameter to new view in air/mobile desktop app
                        GJB@Eplixo

                        Hi Guys

                         

                        I came across an issue in the navigator.pushView function and wondered if you had any thoughts on it.

                         

                        I have a scenario assigning variables from a list. My problem is the limitation of not being able to assign a variable which identifies the VIEW in a click event of the list.

                         

                        For example:

                         

                        In the list I have a 'click' handler that passes the list.selectedItem as the data element. However I want to choose the different VIEW based on another variable that I pass to the click handler but find I cannot pass the name of the VIEW as a variable. I tried this as a string, an Object but to no avail. It seems that the VIEW is a class and will not accept anything other than a Class in the navigator.pushView(VIEW , list.selectedItem) thereby not able to accept any other variable.

                         

                        I have tried using

                         

                        var SomeView:String = list.selectedItem.vPage.valueOf()

                        var SomeView:Object = list.selectedItem.vPage // where vPage was the variable string that was assigned from the data of the object in each ListDataItem

                         

                        navigator.pushView(VIEW , list.selectedItem) // works because it is a static Class VIEW destination named VIEW

                        navigator.pushView(SomeView , list.selectedItem) // won't work because it cannot convert (SomeView) String or Object variable to Class

                         

                        So if anyone has any thoughts on this it would be useful.

                         

                        Gerry

                        • 9. Re: pass parameter to new view in air/mobile desktop app
                          Shongrunden Adobe Employee

                          @Gerard Brandon - The first parameter of pushView() takes a Class, not a string or object.  A new instance of the Class you pass in is then created.

                           

                          For example this is correct:

                           

                          navigator.pushView(views.MyNewView);

                           

                          But these are incorrect:

                           

                          navigator.pushView("views.MyNewView");

                           

                          var newView:MyNewView = new MyNewView();

                          navigator.pushView(newView);