Copy link to clipboard
Copied
Hi all,
I'm working in FB4, but I think this is an AS3 question ![]()
I'm dynamically creating a MovieClip instance (It's a flash symbol that inherits from a MovieClip):
var cls:Class=_loaderInfo.applicationDomain.getDefinition("com.company.SymbolName") as Class;
var mySymbol:Object;
try {
mySymbol=new cls;
} catch (error:Error) {
...
}
This works fine, and I can add it to the stage: stage.addChild(obj) and I actually see it.
Now when I click on it, I expect the MouseEvent.target to point to the mySymbol instance. But it doesn't!
MouseEvent.target points to another instance of a MovieClip... I can see that because this expression fails
stage.addEventListener(MouseEvent.MOUSE_DOWN, startDrag);
function startDrag(event:MouseEvent):void {
trace(mySymbol === event.target); // false!
}
when clicking on the mySymbol visual instance, and in FB3 debug mode, I can see different addresses for mySymbo and event.target...
Does anyone have a clue? I need to backtrack the creator of the mySymbol on clicking, I only have the clicked instance,
and from there on I need to find the object that created the mySymbol instance.
Thanks,
Ronaldo
This is definitely AS3 Question. ![]()
AS3 has a mechanism to pass its Events.
Say you have PARENTMC and a CHILDMC inside PARENTMC
Now you click on the CHILDMC the event will be rgistered to PARENTMC if there are any listeners to this event for PARENTMC it will call those.
Then it will be registered with the CHILDMC if you have any listeners to CHILDMC for this event then this will be called.
Solution to this can be:
Copy link to clipboard
Copied
This is definitely AS3 Question. ![]()
AS3 has a mechanism to pass its Events.
Say you have PARENTMC and a CHILDMC inside PARENTMC
Now you click on the CHILDMC the event will be rgistered to PARENTMC if there are any listeners to this event for PARENTMC it will call those.
Then it will be registered with the CHILDMC if you have any listeners to CHILDMC for this event then this will be called.
Solution to this can be:
Copy link to clipboard
Copied
Hi,
Thanks for your reply.
I already found out a MovieClip consists of multiple parts, each of which can be the target of a mouseclick, when (as you point out) mouseChildren = true.
So I was using point 3 to get to the right parent, which worked for me. But 2 is a more elegant solution for my problem.
Thanks for pointing me to the mouseChildren property!
Ronaldo
Copy link to clipboard
Copied
Google event.target vs event.currentTarget:
http://www.google.com/search?hl=en&q=event.target+vs+event.currenttarget
Short answer, always use Event.currentTarget, which will give you the instance the event was registered to. Use Event.target to get the instance that triggered the event, which may be a child of the instance the event was registered to.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more