Skip to main content
Participant
March 9, 2023
Question

Hover/click button change

  • March 9, 2023
  • 1 reply
  • 367 views

Hello, I am trying to code a button so that when the mouse hovers over, it changes color, and then when you click it changes again. 

 

Right now I have the button built with three frames, but when I do the test animation and hover over the button it only flashes for an instance. When I click it flashes the three frames, but what I'd like is for it to click and hold on the third frame. The button is called "upgrade_now" - any help or guidance on the code for this would be appreciated. 

 

Thanks!

    This topic has been closed for replies.

    1 reply

    kglad
    Community Expert
    Community Expert
    March 9, 2023

    you need to use a movieclip and code it to respond to the mouse.

    Participant
    March 9, 2023

    Hey, thanks again for your help. Right now I am trying to get the movieclip to click and hold on frame 3, and have the code written as follows: 

     

    movieclipname.addEventListener(MouseEvent.CLICK,clickF);

     

    function clickF(e:MouseEvent):void{

    gotoAndStop(3);

    }

     

    But I am still running into the issue of it just causing the movieclip to play and loop to frame 1. The action script is set on the main timeline, and starts when the movie clip appears. I have yet to figure out how to get the movie clip to respond and pause on frame 2 with just a hover over action.

    kglad
    Community Expert
    Community Expert
    March 9, 2023

    you should use frame labels.  it's easier to debug and edit.

     

    moveclipname.addEventListener(MouseEvent.MOUSE_OVER,overF);

    movieclipname.addEventListener(MouseEvent.MOUSE_OUT.outF);

    movieclipname.addEventListener(MouseEvent.CLICK,clickF);

     

    function overF(e:MouseEvent):void{

    e.currentTarget.gotoAndStop("overframe");

    }

    function outF(e:MouseEvent):void{

    e.currentTarget.gotoAndStop("upframe");

    }

    function clickF(e:MouseEvent):void{

    e.currentTarget.gotoAndStop("clickedframe";  // you may want to remove your mouseout listener here

    this.gotoAndStop(3); //if you're trying to direct the parent of movieclipname to its frame 3.

    }