Skip to main content
nated_design
Participant
August 12, 2015
Question

ActionScript - Controls Show/Hide on MouseOver/MouseOut

  • August 12, 2015
  • 1 reply
  • 1796 views

Hi, all!

I currently have a simple play/pause button named "pp" with a two-frame structure as follows:

Frame 1:

              stop();

               btn_2.addEventListener (MouseEvent.CLICK, stopplaying);

function stopplaying(e:MouseEvent):void {

  MovieClip(root).stop();

  stop();

  gotoAndStop(2);
}

Frame 2:

stop();

btn_1.addEventListener (MouseEvent.CLICK, startplaying);

function startplaying(e:MouseEvent):void {

  MovieClip(root).play();

  play();

}

There's also a transparent square called "backpp" that triggers showing/hiding the play/pause button on mouseevents. The code looks like this:

var btn_1, btn_2;


pp.visible = false;

backpp.addEventListener(MouseEvent.MOUSE_OVER, mouseOver);

backpp.addEventListener(MouseEvent.MOUSE_OUT, mouseOut);

function mouseOver(e:Event):void {

    //show the buttons if they exist

    //if(btn_1) btn_1.visible = true;

    //if(btn_2) btn_2.visible = true;

  if(pp) pp.visible = true;

}

function mouseOut(e:Event):void {

    //hide the buttons if they exist

    //if(btn_1) btn_1.visible = false;

    //if(btn_2) btn_2.visible = false;

  if(pp) pp.visible = false;

}


So, my question: whenever I don't have the mouseevent code that shows/hides the playback controls, the controls work perfectly. When I do introduce the show/hide code, the controls show and hide perfectly, but the playback controls no longer function - they essentially become a dumby graphic. Any insight would be hugely appreciated!

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
August 12, 2015

the code you showed with all the comments does nothing to btn_1 and btn_2.

once you removed the if-statement comments, btn_1 and btn_2 won't be visible and clickable at the same time.  ie, they'll never work.

nated_design
Participant
August 12, 2015

Sorry for the confusion. Those lines were from earlier iterations, and I simply forgot to remove them from the post. That section should read:

var btn_1, btn_2;

pp.visible = false;

backpp.addEventListener(MouseEvent.MOUSE_OVER, mouseOver);

backpp.addEventListener(MouseEvent.MOUSE_OUT, mouseOut);

function mouseOver(e:Event):void {

  if(pp) pp.visible = true;

}

function mouseOut(e:Event):void {

  if(pp) pp.visible = false;

}

Where, again, "pp"

kglad
Community Expert
Community Expert
August 12, 2015

use a mousedown for btn_1 and btn_2 listeners.