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

TypeError: Error #1009 + ArgumentError: Error #2025

Community Beginner ,
May 19, 2018 May 19, 2018

Copy link to clipboard

Copied

The following is an error i do not know how to fix:

TypeError: Error #1009: Cannot access a property or method of a null object reference.

    at Piximalism_Project_fla::MainTimeline/catchBomb()

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.

    at flash.display::DisplayObjectContainer/removeChild()

    at Piximalism_Project_fla::MainTimeline/catchFruit()

var bombArray:Array = new Array(Bomb);

var bombOnStage:Array = new Array();

var HPleft:int = 3

for (var b:int = 0; b < 10; b++)

{

    var pickBomb = bombArray[int(Math.random() * bombArray.length)];

    var bomb:MovieClip = new pickBomb();

    addChild(bomb);

    bomb.x = Math.random() * stage.stageWidth;

    bomb.y = Math.random() * -500;

    bomb.speed = Math.random() * 5 + 5;

    bombOnStage.push(bomb);

}

stage.addEventListener(Event.ENTER_FRAME,catchBomb);

function catchBomb(evt:Event):void

{

    for (var b:int = bombOnStage.length-1; b > -1; b--)

    {

        var currentBomb:MovieClip = bombOnStage;

        currentBomb.y += currentBomb.speed;

        if (currentBomb.hitTestObject(bowl_mc))

            {

                HPleft--;

                removeChild(currentBomb);

                field3.text = "" + HPleft;

                bombOnStage.splice(b,1);

            }

            if(HPleft == 0)

                {

                    gotoAndStop("GameOver")

                    bowl_mc.alpha=0;

                    field3.text = "" + HPleft;

                }

                else if (HPleft == 1)

                    {

                        field3.text = "" + HPleft;

                    }

                    else if (HPleft == 2)

                        {

                            field3.text = "" + HPleft;

                        }

                        else if (HPleft == 3)

                            {

                                field3.text = "" + HPleft;

                            }

    }

}

TOPICS
ActionScript

Views

439

Translate

Translate

Report

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

Community Expert , May 23, 2018 May 23, 2018

Here it is:

Game 2_jc.zip - Google Drive

The error happens when a bomb is hit, you change the current frame of the main timeline, and because of it some text fields are no longer available even though the code tries to access them.

This situation is quite common.

My fix was to put some verifications like this:

if (field3_txt)

     field3_txt.text = "" + HPleft;

In this way, you can guarantee that your code will not try to access a object that no longer exists.

You can instead extend the keyframe of your

...

Votes

Translate

Translate
Advisor ,
May 19, 2018 May 19, 2018

Copy link to clipboard

Copied

for this kind of code the best is to put all your code in a Main class linked to your stage with inside the constructor

since the ENTER_FRAME is certainly faster than the precedent code.

package{

    import flash.display.MovieClip;

    etc....

    public class Main{

          private  var bombArray:Array = new Array();

          private var bombOnStage:Array = new Array();

          private var HPleft:uint = 3;

          public function Main(){

                  addEventListener(Event.ADDED_TO_STAGE,build);

          }

          private function build():void{

                  bombArray.push(Bomb);  // You must declare Bomb somewhere!!!...

                  for(var b:uint = 0; b < 10; b++)  {

                       var pickBomb = bombArray[int(Math.random() * bombArray.length)]; 

                       var bomb:MovieClip = new pickBomb(); 

                       addChild(bomb); 

                       bomb.x = Math.random() * stage.stageWidth; 

                       bomb.y = Math.random() * -500; 

                       bomb.speed = Math.random() * 5 + 5; 

                       bombOnStage.push(bomb); 

                }

               addEventListener(Event.ENTER_FRAME,catchBomb);

          }

          private function catchBomb):void{

               // code...

          }

    }

Votes

Translate

Translate

Report

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 ,
May 20, 2018 May 20, 2018

Copy link to clipboard

Copied

I would like to refrain from using an external as3 file as i have other Scenes in my fla file which means that if i put the class name on the scene, it will display the game rightaway while displaying my other scenes. So is there any other way?

Votes

Translate

Translate

Report

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 ,
May 19, 2018 May 19, 2018

Copy link to clipboard

Copied

The 1009 error indicates that one of the objects being targeted by your code is out of scope.  This could mean that the object....

 

- is declared but not instantiated

- doesn't have an instance name (or the instance name is mispelled)

- does not exist in the frame where that code is trying to talk to it

- is animated into place but is not assigned instance names in every keyframe for it

- is one of two or more consecutive keyframes of the same objects with no name assigned in the preceding frame(s).

 

If you go into your Publish Settings Flash section and select the option to Permit debugging, your error message should have a line number following the frame number which will help you isolate which object is involved.

For the 2025 error, when you start removing children you need to make sure they exist first, and that you stop checking for their existence after they are removed.  Try adding some traces in your function just before the removeChild line to check to see if the currentBomb exists.  That will also help show you if you are continuing to check for one after you removed it.

Votes

Translate

Translate

Report

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 ,
May 20, 2018 May 20, 2018

Copy link to clipboard

Copied

i am still unable to fix the 1009 error....

As for the 2025 error i added a child and added traces in the function, when i launch my game and it hits the bomb it traced "You hit a bomb" but after the game ends with you winning, it displays the 1009 error. But when you lose it displays 1009 error and 2025 error

Votes

Translate

Translate

Report

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 ,
May 22, 2018 May 22, 2018

Copy link to clipboard

Copied

Did you turn on the the option to permit debugging?  That can help by pointing to the line where the 1009 error erupts.  It will be the first frame:line number indicated in the error message (followed by other lines).  That will help you to focus on where your traces are most likely to shed some light on the problem.

Votes

Translate

Translate

Report

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 ,
May 20, 2018 May 20, 2018

Copy link to clipboard

Copied

Game 2.fla - Google Drive

I've separated my game scene from my main file so that you can see the content in game 2 faster

Votes

Translate

Translate

Report

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 Expert ,
May 23, 2018 May 23, 2018

Copy link to clipboard

Copied

LATEST

Here it is:

Game 2_jc.zip - Google Drive

The error happens when a bomb is hit, you change the current frame of the main timeline, and because of it some text fields are no longer available even though the code tries to access them.

This situation is quite common.

My fix was to put some verifications like this:

if (field3_txt)

     field3_txt.text = "" + HPleft;

In this way, you can guarantee that your code will not try to access a object that no longer exists.

You can instead extend the keyframe of your objects until the win and lose frames and hide them with code.

I hope it helps.

Regards,

JC

Votes

Translate

Translate

Report

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