Question

The following displays a ComboBox with the text "Select One":

**This is pseudo code*

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:ComboBox prompt="Select One">
        <mx:dataProvider>
            <mx:Array>
                <mx:Object label="Obj 1" />
                <mx:Object label="Obj 2" />
                <mx:Object label="Obj 3" />
            </mx:Array>
        </mx:dataProvider>
    </mx:ComboBox>
</mx:Application>

However, the following displays a ComboBox with the text "Obj 1" (the label of the first item):

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Script>
        <![CDATA[
            [Bindable]
            private var promptText:String = "Select One";
        ]]>
    </mx:Script>

    <mx:ComboBox prompt="{promptText}">
        <mx:dataProvider>
            <mx:Array>
                <mx:Object label="Obj 1" />
                <mx:Object label="Obj 2" />
                <mx:Object label="Obj 3" />
            </mx:Array>
        </mx:dataProvider>
    </mx:ComboBox>
</mx:Application>

Why can't I use a Bindable String for the prompt???

Was it helpful?

Solution

This worked:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Script>
        <![CDATA[
            [Bindable]
            private var promptText:String = "Select One";
        ]]>
    </mx:Script>

    <mx:ComboBox selectedIndex="-1" prompt="{promptText}">
        <mx:dataProvider>
            <mx:Array>
                <mx:Object label="Obj 1" />
                <mx:Object label="Obj 2" />
                <mx:Object label="Obj 3" />
            </mx:Array>
        </mx:dataProvider>
    </mx:ComboBox>
</mx:Application>

I can't figure out why I have to explicitly set selectedIndex to -1, but, it works!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top