• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Push a View by converting a string to a class?

New Here ,
Apr 27, 2012 Apr 27, 2012

Copy link to clipboard

Copied

Hi,

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:

    <fx:Script>

        <![CDATA[

            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;

                splitNavigator.hideViewNavigatorPopUp();

               

                if(list.selectedItem.data == "NewListView")

                {

                    var myClass:Class = getDefinitionByName(selectedItem) as Class;                   

                    trace("View Class = " + myClass);

                    detailNavigator.pushView(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;

                splitNavigator.hideViewNavigatorPopUp();

            }

           

           

        ]]>

    </fx:Script>

    <fx:Declarations>

        <!-- Place non-visual elements (e.g., services, value objects) here -->

    </fx:Declarations>

   

    <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"

            alternatingItemColors="[0x202020,0x2a2a2a]"

            top="140" horizontalCenter="0" bottom="200"

            downColor="0x70B2EE"

            selectionColor="0x70B2EE"

            change="list_changeHandler(event)">   

        <s:itemRenderer>

            <fx:Component>

                <s:IconItemRenderer messageStyleName="myFontStyle" fontSize="22" height="70"

                                    labelField="label"

                                    messageField=""

                                    />

            </fx:Component>

        </s:itemRenderer>       

    </s:List>

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??

Thanks

Views

703

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 28, 2012 Apr 28, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 28, 2012 Apr 28, 2012

Copy link to clipboard

Copied

LATEST

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");

    ViewNavigator.pushView(MyView);

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?

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines