n>3 個の文字列値を持つ dataprovider を持つ ComboBox を持つ。
combobox.inputText.text = "value in dataprovider";
// OK, selectedIndex is set also
数秒後、ユーザーがボタンを押して開始:
combobox.selectedIndex = 3;
// OK
数秒後にもう一度これを行います
combobox.inputText.text = "value NOT in dataprovider";
最後の行は、combobox.inputText を設定しますが、inputText 値が dataprovider 値に含まれていなくても、selectedIndex を 3 にします。
これは、ボタン 1 を押してからボタン 4 を押してから、もう一度ボタン 1 を押す次の例で証明できます。
<?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"
initialize="initializeHandler(event)">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
[Bindable] private var array : ArrayCollection;
protected function initializeHandler(event:FlexEvent):void {
array = new ArrayCollection();
array.addItem("0:00");
array.addItem("0:30");
array.addItem("1:00");
array.addItem("1:30");
addEventListener(Event.ENTER_FRAME, ef);
}
protected function btnSelect1_clickHandler(event:MouseEvent):void {
cb.selectedIndex = 3;
}
protected function btnSelect2_clickHandler(event:MouseEvent):void {
cb.selectedIndex = -1;
}
protected function btnSelect3_clickHandler(event:MouseEvent):void {
cb.textInput.text = "1:00";
}
protected function btnSelect4_clickHandler(event:MouseEvent):void {
cb.textInput.text = "1:01";
}
protected function ef(event:Event):void {
l.text = "inputText=\"" + cb.textInput.text + "\" selectedIndex=\""+cb.selectedIndex+"\"";
}
]]>
</fx:Script>
<s:VGroup>
<s:ComboBox id="cb" dataProvider="{array}"/>
<s:Button label="select index 3" click="btnSelect1_clickHandler(event)" />
<s:Button label="select index -1" click="btnSelect2_clickHandler(event)" />
<s:Button label="select '1:00'" click="btnSelect3_clickHandler(event)" />
<s:Button label="select '1:01'" click="btnSelect4_clickHandler(event)" />
<s:Label id="l" />
</s:VGroup>
</s:Application>