首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

动态创设button,动态指定事件

2012-12-22 
动态创建button,动态指定事件ActionScript的很多写法与JavaScript的写法很像var button:Button new Butt

动态创建button,动态指定事件
ActionScript的很多写法与JavaScript的写法很像

var button:Button = new Button;button.label = "按钮";button.id = "button_1";button.addEventListener(MouseEvent.CLICK, clickHandler("hello"));或者如下//button.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void{clickChangeHandler(e, "hello")});

private function clickHandler(title:String):Function{return function(e:MouseEvent):void{clickChangeHandler.apply(null, [e, title])};}

private function clickChangeHandler(event:Event, title:String):void{Alert.show(title);}

热点排行