Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Community Beginner ,
Nov 21, 2020 Nov 21, 2020

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);

}

 

430
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 21, 2020 Nov 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).

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 21, 2020 Nov 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 21, 2020 Nov 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.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 21, 2020 Nov 21, 2020

Wow, you are awesome kglad...! Thank you so much for helping me. Will try this. 😊

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 21, 2020 Nov 21, 2020

Code works great - Thanks kglad - I still have the issue with buttons disappearing after clicking one of them. Is there a work around for this? The artwork and instance names are all different so not sure why the other buttons disappear.

 

Storyboard description is; the mouse cursor roams 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 same time the mouse cursor hits other buttons which do similar things on the stage in frame 1 increasing a score until all buttons are pushed - pretty simple set up. How do I tell AS3 (or HTML code) to keep the other buttons visible until they are clicked in frame 1? Right now, all other buttons disappear after clicking just the first button on the stage. I also need a counter that relates to clicked buttons. Let me know if this can work. Thanks in advance! cmdh

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 21, 2020 Nov 21, 2020

put the jelly buttons on their own layer(s) with no other keyframes in their layer(s) and extend the layer(s), at least, to frame 4.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 21, 2020 Nov 21, 2020

You want the mouse cursor to roam around the stage finding things... by itself? You're going to need some sort of AI routine for it then.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 21, 2020 Nov 21, 2020

Oh really - cool! How do I do that? 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 21, 2020 Nov 21, 2020

Thank you ClayUUID. I am searching online and in adobe support but I cannot find anything on AI routine "templates" "code examples" or "tutorials" for animate that I could try for a work around. Do you know of any compatible sites I could get sufficient code / plugins or tutorials to do what I want? 

 

Storyboard description is; the mouse cursor roams 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 same time the mouse cursor hits other buttons which do similar things on the stage in frame 1 increasing a score until all buttons are pushed - pretty simple set up. How do I tell AS3 (or HTML code) to keep the other buttons visible until they are clicked in frame 1? Right now, all other buttons disappear after clicking just the first button on the stage. I also need a counter that relates to clicked buttons. Let me know if this can work. Thanks in advance! cmdh

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 21, 2020 Nov 21, 2020

I figured it out - yay! Thanks for the assistance here in the forum. cmdh

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 22, 2020 Nov 22, 2020
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines