dimanche 22 novembre 2015

AS3 combobox with icons

I would like to do a combobox with icons. This code is showing icons when combo is expanded, but not when it is closed.

ComboBox

package  {

    import flash.display.MovieClip;

    import fl.controls.ComboBox;
    import fl.data.DataProvider;
    import flash.display.Loader;
    import flash.display.LoaderInfo;
    import flash.display.Bitmap;

    import flash.net.URLRequest;
    import flash.events.Event;

    public class Main extends MovieClip {

        private var _imageLoader:Loader  = new Loader();
        private var _i:int = 0;
        private var _imagenes:Array;
        private var _cb:ComboBox = new ComboBox();
        private var _dp:DataProvider = new DataProvider();

        public function Main() {

            // constructor code         
            _imagenes = ["/images/espana_120x80.png",
                         "/images/alemania_120x80.png",
                         "/images/francia_120x80.png",
                         "/images/inglaterra_120x80.png",
                         "/images/estados-unidos_120x80.png"];

            // loader
            _imageLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, onImageLoadComplete);
            _imageLoader.load(new URLRequest(_imagenes[_i]));

            // ComboBox
            _cb.height = 55;
            _cb.width = 120;

            //_cb.dropdownWidth = 90;
            _cb.dropdown.rowHeight = 55;
            _cb.dropdown.iconField = 'iconClass';
            _cb.dataProvider = _dp;
            _cb.y = 200;

            _cb.selectedIndex=0;
            _cb.addEventListener(Event.CHANGE, changeHandler);

            addChild(_cb);

        }

        function changeHandler(e:Event):void {

            trace(e + " " + _cb.selectedIndex);

        }

        function onImageLoadComplete(e:Event):void{

            var loaderInfo:LoaderInfo = e.target as LoaderInfo;
            var loadedBitmap:Bitmap = loaderInfo.content as Bitmap; 

            loadedBitmap.width = 80;
            loadedBitmap.height = 53;

            _dp.addItem( {item: _i, iconClass: loadedBitmap} );

            _cb.selectedIndex = 0;

            _i++;
            if(_i < _imagenes.length)
                _imageLoader.load(new URLRequest(_imagenes[_i]));
        }


    }

}

Any idea about how to solve it?

Aucun commentaire:

Enregistrer un commentaire