rosedewar
asked on
Using addEventListener in ActionScript 3
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!
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);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Brilliant. That nailed it. Thank you so much.
Open in new window