mardi 30 juin 2015

Add Event-Listener for the whole Symbol

I´ve put a Label and a ComboBox together in a Symbol, like in the code below.

public class LabelCombo extends MovieClip {     


        //myLabel is an instance of fl.controls.Label
        //myCombo is an instance of fl.controls.ComboBox
        public function LabelCombo() {              
        }


        public function setLabelText(s:String):void{
            myLabel.text = s;
        }

        public function getLabelText():String{
            return myLabel.text;
        }



        public function removeAllItems():void{
            if(myCombo.dataProvider.length > 0)
                myCombo.removeAll();
        }


        public function setSingleItem(o:Object):void{
            removeAllItems();
            myCombo.addItem(o);
        }


        public function setList(itemList:Array):void{
            for(var i:int = 0; i < itemList.length; i++){
                if(i==0)
                    setSingleItem(itemList[i]);
                else
                    addSingleItem(itemList[i]);
            }
        }


        public function addSingleItem(o:Object):void{
            for(var i:int = 0; i < myCombo.dataProvider.length; i++){
                    if(o == myCombo.getItemAt(i))
                        return;
                }
            myCombo.addItem(o);
        }


        public function addList(itemList:Array):void{
            for(var i:int = 0; i < itemList.length; i++){
                addSingleItem(itemList[i]);
            }
        }

        public function getSelectedItem():Object{
            return myCombo.selectedItem;
        }

        public function getItemByLabel(s:String):Object{
            return Object(myCombo.getChildByName(s));
        }

        public function selectItemAt(index:int):void{
            myCombo.selectedIndex = index;
        }

        public function getselectedIndex():int{
            return myCombo.selectedIndex;
        }

    }

Now I want to addEventListener(Event.CHANGE, changeHandler) on the whole Symbol so I can do something like that

trace(LabelCombo(event.currentTarget).getLabelText())

trace(LabelCombo(event.currentTarget).getSelectedItem().data)

I need information from both single controls. It`d be nice if someone can show me how to do this.

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire