Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Movieclip instance != created instance ?

Community Beginner ,
Sep 10, 2009 Sep 10, 2009

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

TOPICS
ActionScript
621
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Sep 10, 2009 Sep 10, 2009

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:

  1. Using currentTarget property instead of target.
  2. Set PARENTMC.mouseChildren = false [Note: t
...
Translate
Guest
Sep 10, 2009 Sep 10, 2009

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:

  1. Using currentTarget property instead of target.
  2. Set PARENTMC.mouseChildren = false [Note: this will restrict the event from travelling further deep into this movieclip.]
  3. Use target.parent to get to your MovieClip [Note: Not a prefferred way of doing]
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 10, 2009 Sep 10, 2009

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 10, 2009 Sep 10, 2009
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines