Flash CS3 event.target

OK, I'm trying to understand what the event.target function does
Now I have the following structure
I have the following Symbol Movie Clip which is compsed with other Symbols movielclips
Buttonbase "Movieclip" Instance name is "button_mc"
-->Button "Movieclip" Instance name is "btn_mc"
-->Light "Movieclip" Instance name is "light_mc"
the Button and Light overlap each other the Light is on top
-->Reflection "Movieclip" Instance name is "reflex_mc"

Now when I hover on the button_mc the event.target.name gives the the "light_mc"
and I was expecting to see the "button_mc" instead

Can some one give me a little more in depth guide on this issue
LVL 10
ranhellAsked:
Who is Participating?
 
IqAndreasCommented:
"currentTarget" is whatever you added the listener to.

"target" is the childmost-children of children that was clicked.


Let's say you add an event listener to a button. That button has several children on it, such as a text label, a border shape, a little icon, and all sorts of stuff that makes up the design of the button.

If you do "button_mc.addEventListener(MouseEvent.CLICK);"
The currentTarget property will be button_mc.
The target property will be whatever child was clicked, for example, if the mouse was hovering over the border when clicked, the target will be the border, not the button.

In your case, light_mc was the childmost of children that was hovered over, and therefore it became the "target", however, you will likely want to listen to "currentTarget", as that will ALWAYS be your button.
0
 
moagriusCommented:
event.currentTarget gives back the element that has the listener attached.

event.target can be a child of that element
0
 
IqAndreasCommented:
If you want to COMPLETELY IGNORE the mouse events for a particular item (such as if you place a MovieClip as a cursor and don't want it to react to the mouse in any way) you can set it's "mouseEnabled" property.
light_mc.mouseEnabled = false;

Now let's say you want Flash to completely ignore all children on the button and instead of ignoring mouse events, having Flash treat the child items as if they ARE the button, and not a child of the button (this means that the "target" property points to the button and not the subitem when clicked) To do this, set the "mouseChildren" property.
button_mc.mouseChildren = false;


For more information, you can check out the language reference. It's quite dry at times, but it tends to give some pretty precise references. Don't use it as a tutorial, but instead like you would use a Dictionary when learning a new language.

This is the specific page for the DisplayObjectContainer (which has all the mouseEnabled and mouseChildren properties on it)
http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/display/DisplayObjectContainer.html


Do you have any more questions regarding children, targets, and mouse events that I can help you with?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
ranhellAuthor Commented:
Ok, guys, thanks for answering, now I understand what my problem is.

Now, I don't want to abuse here, but just in case any of you already knows how to swap a moviclip with actuion script CS3 I'll would really appreciate it.

0
 
ranhellAuthor Commented:
thanks
0
 
IqAndreasCommented:
What do you man by "swap MovieClips"?

Do you mean swap the order to make one appear on top of the other?
> Then you would need swapChildren(mc1, mc2);
http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/display/DisplayObjectContainer.html#swapChildren%28%29

Or do you mean remove one MovieClip and replace it with another?
> removeChild(old_mc);> addChild(new_mc);

Could you elaborate a little more on your question?
0
 
ranhellAuthor Commented:
Well, i though it was a simple question, but I guess not.
What I meant by swap movieclips, was that lets say I have buttonA and ButtonB on my library
And then I manually put on the stage ButtonA and then either with hove over or an specific frame I decided to swap it whit ButtonB.
How would I do that.
I guess both of your suggestions involves the DisplayContainer class right....?
0
 
IqAndreasCommented:
Yes, you would need to use DisplayObjectContainers, but don't worry about the name too much, because Sprites and MovieClips ARE DisplayObjectContainers since they can hold other items.

But yes, it would actually be quite simple to replace a MovieClip at the same depth as the old one. The neatest way is likely like this:
addChild(new_mc);swapChildren(new_mc, old_mc);removeChild(old_mc);


However, it is also possible to get the depth of the old MovieClip and manually set the depth to that same number on the new MovieClip, but this method is a little neater. ;)


If you throw it up as a new question, you might be able to get some more responses and alternate ways of doing it, but I think I pretty much covered what you need in this post.
0
 
ranhellAuthor Commented:
"but I think I pretty much covered what you need in this post."
--->Yes you did, thanks very much
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.