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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

moagriusCommented:
event.currentTarget gives back the element that has the listener attached.

event.target can be a child of that element
0
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.