Action Script 3 MovieClip MouseEvent CLICK Problem

Hi, All Thank you Guys for Supporting my articles. Today i came across a very strange behaviour of flash action script 3 click MouseEvent.

I had a custom class lets say

Public class CustomMovieClip extends MovieClip {
public function CustomMovieClip()
{
     addChild(new DisplayObject()); //Suppose its name is instance123
}
}

Now after that if i add a reference of this class on Lets suppose stage

var mc = stage.addChild(new CustomMovieClip());
mc.addEventListener(MouseEvent.Click,clicker);
trace(mc.name); 

//Suppose its name assigned is instance124
function clicker(event:MouseEvent)
{
trace(evt.target.name); //Here it will out put instance123,
                            //instead of instance124
}

You see i have applied event handler on the object of CustomMovieClip but its fired for the child. Here if i need to Get the state of the CustomMovieClip object i need to change the following

function clicker(event:MouseEvent)
{
    trace(evt.target.parent.name); //Here it will out put instance124, 
                                   //now its the right out put
}

if you have found this posting help full and if you have further explanation to why this happens Kindly share it with all here.

Do write comments, this will help me motivated to right more and more articles on Action script 3.

Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically to your feed reader.

Comments

Hi. As i understood, you have to use evt.curentTarget instead of evt.target.

Max.

[Reply]

Actually, you can use:

instance123.mouseChildren = false;

and avoid the confusing instance124.parent.etc. This is better because if you will add children to instance124, THEY will come up as the Event Target. It actually isn’t strange, it’s normal. Flash is telling you what item was clicked. If you click on the stage, would you rather get “stage” or the item you clicked on? Flash keeps extending this principle.

Cheers,
M

[Reply]

Leave a comment

(required)

(required)