2 Replies Latest reply on Apr 28, 2012 7:20 AM by anixan

    Push a View by converting a string to a class?




      I am currently working in Flashbuilder 4.6 creating a mobile application and I wish to push the users to a view by based on the menu item they select. My code below shows how I have tried to convert a string from a selected list item into a class object and then pass that into the parameter for the pushView:


                  import mx.collections.*;            
                  import spark.components.SplitViewNavigator;
                  import spark.components.ViewNavigator;
                  import spark.events.IndexChangeEvent;
                  import spark.events.ViewNavigatorEvent;
                  import spark.managers.PersistenceManager;
                  import spark.skins.mobile.SplitViewNavigatorSkin;
                  public var menuAC:ArrayCollection;            
                  public var j_array:Array = [{label:"Home", data:"NLView"}, 
                      {label:"All Jobs", data:"JList"}, 
                      {label:"Company Profiles", data:"SView"}, 
                      {label:"Search By Sector", data:"JView"}];
                  protected function list_changeHandler(event:IndexChangeEvent):void
                      var selectedItem:String = new String(list.selectedItem.data);
                      //trace("Selected Item = " + selectedItem);
                      var splitNavigator:SplitViewNavigator = navigator.parentNavigator as SplitViewNavigator;
                      var detailNavigator:ViewNavigator = splitNavigator.getViewNavigatorAt(0) as ViewNavigator;
                      if(list.selectedItem.data == "NewListView")
                          var myClass:Class = getDefinitionByName(selectedItem) as Class;                    
                          trace("View Class = " + myClass);
                      else if(list.selectedItem.data)
                  protected function view1_viewActivateHandler(event:ViewNavigatorEvent):void
                      if(data.view == "JSFilt")
                          menuAC = new ArrayCollection(j_array);    
                      list.dataProvider = menuAC;
                      // TODO Auto-generated method stub
                      var splitNavigator:SplitViewNavigator = navigator.parentNavigator as SplitViewNavigator;
                      var detailNavigator:ViewNavigator = splitNavigator.getViewNavigatorAt(1) as ViewNavigator;
              <!-- Place non-visual elements (e.g., services, value objects) here -->
          <s:BitmapImage width="100%" height="100%" source="@Embed('assets/images/sidebg.png')" fillMode="repeat"/>
          <s:BitmapImage horizontalCenter="0" top="5" width="175" height="130" source="@Embed('assets/images/G_S_Logo_170x130.png')"/>
          <s:List id="list" left="0" right="0"
                  color="0xFFFFFF" contentBackgroundColor="0x101010"
                  fontSize="20" width="280"
                  top="140" horizontalCenter="0" bottom="200"
                      <s:IconItemRenderer messageStyleName="myFontStyle" fontSize="22" height="70" 

      I have also tried using the following command which also did not work:


      var viewClass:Class = Class(getDefinitionByName(getQualifiedClassName(selectedItem)));


      Has anyone got anyidea how to look at a value selected on a list and then use that string name to push the App to the view as the pushView method wont accept a string??



        • 1. Re: Push a View by converting a string to a class?
          anixan Level 1

          Is there no one who can help on this forum, I post questions here and no one ever answers them?!?

          • 2. Re: Push a View by converting a string to a class?
            anixan Level 1

            I have tried to use the following code in replacement of what I had:


                var myClass:Class = getDefinitionByName(selectedItem.data);


            I should maybe just keep this simple and explain what I want to do. I want to pass a string into the "ViewNavigator.pushView()" that usually only accepts a View Class Object. So I would have the name of the view I want to navigate to stored as a String and then i want to execute the follwoing code, where "MyView" is a String:


                var MyView:String = new String("RightView");



            This seems like a simple concept to me but the "viewNavigator.pushView()" only seems to accept a View Class being passed to it. Can someone please help me?