I recieve the following error..
Type Coercion failed: cannot convert Stinger@d8d43a1 to Array.
In a summary. This is what I am trying to do...
var laser = new StingerLaser();
laser.laserDir = dir1;
laser.wielder.push(this);
laser.x = x + 20;
laser.y = y + 40;
eApi.addGameChild(laser);
where laser.wielder is an Array that gets declared inside of the StingerLaser Class. As of right now, there is only one type of object I am trying to put into the the array. And that is stinger
When trying to add an object that is type Stinger to an Array. here is my code.
package com.objects{
import flash.display.MovieClip
public class StingerLaser extends gameObject {
public var speed:Number = 20;
public var targets:Array;
public var laserDir:Number = -40;
public var wielder:Array; // <-------- Here is the array
public function StingerLaser():void{
stop();
wielder = new Array(); //<---- it gets declared here
targets = new Array();
}
override public function updateObject():void
{
blowUp();
rotation = laserDir;
//blowUp();
var xdir = Math.cos(laserDir * Math.PI/180);
var ydir = Math.sin(laserDir * Math.PI/180);
x += xdir * speed;
y += ydir * speed;
if(y > 800 || y < -30 || x > 800 || x < -30)
{
garbage = true;
}
if(eApi.gameStage[2] != undefined && eApi.gameStage[2] != null)
{
for(var i = 0; i < eApi.gameStage[2].length; i++)
{
if(hitTestObject(eApi.gameStage[2][i]) && eApi.gameStage[2][i] != wielder)
{
//dead();
var w:Boolean = false;
for(var wd = 0; wd < wielder.length; wd++)
{
if(eApi.gameStage[2][i] == wielder[wd])
w = true;
}
if(eApi.gameStage[2][i].dead != true && w != true)
{
eApi.gameStage[2][i].Hit(.01);
dead = true;
}
}
}
}
}//update object
protected function blowUp():void
{
if(dead)
{
play();
if(currentFrame == totalFrames)
{
garbage = true;
}
}
}
}
}
Here is the class that I am trying to put into the array
package com.objects{
import flash.display.MovieClip
public class Stinger extends gameObject {
public var cspeed:Number = 2;
public var attackDelay:Number = 1350;
protected var scale:Number = 1;
public function Stinger():void
{
stop();
lastTime = getTime();
health = 1;
}
public function Hit(dmg:Number = .01):void {
if(health > 0)
health -= dmg;
if(health < 0)
health = 0;
}
public function blowUp():void
{
attackDelay = 100;
scaleX -= .01;
scaleY -= .01;
if((getTime() - lastTime) > attackDelay)
{
var explode = new Explosions();
explode.x = x - (width/2) + (Math.random()* width);
explode.y = y - (height/2) + (Math.random()* height);
explode.scaleX = scaleX;
explode.scaleY = scaleY;
eApi.addGameChild(explode,3);
lastTime = getTime();
}
if(scaleX < .5)
{
rotation = 25;
cspeed = 20;
}
}
override public function Attack(dir:Number = 40):void
{
if((getTime() - lastTime) > attackDelay)
{
var laser = new StingerLaser();
laser.laserDir = dir;
laser.wielder.push(this);
laser.x = x;
laser.y = y;
eApi.addGameChild(laser);
lastTime = getTime();
}
}
public function DoubleShot(dir1:Number = 40, dir2:Number = 120):void
{
if((getTime() - lastTime) > attackDelay)
{
var laser = new StingerLaser();
laser.laserDir = dir1;
laser.wielder.push(this);
laser.x = x + 20;
laser.y = y + 40;
eApi.addGameChild(laser);
var laser2 = new StingerLaser();
laser2.laserDir = dir2;
laser2.wielder.push(this);
laser2.x = x + -20;
laser2.y = y + 40;
eApi.addGameChild(laser2);
lastTime = getTime();
laser.wielder = this;
}
}
override public function updateObject():void
{
eApi.setChildIndex(this, (eApi.numChildren - 5));
if(!dead)
{
DoubleShot(70,110);
}
y += cspeed;
if(y > 800 || y < -45)
garbage = true;
if(health <= 0)
{
dead = true;
blowUp();
}
}
}
}
If no one can figure this issue out, atleast I would like to know how loose is an Array in actionscript? Can it take all types of classes or just classes that are of the same parent class or what?. thanks!