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

Help with MOUSE_OVER and MOUSE_OUT events

New Here ,
Nov 05, 2013 Nov 05, 2013

Hello,

I'm very new to Flash and I'm having a bit of an issue with my first ActionScript.

I am working on a project where I have a black and white picture. When you mouse over the picture, it turns to a color version of the same picture. When you take your mouse off of the picture, it goes back to black and white.

I have three instances of the picture, a black and white image at frame 1, a color image at frame 10, and a black and white image at frame 20. Currently, when I mouse over the black and white picture, it turns to the color picture like I had hoped. However, when my mouse leaves the picture, it stays on the color picture.

My code looks like this:

import flash.events.MouseEvent;

stop();

btnCory.addEventListener(MouseEvent.MOUSE_OVER, coryOn);
btnCory2.addEventListener(MouseEvent.MOUSE_OUT, coryOff);
function coryOn(event:MouseEvent):void {
gotoAndStop(10)
}
function coryOff(event:MouseEvent):void {
gotoAndStop(20)
}

btnCory is the first black and white picture at frame 1, btnCory2 is the color picture at frame 10.

Any feedback / help would be much appriciated.


Thanks,


Jeremy

TOPICS
ActionScript
388
Translate
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 , Nov 05, 2013 Nov 05, 2013

your movieclip with images on frame 1, 10 and 20 should have one name (eg, image_mc) and you don't need to convert the images on frames 1 and 10 (and 20 though there's no point to having a duplicate image on frames 1 and 20) to objects and your code should look something like:

import flash.events.MouseEvent;

stop();

image_mc.addEventListener(MouseEvent.MOUSE_OVER, onF);
image_mc.addEventListener(MouseEvent.MOUSE_OUT, offF);
function onF(event:MouseEvent):void {
image_mc.gotoAndStop(10)
}
function offF(e

...
Translate
Community Expert ,
Nov 05, 2013 Nov 05, 2013
LATEST

your movieclip with images on frame 1, 10 and 20 should have one name (eg, image_mc) and you don't need to convert the images on frames 1 and 10 (and 20 though there's no point to having a duplicate image on frames 1 and 20) to objects and your code should look something like:

import flash.events.MouseEvent;

stop();

image_mc.addEventListener(MouseEvent.MOUSE_OVER, onF);
image_mc.addEventListener(MouseEvent.MOUSE_OUT, offF);
function onF(event:MouseEvent):void {
image_mc.gotoAndStop(10)
}
function offF(event:MouseEvent):void {
image_mc.gotoAndStop(1); 
}

and from a message in the cc forum i see you're using 5 images, so use:

import flash.events.MouseEvent;

stop();

image_mc.addEventListener(MouseEvent.MOUSE_OVER, onF);
image_mc.addEventListener(MouseEvent.MOUSE_OUT, offF);
function onF(event:MouseEvent):void {
MovieClip(e.currentTarget).gotoAndStop(10)
}
function offF(event:MouseEvent):void {
MovieClip(e.currentTarget).gotoAndStop(1); 
}

Translate
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