0
votes

I need help with something with Actionscript for school. It's a simple catching game. It keeps saying that my displayed object must be a caller of the child which it should be and it kinda works but I'm not sure how to fix the problem where my bunny object falls through my point character and gives me an error when it collides with the point character and when it hits the floor when it's not caught. The child should exist but I guess it doesn't. I don't know what to do. The commented stuff was stuff I tested on another file and transferred it over to see what it would do.

//Block = Asuka
//Ball = Bunny
//Ballz = Bunz
//Bunny is linked in library
import flash.events.Event;

var intervalBunny = setInterval(addBunny, 1000);

var bunz: Array = [];

function addBunny() {
    var bunny: Bunny = new Bunny();
    bunny.x = Math.ceil(Math.random() * 500);
    bunny.y = -50;
    addChild(bunny);
    bunz.push(bunny);
    bunny.addEventListener(Event.ENTER_FRAME, dropBunny);
}

function dropBunny(e: Event) {
    var b: Bunny = Bunny(e.target);
    b.y += 10;
    if (b.y > 400) {
        eliminatebunz(b);
    }
}

stage.addEventListener(Event.ENTER_FRAME, moveAsuka);

function moveAsuka(e: Event) {
    Asuka.x = mouseX;
    for (var i: int = 0; i < bunz.length; i++) {
        trace(i);
        if (Asuka.hitTestObject(bunz[i])) {
            eliminatebunz(bunz[i]);
            //points
        }
    }
}

function eliminatebunz(p) {

    p.removeEventListener(Event.ENTER_FRAME, dropBunny);
    removeChild(p);
}

Here's the code Any help on how to fix it would be GREATLY appreciated, especially since I am not a big coder and I'm more of an artist/illustrator

1
The problem is going to be in the removeChild() line. Somehow you're removing the bunny twice. It looks likely that somehow your moveAsuka is detecting a hit after dropBunny calls eliminateBunz.Amy Blankenship
What would I do to make it so that it doesn't do that? Do I have like a parent.Removechild or something towards the end? if you want a visual of what it going on when i play the game, I have a link twitter.com/RyuGoomba/status/726095888402268160Ryu Goomba

1 Answers

0
votes

Just do this:

function eliminatebunz(p) 
{
    if(p)
    {
        p.removeEventListener(Event.ENTER_FRAME, dropBunny);
        if(p.parent)
        {
            removeChild(p);
        }
    }        
}