egret--一次性给多个对象添加点击事件
程序员文章站
2024-03-16 16:00:34
...
创建一个函数:
/** *param(数组) 将所需控件的ID放进去 *this.list_MyListener事件列表 */
protected addTouchEventListener(...param:string[]):void
{
if(!this.list_MyListener)
{
this.list_MyListener = [];
}
var name_:string ;
for(var i = 0; i < param.length; i++)
{
name_ = param[i];
if(this.skin[name_])
{
this.skin[name_]["name"] = name_;
this.list_MyListener.push( this.skin[name_] );
}
}
}
/** *在事件列表中添加事件回调 */
protected setListenerTouchEvent(isAdd:boolean):void
{
if(isAdd)
{
for(var i = 0; i < this.list_MyListener.length; i++)
{
var one:any = this.list_MyListener[i];
if(one)
{
one.addEventListener( egret.TouchEvent.TOUCH_TAP, this.onTouch, this );
}
}
}
else
{
for(var i = 0; i < this.list_MyListener.length; i++)
{
var one:any = this.list_MyListener[i];
if(one)
{
one.removeEventListener( egret.TouchEvent.TOUCH_TAP, this.onTouch, this );
}
}
}
}
在所需页面调用: /** 1,2,3为控件id */ super.addTouchEventListener("3","2","1");