4 Replies Latest reply on Jul 16, 2007 10:13 AM by ntsiii

    Combobox = different images

    Anti-Girl Level 1
      [Embed(source="data/A.swf")]
      [Bindable]
      public var A:Class;

      <mx:Image id="xx" source="{A}" x="0" y="0"/>

      if i have an image and combo box, how can i reveal different images on selection
      <mx:Image id="xx" source="{ComboBoxID.selectedItem}" x="0" y="0"/> wont work?
        • 1. Re: Combobox = different images
          ntsiii Level 3
          How about something like:
          [Bindable]var currentImage:Class;

          private function onChangeCombo(oEvent:Event):void
          var sImageId:string = oEvent.target.selectedItem.imgId;
          currentImage = this[sImageId];
          ...
          <mx:Image id="xx" source="{currentImage}" ;

          Tracy
          • 2. Re: Combobox = different images
            ntsiii Level 3
            You will still need the image variabled declared.
            [Embed(source="data/A.swf")]
            [Bindable]
            public var A:Class;
            • 3. Re: Combobox = different images
              Anti-Girl Level 1
              thank u very much ntsiii, not sure why imgId; is at the end of selecteditem,
              but heres the code for anyone that searches for a similar question

              import flash.events.Event;

              [Embed(source="data/A.swf")]
              [Bindable] public var A:Class;

              [Bindable]var currentImage:Class;

              private function onChangeCombo(oEvent:Event):void{
              var sImageId:String = oEvent.target.selectedItem;
              currentImage = this[sImageId];
              }

              <mx:ComboBox id="clicks" change="onChangeCombo(event)">
              <mx:Array>
              <mx:String>select</mx:String>
              <mx:String>A</mx:String>
              </mx:Array>
              </mx:ComboBox>

              <mx:Image id="xx" source="{currentImage}" x="168" y="171"/>
              • 4. Re: Combobox = different images
                ntsiii Level 3
                This assignment:
                var sImageId:string = oEvent.target.selectedItem.imgId;
                depends on the structure of the ComboBox datProvider item objects. Yours is clearly a simple string, but it is more typical to have an array of objects. My example assumed an object with a property named "imgId" which held the image id string.

                Tracy