Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6879277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:49:34+00:00 2026-05-27T04:49:34+00:00

so here is the problem that I have so far. I tried to simplify

  • 0

so here is the problem that I have so far. I tried to simplify my code so I can attempt to figure this out, but I have had absolutely no luck. I have a viewstack that contains 1 dropdown per stack. They share the same data provider. What I want to do is to select the item contents from the first one. Once I do that, when I click a button to the next stack I have a function that searches from index 0 to the dataprovider length and if the item from the first stack matches the second one, I want to have the second dropdown pick that item up and display it. I have it matching, and I try to select it, but when I run the application it shows up like nothing is selected. Here is what I have:

edit: I got it to work for a simple example, but when I attempt to use it in my more complicated example, on that button click it for some reason resets the value of selectedIndex to -1. How do I prevent this from happening? This is working code for the simple example

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" applicationComplete="popList()">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>


<fx:Script>
    <![CDATA[
        import mx.collections.ArrayCollection;
        import mx.controls.Alert;
        [Bindable]
        private var myList : ArrayCollection;

        [Bindable]
        private var selectedItem : String;

        [Bindable]
        private var index : int;

        [Bindable]
        private var ind : int;

        private function popList() : void {
            myList = new ArrayCollection();
            stack.initialize();
            myList.addItem("1");
            myList.addItem("2");
            myList.addItem("3");
            myList.addItem("4");
            myList.addItem("5");
            myList.addItem("6");
            first.initialize();
            second.initialize();
        }

        private function goNext() : void {
            selectedItem = first.selectedItem;
            stack.selectedChild = stackb;

            for(index = 0; index < myList.length; index++){
                var itemNow : String = myList[index].toString();
                if(selectedItem == myList[index].toString()){
                    ind = index;
                }
            }

        }

    ]]>
</fx:Script>
<mx:ViewStack id="stack" width="862" height="500">
    <s:NavigatorContent id="stacka">
        <s:DropDownList x="317" y="174" id="first" dataProvider="{myList}"></s:DropDownList>
        <s:Button id="next" x="335" y="263" label="Next" click="goNext()"/>
    </s:NavigatorContent>
    <s:NavigatorContent id="stackb">
        <s:DropDownList x="317" y="174" id="second" dataProvider="{myList}" selectedIndex="{ind}"></s:DropDownList>
    </s:NavigatorContent>
</mx:ViewStack>



</s:Application>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:49:35+00:00Added an answer on May 27, 2026 at 4:49 am

    I didn’t try to run the code, but I have a bunch of observations:

    1. First, don’t use the same dataProvider for two separate DropDownLists. It causes weird issues. It makes no sense, I have no idea why; but it does. You could dupe the dataProvider by creating a second collection using the same source. Something like this:

    –

    second.dataProvider = new ArrayCollection(myList.source);
    
    1. Second, you shouldn’t have to manually call the initialize method on either of the DropDownLists. That is highly unusual. The initialize event is fired as part of the creation process; and I assume the initialization method is part of the default event handler. But, firing that event is not the same as having the component go through it’s Lifecycle process.

    2. A ViewStack doesn’t initialize it’s children before the view changes. So, you are probably setting the selectedIndex on the second DropDownList before that DropDownList is initialized, possibly allowing that drop down list to get lost. You can combat this by setting the creationPolicy to all on the ViewStack.

    3. You can probably solve this issue with binding. Something like this.

    –

    <s:DropDownList x="317" y="174" id="second" dataProvider="{myList}" selectedIndex="{first.selectedIndex}"></s:DropDownList>
    
    1. Your code to select the next item is comparing an object to a string, so you’ll hever the selectedItem.

    You could change your loop to something like this:

            for(index = 0; index < myList.length; index++){
                if(selectedItem == myList[index]){
                    second.selectedIndex = index;
                }
            }
    
    1. But, if you’re using the same dataProvider, or a copy of it, why do you even need the loop? Just use the selectedIndex property:

    –

    second.selectedIndex = first.selectedIndex 
    

    Does that help?

    Note: StackOverflow makes it real hard to do code formatting inside a list; sorry for not keeping the numbers in my list.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the code that I have so far to define the icon: icon_bg
I have a problem I tried solving on my own, but didn't get far
I have a problem that I tried to ask about previously, but didn't get
Here is a hum-dinger of a problem that I have not found an answer
I have an interesting SQL problem that I need help with. Here is the
I'm having a strange problem here... I have an ASP.NET 3.5 application that has
Here's my problem: I have an unmanaged dll that I made.I'm calling one of
Here's my problem: I have a virtual method defined in a .h file that
Here's the problem: 1.) We have page here... www.blah.com/mypage.html 2.) That page requests a
Here's the core problem: I have a .NET application that is using COM interop

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.