1
votes

having some trouble with hitTestObject and now Flash is telling me it can't convert my ship to a display object.. my problem is the ship class extends Sprite to begin with so I don't know what's going on:

Compile error shows this:

TypeError: Error #1034: Type Coercion failed: cannot convert Ship$ to flash.display.DisplayObject.
at Control/controlgame()

Control / controlgame() is this:

function controlgame(e:Event) {
        for (var i = 0; i < wprojectiles.length; i ++) {
            if (wprojectiles[i].x < -200 || wprojectiles[i].x > 750 || wprojectiles[i].y < -200 || wprojectiles[i].y > 600) {
                parent.removeChild(wprojectiles[i]);
                wprojectiles.splice(i,1);
            }
            if (wprojectiles[i].hitTestObject(Ship)) {
                parent.removeChild(wprojectiles[i]);
                wprojectiles.splice(i,1);
            }
        }
    }

Using the debugger, I get this error:

TypeError: Error #1034: Type Coercion failed: cannot convert Ship$ to flash.display.DisplayObject.
at Control/controlgame()[C:\Users\Harry\Desktop\Flash Games\Games\Dodge\Control.as:29]

Line 29, seen in the above snippet, is this:

if (wprojectiles[i].hitTestObject(Ship)) {

Tearing my hair out here, tried everything I could think of and I get this error every single time, no matter what I do! Help would be so badly appreciated!

Thanks in advance.

e: if it bears relevance, this is my document class file

1

1 Answers

1
votes

Where did you declare Ship? It looks like you're using a Class for your test instead of an instance... do you have something like Ship = new ShipClass() somewhere?