Be a Supporter!

Undefined Method Error

  • 260 Views
  • 2 Replies
New Topic Respond to this Topic
jujaswe
jujaswe
  • Member since: May. 5, 2012
  • Offline.
Forum Stats
Member
Level 04
Blank Slate
Undefined Method Error 2012-05-08 08:26:25 Reply

So basically, when I test or preview the flash game it says "Error 1180: Call to a possibly undefined method afireballArray". I checked my codes and I made sure that the variable was properly defined. Can someone tell me what's wrong here:

public class gametest02 extends MovieClip
{
public var man:MovieClip;
public var ground:MovieClip;

private var leftIsDown:Boolean;
private var rightIsDown:Boolean;
private var upIsDown:Boolean;
private var downIsDown:Boolean;

private var afireballArray:Array;

public function gametest02()
{
//trace("Game Loaded")
afireballArray = new Array();
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUp);

stage.addEventListener(Event.ENTER_FRAME, gameLoop);
}

private function gameLoop(e:Event):void
{
playerControl();
clampPlayer();
fireballout();
}

private function fireballout():void
{
for (var i:int = 0; i <a fireballArray.length; i++)
{
var currentfireball:fireball = afireballArray(i);

if (currentfireball.x > stage.stageWidth)
{
afireballArray.splice(i, 1);

currentfireball.destroyfireball();
}
}
}

SantoNinoDeCebu
SantoNinoDeCebu
  • Member since: Jul. 20, 2002
  • Offline.
Forum Stats
Supporter
Level 32
Programmer
Response to Undefined Method Error 2012-05-08 08:43:56 Reply

To access elements in an array you use the square brackets

var currentfireball:fireball = afireballArray[i];

Because you used round brackets it is looking for the method 'afireballArray()' which doesn't exist!

jujaswe
jujaswe
  • Member since: May. 5, 2012
  • Offline.
Forum Stats
Member
Level 04
Blank Slate
Response to Undefined Method Error 2012-05-08 08:55:42 Reply

At 5/8/12 08:43 AM, SantoNinoDeCebu wrote: To access elements in an array you use the square brackets

var currentfireball:fireball = afireballArray[i];

Because you used round brackets it is looking for the method 'afireballArray()' which doesn't exist!

Oh okay. Now I know. Thank you! That actually did the trick.