How do I get the child of a unique parent in ActionScript?
Posted
by
Koen
on Game Development
See other posts from Game Development
or by Koen
Published on 2013-03-09T10:47:09Z
Indexed on
2013/11/04
22:17 UTC
Read the original article
Hit count: 321
actionscript-3
My question is about targeting a child with a unique parent. For example. Let's say I have a box people can move called box_mc
and 3 platforms it can jump on called:
- Platform_1
- Platform_2
- Platform_3
All of these platforms have a child element called hit.
- Platform_1
- Hit
- Platform_2
- Hit
- Platform_3
- Hit
I use an array and a for each
statement to detect if box_mc
hits one of the platforms childs.
var obj_arr:Array = [Platform_1, Platform_2, Platform_3];
for each(obj in obj_arr){
if(box_mc.hitTestObject(obj.hit)){
trace(obj + " " + obj.hit);
box_mc.y = obj.hit.y - box_mc.height;
}
}
obj seems to output the unique parent it is hitting but obj.hit ouputs hit, so my theory is that it is applying the change of y to all the childs called hit in the stage. Would it be possible to only detect the child of that specific parent?
© Game Development or respective owner