Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 576239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:01:34+00:00 2026-05-13T14:01:34+00:00

I recieve the following error.. Type Coercion failed: cannot convert Stinger@d8d43a1 to Array. In

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:01:35+00:00Added an answer on May 13, 2026 at 2:01 pm

    Array’s are very open, you can push anything you want into them. Here is the line of code cause your troubles though:

    laser.wielder = this
    

    It’s in the class “Stinger”, method “DoubleShot”

    Goodluck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 394k
  • Answers 394k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Neither. You should have methods that do things. If one… May 15, 2026 at 2:28 am
  • Editorial Team
    Editorial Team added an answer SELECT count(*) FROM ( SELECT records FROM table WHERE status… May 15, 2026 at 2:28 am
  • Editorial Team
    Editorial Team added an answer Solr can only sort facets in lexicographical order or by… May 15, 2026 at 2:28 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.