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

Simple AS script to play a movie clip on stage with a button

New Here ,
Jan 15, 2020 Jan 15, 2020

Copy link to clipboard

Copied

I have a simple movie clip on stage, (has its own timeline). I need a button on stage, (onHover) to play frame 2 of the MC and (onRollout) to play fram 16 of the mc?

both mc and button are on stage, timeline is one frame.

 

TOPICS
ActionScript , How to , Timeline

Views

149

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Jan 15, 2020 Jan 15, 2020

Hi.

 

It could be something like this:

import flash.events.MouseEvent;

function startAnim(e:MouseEvent):void
{
	yourAnim.gotoAndPlay(2);
}

function endAnim(e:MouseEvent):void
{
	yourAnim.gotoAndPlay(16);
}

yourButton.addEventListener(MouseEvent.MOUSE_OVER, startAnim);
yourButton.addEventListener(MouseEvent.MOUSE_OUT, endAnim);

 

Just assign two mouse event listeners to your button: one for when the cursor is hovering over the button and another one for when the cursor is out.

 

If you want yo

...

Votes

Translate

Translate
Community Expert ,
Jan 15, 2020 Jan 15, 2020

Copy link to clipboard

Copied

LATEST

Hi.

 

It could be something like this:

import flash.events.MouseEvent;

function startAnim(e:MouseEvent):void
{
	yourAnim.gotoAndPlay(2);
}

function endAnim(e:MouseEvent):void
{
	yourAnim.gotoAndPlay(16);
}

yourButton.addEventListener(MouseEvent.MOUSE_OVER, startAnim);
yourButton.addEventListener(MouseEvent.MOUSE_OUT, endAnim);

 

Just assign two mouse event listeners to your button: one for when the cursor is hovering over the button and another one for when the cursor is out.

 

If you want your code to be more efficient, you can add and remove the mouse out event only when needed.

import flash.events.MouseEvent;

function startAnim(e:MouseEvent):void
{
	yourAnim.gotoAndPlay(2);
	yourButton.addEventListener(MouseEvent.MOUSE_OUT, endAnim);
}

function endAnim(e:MouseEvent):void
{
	yourAnim.gotoAndPlay(16);
	yourButton.removeEventListener(MouseEvent.MOUSE_OUT, endAnim);
}

yourButton.addEventListener(MouseEvent.MOUSE_OVER, startAnim);

 

Regards,

JC

Votes

Translate

Translate

Report

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