user2743708
user2743708

Reputation: 1

Actionscript 3 mouseover issue

Hi I'm a total novice with actionscript so any help is greatly appreciated.

Basically I have a movie with 2 layers, 1 has closed eyes on the other open eyes.

So the functionality should be that the movie starts with they eyes closed the when the mouse rolls over the movie the eyes open and then when the mouse leaves the movie they close again.

This is the code I have at present, but it isn't working:

package 
{

import flash.display.MovieClip;
import flash.events.MouseEvent;

eyes_closed.addEventListener(MouseEvent.MOUSE_OVER, hideEyes);
eyes_closed.addEventListener(MouseEvent.MOUSE_OUT, openEyes);

function hideEyes(event:MouseEvent):void {
  eyes_open.visible = true;
}

function openEyes(event:MouseEvent):void {
  eyes_closed.visible = true;
}

}

What am I doing wrong?

Upvotes: 0

Views: 5508

Answers (4)

Iagows
Iagows

Reputation: 1099

You forgot to hide the eyes.

function hideEyes(event:MouseEvent):void {
  eyes_open.visible = true;
  eyes_closed.visible = false;
}

function openEyes(event:MouseEvent):void {
  eyes_closed.visible = true;
  eyes_open.visible = false;
}

Another option: change layer order using setChildIndex

Upvotes: 0

DennisBo
DennisBo

Reputation: 48

You want to make one invisible when you make the other visible.

package 
{



    import flash.display.MovieClip;
    import flash.events.MouseEvent;

    eyes_closed.addEventListener(MouseEvent.MOUSE_OVER, hideEyes);
    eyes_closed.addEventListener(MouseEvent.MOUSE_OUT, openEyes);

    function hideEyes(event:MouseEvent):void {
      eyes_open.visible = true;
      eyes_closed.visible = false;
    }

    function openEyes(event:MouseEvent):void {
      eyes_closed.visible = true;
      eyes_open.visible = false;
    }

}

Upvotes: 0

Strille
Strille

Reputation: 5781

One simple solution (no pun intended) is to use the SimpleButton class. It lets you create one display object which internally displays different display objects depending on 3 states (normal, mouse over, and mouse down). Also, a 4:th display object determines the "hit area" (usually the same as the display object used for the normal state).

Example:

import flash.display.SimpleButton;

var closed : MovieClip = new closedMC();
var open : MovieClip = new openMC();

var button : SimpleButton = new SimpleButton(closed, open, open, closed);

One thing though: If you use MovieClip with animation, the MovieClip will restart from frame 1 when the state changes (when you press the button for instance).

Upvotes: 0

Eran
Eran

Reputation: 1702

There are a few options to do what you are trying, one simple solution is :

create 2 layers of sprites - one with eyes closed and over it one with eyes opened (probably you've done it already)

add 2 event listeners to the bottom sprite (eyes_closed) - mouse over ->show eyes_open , mouse_out -> hide eyes_open

Now this is important - on your eyes_open sprite (the top one of the 2) add

eyes_open.mouseEnabled = false
eyes_open.mouseChildren = false

Upvotes: 1

Related Questions