This error keeps appearing:
“1067 implicit coercion of a value of type Array to an unrelated type flash.display.DisplayObject”
When I added code to test for hits between the array “ships” and the movieclip “city1”
the error is originating from my document class line 128:
if (city1.hitTestObject(ships))
any help will be greatly appreciated thanks in advance
code:
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.ui.Mouse;
public class Level extends MovieClip
{
var ships:Array;
var bullets:Array;
public var avatar:Avatar;
private var score:Number;
public var cash:Number;
public var city1:City1;
var health:int;
public function Level()
{
health:10;
avatar = new Avatar();
addChild( avatar );
avatar.x = mouseX;
avatar.y = mouseY;
score = 0;
cash = 0;
//addEventListener(Event.ENTER_FRAME, loop);
ships = new Array ;
bullets = new Array ;
addEventListener(Event.ENTER_FRAME, update);
}
function update(e:Event)
{
avatar.x = mouseX;
avatar.y = mouseY;
Mouse.hide();
output.text = "Score: " + score;
output2.text = "Cash: $ " + cash;
if (numChildren<10)
{
var s = new Ship();
addChild(s);
s.x = Math.random() * stage.stageWidth;
s.y = -120;
//s.rotation = Math.random() * 360;
ships.push(s);
}
for (var b = ships.length - 1; b >= 0; b--)
{
ships**.update();
if (ships**.x < 0 || ships**.x > 500 || ships**.y > 500)
{
this.removeChild(ships**);
ships.splice(b, 1);
}
for (var i = bullets.length - 1; i >= 0; i--)
{
bullets*.update();
if (bullets*.parent == null)
{
bullets.splice(i, 1);
i--;
}
}
for (var count = 0; count<ships.length; count++)
{
ships[count].update();
for (i=0; i<bullets.length; i++)
{
if (ships[count].hitTestObject(bullets*))
{
if (ships[count].x < -50 || ships[count].x > 550 || ships[count].y > 700)
{if (ships!=null)
{
if (city1.hitTestObject(ships))
{
trace("hit");
removeChild(ships[count]);
ships.splice(count, 1);
}
}
}
removeChild(bullets*);
bullets.splice(i,1);
removeChild(ships[count]);
ships.splice(count, 1);
//trace(score);
score += 10;//*level;
//trace(score);
cash += 5;//*level;
//if (ships[count].hitTestObject(turret))
//{
//
//
//removeChild(ships[count]);
//ships.splice(count, 1);
//
//
//}
}
}
}
}
}
}
}