Actionscript 3: setChildIndex
- Started
- Last post
- 9 Responses
- CyBrain0
This code may be easier to follow.
http://pastebin.com/m366af2d8
- Autokern0
What is happening basically is:
the event.target gives you a generic object while to use the setChildIndex you need to use a display object.
So, it's about recasting the event.target, that you know to be a display object as one.
- CyBrain0
Once I put
import flash.display.DisplayObject;
at the top of my class, that worked. Thanks. I thought MovieClips were considered DisplayObjects.
- CyBrain0
I think Actionscript 3 is racist. There's a lot of profiling going on.
- Autokern0
They are, but again, event.target returns a generic object
so whatever you do inside a event handling function using event.target
flash considers it as a generic object, throwing a coercion error.
You have to cast the event target to his proper type to work with it properly.
- maximillion_0
try event.currentTarget
- dparra0
try this, thos should work:
this.setChildIndex(e.target as DisplayObject, this.numChildren - 1);
- era4O40
yeah. use e.currentTarget
or cast it: DisplayObject(e.target).You don't need a Display Object, though. SetChildIndex takes any Sprite.