Skip to main content
Known Participant
November 21, 2020
Question

Multiple buttons on stage targeted by mouse cursor - not working properly

  • November 21, 2020
  • 11 replies
  • 552 views

I am new to animate and want to know what I'm missing. I set up a custom mouse cursor to drag around the stage and grab/click multiple buttons on frame 1 where the button clicked disappears and jumps to a movie clip tween. I want the mouse cursor to grab one button after the other on the stage and keep the rest of the buttons active until they are grabbed/clicked by the mouse. If I have only one button on the stage, it works fine but the moment I add two or more buttons, all the buttons disappear after clicking the first button. Can anyone tell me what I am missing for this? Not sure if it would be a timeline layout change or dropping in code to tell the other buttons to stay put until they are "grabbed" by the mouse. Thanks in advance! cmdh

 

 

stop();

stage.addChild(ball1_mc);

ball1_mc.mouseEnabled = false;

ball1_mc.addEventListener(Event.ENTER_FRAME, fl_CustomMouseCursor_5);

function fl_CustomMouseCursor_5(event:Event)

{

            ball1_mc.x = stage.mouseX;

            ball1_mc.y = stage.mouseY;

}

Mouse.show();

jelly1_btn.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_6);

 

function fl_MouseClickHandler_6(event:MouseEvent):void

{

 

}

 

jelly1_btn.addEventListener(MouseEvent.CLICK, fl_ClickToHide_8);

 

function fl_ClickToHide_8(event:MouseEvent):void

{

            jelly1_btn.visible = false;

}

 

jelly1_btn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_4);

 

function fl_ClickToGoToAndStopAtFrame_4(event:MouseEvent):void

{

            gotoAndStop(2);

}

 

jellypink2_btn.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_10);

 

function fl_MouseClickHandler_10(event:MouseEvent):void

{

           

}

 

jellypink2_btn.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_11);

 

function fl_MouseClickHandler_11(event:MouseEvent):void

{

           

}

 

jellypink2_btn.addEventListener(MouseEvent.CLICK, fl_ClickToHide_9);

 

function fl_ClickToHide_9(event:MouseEvent):void

{

            jellypink2_btn.visible = false;

}

 

stage.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_12);

 

function fl_MouseClickHandler_12(event:MouseEvent):void

{         

}

 

jellypink2_btn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_5);

 

function fl_ClickToGoToAndStopAtFrame_5(event:MouseEvent):void

{

            gotoAndStop(4);

}

 

    This topic is closed to new replies. Start a new post to keep the conversation going.

    11 replies

    kglad
    Community Expert
    Community Expert
    November 21, 2020

    there's nothing in your code about "grabbing" anything. 

     

    there's code the causes ball1_mc to follow the cursor (which you don't hide) and there are click handlers:

     

    1/3 of which do nothing,

    1/3 of which cause the clicked button to disappear.

    1/3 change frames on the timeline that contains that code (and is probably the cause of unintended consequences).

     

    cmdhAuthor
    Known Participant
    November 21, 2020

    Thank you for responding to my inquiry. If I understand correctly, streamlining the code with less "mouseclickhandlers" may fix the problem. What I want is the mouse cursor to roam around the stage finding buttons to click, the button plays through hit/up/down stage, jumps to a movie clip and goes away. At the sme time the mouse cursor hits other buttons which do the similar things increasing a score until all buttons are pushed - pretty simple set up. I want things to happen simultaneously on the stage and currently using frame 1 for mouse /buttons and other frames for the movie clips. Please include the best way to lay out my timeline and other code snippets I coud use to replace or enhance "addEventListener(MouseEvent.CLICK" "show an object" "click to hide" to accomplish what I'm trying to do?  Thank you in advance! cmdh

    kglad
    Community Expert
    Community Expert
    November 21, 2020

    no, getting rid of the useless code won't solve the problem.  it will just make helping you (and you helping yourself easier):

     

    replace all your code with the following:

     

    stop();

    stage.addChild(ball1_mc);

    ball1_mc.mouseEnabled = false;

    ball1_mc.addEventListener(Event.ENTER_FRAME, fl_CustomMouseCursor_5);

    function fl_CustomMouseCursor_5(event:Event)

    {

                ball1_mc.x = stage.mouseX;

                ball1_mc.y = stage.mouseY;

    }

    Mouse.show();  // this is superfluous unless there's code elsewhere that hid the mouse

     

    jelly1_btn.addEventListener(MouseEvent.CLICK, jelly1F);

    jellypink2_btn.addEventListener(MouseEvent.CLICK, jelly2F);

     

    function jelly1F(event:MouseEvent):void

    {

     jelly1_btn.visible = false;

    gotoAndStop(2);

    }

     

    function jelly2F(event:MouseEvent):void

    {

       jellypink2_btn.visible = false;

                gotoAndStop(4);

    }

    ////////////////////////////////

    that fixes no problems but it removes all the useless code and makes reading and debugging your code easier. 

     

    to fix your problem(s), your jelly buttons should exist on frame 1 with the above code and should be in layers that have no other keyframe and extend to, at least, frame 4.