heidour
V2EX  ›  Flash

action script 3 如何为function加参数

  •  
  •   heidour · Jul 3, 2012 · 3919 views
    This topic created in 5071 days ago, the information mentioned may be changed or developed.
    很多按钮,分别跳到第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 replies    1970-01-01 08:00:00 +08:00
    imcotton
        1
    imcotton  
       Jul 3, 2012   ❤️ 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
       Jul 3, 2012
    @imcotton 虽然不是很明白,但是确实成功了。感谢。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3938 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 00:14 · PVG 08:14 · LAX 17:14 · JFK 20:14
    ♥ Do have faith in what you're doing.