action script 3 如何为function加参数

2012-07-03 10:21:20 +08:00
 heidour
很多按钮,分别跳到第2帧,3帧,N帧。我这样写的话要写一堆。
怎样只写一个function,然后调用的时候加一个数字就可以跳到相应的帧呢?

function detailshow2(event:MouseEvent) {
gotoAndPlay(2);
}

function detailshow3(event:MouseEvent) {
gotoAndPlay(3);
}

btn1.addEventListener(MouseEvent.MOUSE_UP,detailshow2);
btn2.addEventListener(MouseEvent.MOUSE_UP,detailshow3);


谢谢各位。
3211 次点击
所在节点   Flash
2 条回复
imcotton
2012-07-03 11:15:46 +08:00
var list:Array = [btn1, btn2];

for each (var i:IEventDispatcher in list)
i.addEventListener(MouseEvent.CLICK, onClick);

function onClick (event:MouseEvent):void
{
var index:int = list.indexOf(event.target);

if (index == -1)
return;

gotoAndPlay(index + 1);
}
heidour
2012-07-03 11:40:05 +08:00
@imcotton 虽然不是很明白,但是确实成功了。感谢。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/41246

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX