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

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

Community Beginner ,
May 19, 2018 May 19, 2018

As said in the title, i have an error of #1009 and i do not know how to fix it

the full error is:

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

    at project_fla::MainTimeline/dragandStop()

import flash.events.MouseEvent;

import flash.events.Event;

import flash.display.MovieClip;

stop();

var foodArray:Array = new Array(Apple, Burger, Carrot, Milk, Pizza, Water);

var foodOnStage:Array = new Array();

var foodCollected:int = 0;

var foodLost:int = 0;

for (var i:int = 0; i <50; i++)

{

    var pickFood = foodArray[int(Math.random() * foodArray.length)];

    var food:MovieClip = new pickFood();

    addChild(food);

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

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

    food.speed = Math.random() * 15 + 5;

    foodOnStage.push(food);

}

basket_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragBasket);

function dragBasket(evt:Event):void

{

    basket_mc.startDrag();

}

stage.addEventListener(MouseEvent.MOUSE_UP, dragandStop);

function dragandStop(evt:Event):void

{

    basket_mc.stopDrag();

}

stage.addEventListener(Event.ENTER_FRAME, catchFood);

function catchFood(evt:Event):void

{

    for (var i:int = foodOnStage.length-1; i > -1; i--)

    {

        var currentFood:MovieClip = foodOnStage;

        currentFood.y += currentFood.speed;

      

        if (currentFood.y > stage.stageHeight - currentFood.height)

        {

            currentFood.y = 0 - currentFood.height;

            foodLost++;

            field2_txt.text = "Total Food Lost: " + foodLost;

        }

        if (currentFood.hitTestObject(basket_mc))

        {

            foodCollected++;

            removeChild(currentFood);

            field1_txt.text = "Total Food Collected: " + foodCollected;

            foodOnStage.splice(i,1);

            if (foodCollected >=50)

            {

                basket_mc.gotoAndStop(50);

                gotoAndStop("win")

                field3_txt.text="You Won!";

            }

            else if (foodCollected > 45)

            {

                basket_mc.gotoAndStop(45);

            }

            else if (foodCollected > 40)

            {

                basket_mc.gotoAndStop(40);

            }

            else if (foodCollected > 35)

            {

                basket_mc.gotoAndStop(35);

            }

            else if (foodCollected > 30)

            {

                basket_mc.gotoAndStop(30);

            }

            else if (foodCollected > 25)

            {

                basket_mc.gotoAndStop(25);

            }

            else if (foodCollected > 20)

            {

                basket_mc.gotoAndStop(20);

            }

            else if (foodCollected > 15)

            {

                basket_mc.gotoAndStop(15);

            }

            else if (foodCollected >10)

            {

                basket_mc.gotoAndStop(10);

            }

            else if (foodCollected >5)

            {

                basket_mc.gotoAndStop(5);

            }

        }

    }

}

TOPICS
ActionScript
966
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

Community Expert , May 19, 2018 May 19, 2018

Hi.

When you use gotoAndStop("win"), is your basket_mc still available?

My best guess is that you are changing the current frame of the main timeline and because of it the dragandStop function can't find the basket_mc Movie Clip anymore when you release the mouse.

Translate
Community Expert ,
May 19, 2018 May 19, 2018

Hi.

When you use gotoAndStop("win"), is your basket_mc still available?

My best guess is that you are changing the current frame of the main timeline and because of it the dragandStop function can't find the basket_mc Movie Clip anymore when you release the mouse.

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

Yup it is exactly as u guessed my basket_mc's frame length didnt reach to the ("win") label. Thanks Alot!!

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

Excellent! You're welcome!

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