assem
assem

Reputation: 3223

How to implement the onmouseover effect in actionscript 3?

I want a scrollbar to show up when the onmouseover event is triggered on element A.

How is this done with actionscript 3?

Upvotes: 0

Views: 1639

Answers (2)

Scott
Scott

Reputation: 31

for this explanation :

  • instance name "spriteA"= your element 'A' is a Sprite that you have on your stage with some background graphic on it.
  • instance name "scrollbar" = your scrollbar is another Sprite that you will have on your stage someplace, since you didn't ask how to get the scrollbar to work, I'll assume you already have.
  • both spriteA and scrollbar are children of the main document class or main stage

Code:

import flash.events.MouseEvent;

toggleScrollbar(new MouseEvent(MouseEvent.ROLL_OUT));

spriteA.addEventListener(MouseEvent.ROLL_OVER, toggleScrollbar);
spriteA.buttonMode = true;

//and if needed:
spriteA.addEventListener(MouseEvent.ROLL_OUT, toggleScrollbar);

private function toggleScrollbar(e:MouseEvent):void
{
    switch(e.type)
    {
        case "rollover":
            scrollbar.visible = true;
            break;

        case "rollout":
            scrollbar.visible = false;
            break;

        default:
            break;

    }
}

Upvotes: 3

Sam
Sam

Reputation: 1243

A.addEventListener(MouseEvent.MOUSE_OVER, showScrollbar);
A.addEventListener(MouseEvent.MOUSE_OUT, hideScrollbar);

function showScrollbar(e:MouseEvent):void
{
//make the scrollbar visible
}

function hideScrollbar(e:MouseEvent):void
{
//hide the scrollbar again
}

Upvotes: 0

Related Questions