开发者

flash list component with buttons

Is there a way to add buttons in a flash List component ? (Flash cs5, not Flex !)

开发者_如何学Python

If not, any alternative to do it ?

Regards.


If you want to use the Label objects in the List component like buttons, you can add an event listener to the List componenent that listens for ListEvent.ITEM_CLICK as you can see in the following:

package
{
    import fl.controls.List;
    import fl.data.DataProvider;
    import fl.events.ListEvent;
    import flash.display.Sprite

    public class ListExample extends Sprite
    {   
        public function ListExample() 
        {
           init();

        }// end function

        private function init():void
        {
            var buttons:Array = new Array("Mouse", "Cat", "Dog");

            var list:List = new List();
            list.dataProvider = new DataProvider(buttons);
            addChild(list);

            list.addEventListener(ListEvent.ITEM_CLICK, onListItemClick);
        }

        private function onListItemClick(e:ListEvent):void
        {
            switch(e.item.label)
            {
                case "Mouse" : trace("Mice eat cheese"); break;
                case "Cat" : trace("Cats eat the mice"); break;
                case "Dog" : trace("Dogs eat cats"); break;

            }// end switch

        }// end function

    }// end class

}// end package

You can add a conditional in the listener function onListItemClick() to differentiate between the labels that are clicked and then invoke the correspoding code. In the preceding example, I use a switch statement.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜