I have a statePicker
component that I created. If I try to pass a value to the statePicker,
then the comboBox will display the proper label for the data I passed in.
For example,
this line of code
will display Massachusetts in the comboBox.
<StatePicker
id="state" width="200" statePassedIn="MA" />
What I really need
to do is bind the data to the variable, statePassedIn. I have successfully
bound data to a custom component before with no trouble, but for some reason
cannot figure out how to get the data to pass in for the the comboBox.
statePassedIn shows up empty in the statePicker component. For
example,
here is a snippet of
what I am trying to do, that won't work.
var
test:String;
function onInit()
{ //I have determined that this ftn is
indeed running properly
test = "MA";
}
...
<StatePicker
id="state" width="200" statePassedIn="{test}" />
...
<<StatePicker.mxml>>
<?xml
version="1.0" encoding="utf-8"?>
<mx:Canvas
xmlns:mx="http://www.macromedia.com/2003/mxml"
xmlns="*">
<mx:Model id="statesModel" source="data/states.xml"/>
<mx:Script>
<![CDATA[
var selectedItem:Object;
public var src;
var _statePassedIn;
function set statePassedIn(src) {
_statePassedIn = src;
}
private function setInitialItem():Boolean
{
var items:Array = mx.utils.ArrayUtil.toArray(statesModel.state);
var dataValueInit:String = _statePassedIn;
var dataValueCur:String;
mx.controls.Alert.show(statePassedIn);
for ( var i:Number=0; i<items.length; i++ ) { //loop over the items in the dataProvider
dataValueCur = items[i].data; //get the current item.data value
if ( dataValueCur == dataValueInit ) { //compare desired value to current item.data value
stateComboBox.selectedIndex = i; //set the seletedIndex of the combo box
return true;
}
}//for ( var i:Number=0;....
return false;
}
]]>
</mx:Script>
<![CDATA[
var selectedItem:Object;
public var src;
var _statePassedIn;
function set statePassedIn(src) {
_statePassedIn = src;
}
private function setInitialItem():Boolean
{
var items:Array = mx.utils.ArrayUtil.toArray(statesModel.state);
var dataValueInit:String = _statePassedIn;
var dataValueCur:String;
mx.controls.Alert.show(statePassedIn);
for ( var i:Number=0; i<items.length; i++ ) { //loop over the items in the dataProvider
dataValueCur = items[i].data; //get the current item.data value
if ( dataValueCur == dataValueInit ) { //compare desired value to current item.data value
stateComboBox.selectedIndex = i; //set the seletedIndex of the combo box
return true;
}
}//for ( var i:Number=0;....
return false;
}
]]>
</mx:Script>
<mx:ComboBox id="stateComboBox" dataProvider="{statesModel.state}"
labelField="name"
width="{this.width}"
change="this.selectedItem=event.target.selectedItem"
initialize="setInitialItem()"/>
</mx:Canvas>
change="this.selectedItem=event.target.selectedItem"
initialize="setInitialItem()"/>
</mx:Canvas>
Please help,
Kim
_________________________________
Kim
Reddington
Principal Consultant/Developer
Deluxe Technologies
http://www.deluxetechnologies.com
508-231-8744
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
YAHOO! GROUPS LINKS
- Visit your group "flexcoders" on the web.
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.