V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
heidour
V2EX  ›  Flash

action script 3 如何为function加参数

  •  
  •   heidour · 2012-07-03 10:21:20 +08:00 · 3193 次点击
    这是一个创建于 4318 天前的主题,其中的信息可能已经有所发展或是发生改变。
    很多按钮,分别跳到第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);


    谢谢各位。
    2 条回复    1970-01-01 08:00:00 +08:00
    imcotton
        1
    imcotton  
       2012-07-03 11:15:46 +08:00   ❤️ 1
    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
        2
    heidour  
    OP
       2012-07-03 11:40:05 +08:00
    @imcotton 虽然不是很明白,但是确实成功了。感谢。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5608 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 08:37 · PVG 16:37 · LAX 01:37 · JFK 04:37
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.