Skip to main content
Participating Frequently
June 4, 2009
Answered

How to get instanceName/Object from MouseEvent.target

  • June 4, 2009
  • 1 reply
  • 477 views

Hello friends,

See I got three MovieClips

mcPlanet

mcPlanetOuter

mcPlanetInner

They are in the following fashion

mcPlanet

        ----->instance of mcPlanetOuter : PlanetEarthOuter_mc

        ----->instance of  mcPlanetInner : PlanetEarthInner_mc

                            ----->PlanetInner_txt(instance of  dynamic Textfield)

instance of mcPlanet :  PlanetEarth_mc.buttonMode = true

So if I move mcPlanet  both mcPlanetOuter and mcPlanetInner and the PlanetInner_txt (mcPlanetInner) should move propotionately, because all of them is under mcPlanet

I set event Target like this,

PlanetEarth_mc.addEventListener(MouseEvent.MOUSE_DOWN, startMoving);


function startMoving(EventReceived:MouseEvent):void {
    EventReceived.target.startDrag();

}

When  Mouse is down on PlanetEarth_mc, only PlanetEarthOuter_mc starts moving,  leaving  PlanetEarthInner_mc and  PlanetInner_txt in the same existing place.

I want to call the parent of the target i.e. I want to move PlanetEarth_mc.

also,

    EventReceived.target.parent.startDrag();   //Gives Error.

Plz tell me How can I achieve that from received  MouseEvent Object

I hope u understand this. Plz help me. This is my first post.

Thanks

Venkat.

This topic has been closed for replies.
Correct answer Ned Murphy

Try using currentTarget instead of target.

If you trace the target, you'll see it shows a different thing than what currentTarget shows, and changes as you move over the movieclip.  currentTarget captures the object with the event listener attached to it.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
June 4, 2009

Try using currentTarget instead of target.

If you trace the target, you'll see it shows a different thing than what currentTarget shows, and changes as you move over the movieclip.  currentTarget captures the object with the event listener attached to it.

Participating Frequently
June 4, 2009

U rock man,

U know what u did, u solved the problem  of my whole day  in 1 min.

And also saved my many hours of frustrations.

Cool.

Thanks Very much.

Ned Murphy
Legend
June 4, 2009

You're welcome