lundi 28 décembre 2015

as3 - How to access child's child?

I dispatched an event for a bullet to spawn on the page. However the bullet should be located in the area where the page's child child should be. There is a Page One Movieclip, which has a child named "player" and the player's child is "gun". So I'm trying to keep the location and rotation of the bullet the same as the player's gun. So I need to access Page One's child's child. The player and the turret are using instance names and not variables.

I tried this code, but the bullet spawns in the page but will not spawn itself on the turret's location. This event is located in the PageOne class.

function fire(e: Event)
    {
        var b: Bullet = new Bullet();
        b.rotation = player.turret.rotation;
        b.x = player.turret.x + player.turret.width * Math.cos(player.turret.rotation / 180 * Math.PI);
        b.y = player.turret.y + player.turret.width * Math.sin(player.turret.rotation / 180 * Math.PI);
        addChild(b);
    }

Aucun commentaire:

Enregistrer un commentaire