AS3.0 关于相类似的监听函数的简便表述

[复制链接]
查看11 | 回复1 | 2010-9-13 12:14:48 | 显示全部楼层 |阅读模式
function circle1(event:MouseEvent):void
{
p1.gotoAndStop(2);
}
p1.addEventListener(MouseEvent.CLICK,circle1);
function circle2(event:MouseEvent):void
{
p2.gotoAndStop(2);
}
p2.addEventListener(MouseEvent.CLICK,circle2);
function circle3(event:MouseEvent):void
{
p3.gotoAndStop(2);
}
p3.addEventListener(MouseEvent.CLICK,circle3);
像这种类型的代码能不能通过什么方法写成只有一个函数一个监听的形式

回复

使用道具 举报

千问 | 2010-9-13 12:14:48 | 显示全部楼层
function circle(event:MouseEvent):void{ event.target.gotoAndStop(2);}for(var i:uint=1;i<=3;i++){ this["p"+i].addEventListener(MouseEvent.CLICK,circle);};用一个for循环去遍历所有按钮,这样就可以了。希望可以帮到你!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行