Copy link to clipboard
Copied
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);
}
}
}
}
1 Correct answer
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Yup it is exactly as u guessed my basket_mc's frame length didnt reach to the ("win") label. Thanks Alot!!
Copy link to clipboard
Copied
Excellent! You're welcome!

