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

Finding the target of a MouseEvent?

Community Beginner ,
Jul 02, 2010 Jul 02, 2010

Copy link to clipboard

Copied

I have an object (a Loader) that you can click on, resulting in a MouseEvent. Clicking on the Loader moves it, which I do by modifying e.currentTarget.x in the MouseEvent function, a la:

private function onClick(e:MouseEvent):void {

     e.currentTarget.x = 0 - (e.currentTarget.width/2);

}


The problem is, I also want to change the ChildIndex of the target. I tried this:


private function onClick(e:MouseEvent):void {

     e.currentTarget.x = 0 - (e.currentTarget.width/2);

     canvas.setChildIndex(e.currentTarget, 10);

}

But that results in a compile error: "Error Implicit coercion of a value with static type Object to a possibly unrelated type flash.display:DisplayObject. at line 85 in Rotation.as"

I've noticed that sometimes I need to refer to the target as e.currentTarget.loader, but I have no idea why (and would love to have that explained to me, as it seems kind of random), so I tried that (canvas.setChildIndex(e.currentTarget.loader, 10);), but I get an error when I run it: "ReferenceError: Error #1069: Property loader not found on flash.display.Loader and there is no default value. at Rotation/onClick()".

What's the proper way for me to get the target so I can apply setChildIndex?
TOPICS
ActionScript

Views

825

Translate

Translate

Report

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
Guest
Jul 02, 2010 Jul 02, 2010

Copy link to clipboard

Copied

Try casting the object as a DisplayObject.

canvas.setChildIndex( DisplayObject(e.currentTarget), 10);

Votes

Translate

Translate

Report

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 ,
Jul 02, 2010 Jul 02, 2010

Copy link to clipboard

Copied

LATEST

That worked great, thanks.

Votes

Translate

Translate

Report

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