Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Using addEventListener in ActionScript 3

Posted on 2009-04-28
3
Medium Priority
?
11,926 Views
Last Modified: 2013-11-11
Hello

I am struggling to make the transition from AS2 to AS3 and I need some help understanding how Flash AS3 handles mouse actions using the addEventListener.

I am authoring a simple Flash presentation which has a movie clip on the stage ('myMainMovieClip') and this contains a second movie clip ('myChildMovieClip').

In frame 1 of the main timeline (on the stage), I have two event listeners detecting MOUSE_OVER and MOUSE_OUT actions. (see code below).

When I test this, if the mouse cursor passes over myChildMovieClip which is inside myMainMovieClip, the parent movie clip then starts looping wildly.

This problem goes away when I change myChildMovieClip to a graphic instance instead of a movie clip instance. So why is this, and is there any way to have a movieclip within a movieclip and so it doesn't affect its parent when the addEventListener is used?

Can someone please explain to me what is going on here and why this happens?

Many thanks!
function mainOver(myevent:MouseEvent):void {
        // Navigate to "Over" label of myMainMovieClip
	myMainMovieClip.gotoAndPlay("Over");
}
 
function mainOut(myevent:MouseEvent):void {
       // Navigate to "Out" label of myMainMovieClip
	myMainMovieClip.gotoAndPlay("Out");
}
 
myMainMovieClip.addEventListener(MouseEvent.MOUSE_OVER, mainOver);
myMainMovieClip.addEventListener(MouseEvent.MOUSE_OUT, mainOut);

Open in new window

0
Comment
Question by:rosedewar
3 Comments
 
LVL 11

Expert Comment

by:Eaddy Barnes
ID: 24255876
try gotoAndStop  and not gotoAndPlay

function mainOver(myevent:MouseEvent):void {
        // Navigate to "Over" label of myMainMovieClip
        myMainMovieClip.gotoAndStop("Over");
}
 
function mainOut(myevent:MouseEvent):void {
       // Navigate to "Out" label of myMainMovieClip
        myMainMovieClip.gotoAndStop("Out");
}
 
myMainMovieClip.addEventListener(MouseEvent.MOUSE_OVER, mainOver);
myMainMovieClip.addEventListener(MouseEvent.MOUSE_OUT, mainOut);

Open in new window

0
 
LVL 5

Accepted Solution

by:
john_hollings earned 2000 total points
ID: 24255880
Hi, I'm not entirely sure why this happens but have you tried using MouseEvent.ROLL_OVER and MouseEvent.ROLL_OUT?
0
 

Author Closing Comment

by:rosedewar
ID: 31575704
Brilliant. That nailed it. Thank you so much.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question