How to hide a button after clicking another button in Flash?

前端 未结 2 1052
旧巷少年郎
旧巷少年郎 2021-01-24 06:05

I am using actionscript 3 to make a point and click game. On frame 1 there are two buttons, button 1 and 2. On frame 3 there are two buttons, button A and B.

I want it

2条回答
  •  执笔经年
    2021-01-24 06:40

    If you try to remove something that is not in the display list yet Flash will thrown an error. I guess the best solution here is setting up a timeline variable to keep track of which button you have pressed. Something like this:

    on frame 1

    var b1:Boolean = false;
    var b2:Boolean = false;
    
    button1.addEventListener(MouseEvent.MOUSE_DOWN, checkButton);
    button2.addEventListener(MouseEvent.MOUSE_DOWN, checkButton);
    
    function checkButton(e:MouseEvent):void
    {
       if(e.target.name == button1) b1 = true;
       else b2 = true;
    
       gotoAndPlay(3);
    }
    

    on frame 3

    myButtomA.visible = false;
    myButtomB.visible = false;   
    
    if (b1) myButtomA.visible = true;
    if (b2) myButtomB.visible = true;
    

提交回复
热议问题