MattJohnson
01-08-2009, 06:58 PM
Hya!
I am VERY new to Flex (using FlexBuilder3).
Trying to make a sample project to help me get aquainted with it, but hitting a snag. This seems like it should be simple, but the solution is eluding me.
Idea:
I want to have a single combobox containing names from an array.
when you select a name, extra data associated with that name appears in both a panel of textboxes and a datagrid at the same time.
Selected another name will update the data, and if NO NAME is selected (empty) it should clear everything out.
Problems:
I am not sure how to access or refer to each individual element of an array.
(thus cannot fill the combobox with names)
I am not sure if the structure of the DataArray is correct. (id="foo").
I am not sure TextBoxes have have DataProvidors that will auto-update when using the combobox or if I should just set the value manually from something like a Fill() function. (I would like to be able to do ti either way just for learning sake, but not sure if one way is better or more correct or easier or more efficient than the other, of if doing it automatically via a dataprovider is even possible)
Any help would be greatly appreciated.
Here is the code I have :
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable] private var DataArray:ArrayCollection ;
<mx:Array id="DataArray">
<mx:List id="Person">
<mx:String id="ID" value="1"/>
<mx:String id="Name" value="Bob Smith"/>
<mx:String id="City" value="Town1"/>
</mx:List>
<mx:List id="Person">
<mx:String id="ID" value="1"/>
<mx:String id="Name" value="Jon Doe"/>
<mx:String id="City" value="Town2"/>
</mx:List>
</mx:Array>
public function Fill():void
{
DataPanel.title = NamesComboBox.selectedLabel ;
// Fill Panel
// next 3 lines get errors. I am note sure how to access
// things like the DataArray.Name element
NameTextBox.text = lastResult.DataArray.Name ;
IDTextBox.text = lastResult.DataArray.ID ;
CityTextBox.text = lastResult.DataArray.City ;
// instead of the above, ahould I add something like
// dataProvider="{DataArray.Name}"
// to each of the TextBoxes?
// Fill DataGrid
// this should be automatic as we have
// DataProvider="{DataArray}"
// set for the DataGrid, right?
}
]]>
</mx:Script>
<!-- ComboBox with list of Names from DataArray.Name -->
<mx:ComboBox id="NamesComboBox" labelField="Name" dataProvider="{DataArray}" change="Fill();" x="10" y="10"></mx:ComboBox>
<!-- Panels Title gets set to selected Name, TexBoxes are filled with appropriate data -->
<mx:Panel id="DataPanel" title="Name" x="10" y="40" width="343" height="321" layout="absolute">
<mx:Label id="NameLabel" text="Name:" x="0" y="52" />
<mx:Text id="NameTextBox" x="66" y="52" width="47"/>
<mx:Label id="IDNumberLabel" text="IDNumber:" x="0" y="24"/>
<mx:Text id="IDNumberTextBox" x="66" y="24" width="47"/>
<mx:Label id="CityLabel" text="City:" x="0" y="78" />
<mx:Text id="CityTextBox" x="66" y="78" width="47"/>
</mx:Panel>
<!-- DaraGrid shows appropriate Data -->
<mx:DataGrid id="DataGrid" dataProvider="{DataArray}" x="361" y="40" width="368" height="321">
<mx:columns>
<mx:DataGridColumn headerText="ID" dataField="ID"/>
<mx:DataGridColumn headerText="Name" dataField="Name"/>
<mx:DataGridColumn headerText="City" dataField="City"/>
</mx:columns>
</mx:DataGrid>
</mx:Application>
I am VERY new to Flex (using FlexBuilder3).
Trying to make a sample project to help me get aquainted with it, but hitting a snag. This seems like it should be simple, but the solution is eluding me.
Idea:
I want to have a single combobox containing names from an array.
when you select a name, extra data associated with that name appears in both a panel of textboxes and a datagrid at the same time.
Selected another name will update the data, and if NO NAME is selected (empty) it should clear everything out.
Problems:
I am not sure how to access or refer to each individual element of an array.
(thus cannot fill the combobox with names)
I am not sure if the structure of the DataArray is correct. (id="foo").
I am not sure TextBoxes have have DataProvidors that will auto-update when using the combobox or if I should just set the value manually from something like a Fill() function. (I would like to be able to do ti either way just for learning sake, but not sure if one way is better or more correct or easier or more efficient than the other, of if doing it automatically via a dataprovider is even possible)
Any help would be greatly appreciated.
Here is the code I have :
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable] private var DataArray:ArrayCollection ;
<mx:Array id="DataArray">
<mx:List id="Person">
<mx:String id="ID" value="1"/>
<mx:String id="Name" value="Bob Smith"/>
<mx:String id="City" value="Town1"/>
</mx:List>
<mx:List id="Person">
<mx:String id="ID" value="1"/>
<mx:String id="Name" value="Jon Doe"/>
<mx:String id="City" value="Town2"/>
</mx:List>
</mx:Array>
public function Fill():void
{
DataPanel.title = NamesComboBox.selectedLabel ;
// Fill Panel
// next 3 lines get errors. I am note sure how to access
// things like the DataArray.Name element
NameTextBox.text = lastResult.DataArray.Name ;
IDTextBox.text = lastResult.DataArray.ID ;
CityTextBox.text = lastResult.DataArray.City ;
// instead of the above, ahould I add something like
// dataProvider="{DataArray.Name}"
// to each of the TextBoxes?
// Fill DataGrid
// this should be automatic as we have
// DataProvider="{DataArray}"
// set for the DataGrid, right?
}
]]>
</mx:Script>
<!-- ComboBox with list of Names from DataArray.Name -->
<mx:ComboBox id="NamesComboBox" labelField="Name" dataProvider="{DataArray}" change="Fill();" x="10" y="10"></mx:ComboBox>
<!-- Panels Title gets set to selected Name, TexBoxes are filled with appropriate data -->
<mx:Panel id="DataPanel" title="Name" x="10" y="40" width="343" height="321" layout="absolute">
<mx:Label id="NameLabel" text="Name:" x="0" y="52" />
<mx:Text id="NameTextBox" x="66" y="52" width="47"/>
<mx:Label id="IDNumberLabel" text="IDNumber:" x="0" y="24"/>
<mx:Text id="IDNumberTextBox" x="66" y="24" width="47"/>
<mx:Label id="CityLabel" text="City:" x="0" y="78" />
<mx:Text id="CityTextBox" x="66" y="78" width="47"/>
</mx:Panel>
<!-- DaraGrid shows appropriate Data -->
<mx:DataGrid id="DataGrid" dataProvider="{DataArray}" x="361" y="40" width="368" height="321">
<mx:columns>
<mx:DataGridColumn headerText="ID" dataField="ID"/>
<mx:DataGridColumn headerText="Name" dataField="Name"/>
<mx:DataGridColumn headerText="City" dataField="City"/>
</mx:columns>
</mx:DataGrid>
</mx:Application>