Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Error #1010: A term is undefined and has no properties. when it is not even on the stage

New Here ,
Aug 19, 2013 Aug 19, 2013

This is an error that i cant even explain to myself why does it trigger, because it doesnt trigger every time - only when i shoot like the 1st or last ship of the Array and it somehow changes and it doesnt splice itself or something like that.

So i have a doShips Function:

function doShips() {

          for (var i:int = shipArray.length - 1; i >= 0; i--) {

                    shipArray.moveDown() //what the code in the Ship and Ship2 class does -> only: this.y += 3

                    for (var bcount= _bulletsArray.length-1; bcount >= 0; bcount--) {

                              //if the bullet is touching the ship

                                        if (shipArray.hitTestObject(_bulletsArray[bcount])) {

                                        //if we get here it means there`s is a collision

                                                  removeChild(_bulletsArray[bcount]);

                                        _bulletsArray.splice(bcount,1);

                                        removeChild(shipArray);

                                        shipArray.splice(i,1);

                              }

                    }

          }

}

When i debug the FLA the error comes from

at ArrayOfShips_newG_withTurret_fla::MainTimeline/doShips()[ArrayOfShips_newG_withTurret_fla.MainTimeline::frame1:100]

line 100 is

if (shipArray.hitTestObject(_bulletsArray[bcount])) {

before that there is a Player on the stage that shoots bullets

//handling the bullets

function doBullets(){

          //make a for loop to iterate all  the _bulletsArray on the screen

          for (var bcount:int = _bulletsArray.length-1; bcount>=0; bcount--) {

                    //make the bullets move Up

                    _bulletsArray[bcount].y -=20;

                    //if the bullet is beyond the screen remove from the stage and the Array

                    if(_bulletsArray[bcount].y < 0) {

                              removeChild(_bulletsArray[bcount])

                              _bulletsArray.splice(bcount,1);

                    }

          }

}

also a function to move the player in the X coordinate.

and also a function that positions the ships,but they are not important because i dont think they have anything to do with the error.

I can show all the code of the FLA if that is going to help somehow to solve this.

TOPICS
ActionScript
902
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Aug 19, 2013 Aug 19, 2013

Try to use index loops as little as possible. Use for...each:

a. they are faster

b. they do not depend/break on removing elements from arrays in the middle of iterations.

Try this code:

function doShips():void

{

          for each(var ship:MovieClip in shipArray)

          {

                    Object(ship).moveDown() ;

                    for each(var bullet:MovieClip in _bulletsArray)

                    {

                              //if the bullet is touching the ship

                              if

...
Translate
Community Beginner ,
Aug 19, 2013 Aug 19, 2013

you are splicing _bulletsArray, but are still looping through it.  maybe use a while?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 19, 2013 Aug 19, 2013

well if i do it with

while (shipArray.hitTestObject(_bulletsArray[bcount])) {

now it gives me

TypeError: Error #2007: Parameter hitTestObject must be non-null.

at the same line

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 19, 2013 Aug 19, 2013

do this: 

trace("bcount: " + bcount);

trace("_bulletsArray length: " + _bulletsArray.length);  

you'll see

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 19, 2013 Aug 19, 2013

Well that is strange.

when i dont shoot it gives me

_bulletsArray length: 0

bcount: 0

_bulletsArray length: 0

bcount: 0

and when i shoot

bcount: 0

_bulletsArray length: 1

bcount: 0

_bulletsArray length: 1

... bcount doesnt change ,so does the problem come from me checking if  shipArray is hitting a _bulletsArray[WITH always a 0 property/number/element].But why when i give it to be

for (var bcount:int = _bulletsArray.length-1; bcount >= 0; bcount--) {

or im totally missing the obvious.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 19, 2013 Aug 19, 2013
LATEST

Try to use index loops as little as possible. Use for...each:

a. they are faster

b. they do not depend/break on removing elements from arrays in the middle of iterations.

Try this code:

function doShips():void

{

          for each(var ship:MovieClip in shipArray)

          {

                    Object(ship).moveDown() ;

                    for each(var bullet:MovieClip in _bulletsArray)

                    {

                              //if the bullet is touching the ship

                              if (ship.hitTestObject(bullet))

                              {

                                        //if we get here it means there's is a collision

                                        removeChild(bullet);

                                        _bulletsArray.splice(_bulletsArray.indexOf(bullet), 1);

                                        removeChild(ship);

                                        shipArray.splice(shipArray.indexOf(ship), 1);

                              }

                    }

          }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines