Using this code I get these dreaded errors:
Scene 1, Layer ‘Actions’, Frame 61, Line 5 1180: Call to a possibly undefined method Worm.
and
Scene 1, Layer ‘Actions’, Frame 61, Line 6 1180: Call to a possibly undefined method Killer.
I have the feeling I need to make classes and have separate .as files for worm and killer but am not sure if I can solve this problem without this as I am not sure how to make classes(I have very basic as3 understanding and am not trying to be lazy)
Is there something someone can suggest that I 1) learn how to make classes for these and a reference for info on that or 2) I don’t need to and its just something simple I am missing?
[AS]
import flash.display.MovieClip;
import flash.events.Event;
// instantiate Killer and Worm instances from the library
var worm:MovieClip = new Worm();
var killer:MovieClip = new Killer();
// position worm
worm.x = 200;
worm.y = -50;
// not sure where killer is supposed to be
killer.x = stage.stageWidth/2 - killer.width/2;
killer.y = stage.stageHeight/2 - killer.height/2;
// add killer and worm to the displaylist
addChild(worm);
addChild(killer);
var speed:Number = 5;
var movement:Number = 5;
addEventListener(Event.ENTER_FRAME, descent);
function descent(e:Event):void
{
worm.y += speed;
// worm exit test
if ( worm.y >= 635 )
{
removeEventListener(Event.ENTER_FRAME, descent);
}
// mouseX test
if ( mouseX > worm.x + 5 )
{
worm.x += movement;
}
else if (mouseX < worm.x - 5)
{
worm.x -= movement;
}
else
{
worm.x = mouseX;
}
// worm collision test
if ( worm.hitTestObject(killer) )
{
removeChild(worm);
removeEventListener(Event.ENTER_FRAME, descent);
gotoAndPlay(237);
}
}
[/AS]
It is a game where the parachutes(falls down) and the player moves the mouse and the worm avoids hitting the fish(killer) and lands on the island winning the game. I had no problems getting the worm to listen to me and what it says in the code until I placed the hitTest in then I tried this approach of naming them movieclips…before my problem was they were null.
Any help or suggestions would be much appreciated.