views:

18

answers:

2

How can I Access Items Selected in a Component from the Main App

Hi,

I've got a component that has a listControl and a couple of RadioButtonGroups. I need to access the selected items in the main application. What's the best/simplest way to create and access the array of selected items. So, the user clicks the button to confirm the selections and then I need to access those selections in the main app. Is there a way I can use a public var to build the array? Another idea?

<mx:Tile direction="horizontal">

        <mx:Box>
            <mx:Label text="Year" fontWeight="bold"/>
            <mx:List id="myYear" >
                <mx:dataProvider>
                    <mx:Object label="09-10" data="2009_2010" />
                    <mx:Object label="08-09" data="2008_2009" />
                </mx:dataProvider>
            </mx:List>
        </mx:Box>


        <mx:Box>
            <mx:Label text="Type:" fontWeight="bold"/>
            <mx:RadioButtonGroup id="type" />
                <mx:RadioButton groupName="Type" label="Big" value="B" selected="true"/>
                <mx:RadioButton groupName="Type" label="Little" value="L"/>
        </mx:Box>


        <mx:Box >
            <mx:Label text="Level:" fontWeight="bold"/>
            <mx:RadioButtonGroup id="level" />
                <mx:RadioButton groupName="level" label="First" value="F" selected="true"/>
                <mx:RadioButton groupName="level" label="Second" value="S" />
        </mx:Box>


</mx:Tile>

<mx:Button id="Go" label="Go"  
            click="" />

Thank you.

-Laxmidi

+2  A: 

You already have your answer. Expose the values you need to access using a public property on the component. This is written in browser, but the gist is:

[Bindable]
public var exposedValues : Array = new Array();

Then keep this value up to date with your visual components. Possibly something like this:

        <mx:RadioButtonGroup id="type" change="{this.exposedValues = type.selectedItems}" />
            <mx:RadioButton groupName="Type" label="Big" value="B" selected="true"/>
            <mx:RadioButton groupName="Type" label="Little" value="L"/>
www.Flextras.com
www.Flextras.com, Thanks so much for the help -- that works perfectly. Sweet! I'm glad that at least I was on the right track.
Laxmidi
@laxmidi Awesome! Glad to help
www.Flextras.com
A: 

I believe that array not need to be Bindable in this setup.

DoubleThink