Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411471 Posts in 69369 Topics- by 58423 Members - Latest Member: antkind

April 23, 2024, 10:30:34 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Flixel: Call to a possibly undefined method...
Pages: [1]
Print
Author Topic: Flixel: Call to a possibly undefined method...  (Read 665 times)
Ingenoire
Level 0
***



View Profile WWW
« on: November 10, 2014, 02:03:41 PM »

I have no idea why I'm struggling with this, but here I go.
I'm trying to call a method from one class in another, but it somehow refuses to comply, spitting out the infamous call to a possibly undefined method.

I'm trying to summon the function theResult() from the PlayState. Calling the inside of theResult() works inside of the update function of HUD, so the content is not the problem...

I've hidden the code that's not related to the problem with //HIDDEN.

Anyone got a clue what's wrong?

Code: ('PlayState')
package gamestate
{
import common.*;
import enemy.*;
import entity.*;
import hud.*;
import item.*;
import org.flixel.*;
import player.*;
import stage.*;

public class PlayState extends FlxState
{
private var hud:HUD;

public function PlayState()
{
}

override public function create():void
{
//HIDDEN
}

public function setLevel(_level:Class):void {

//HIDDEN
//HUD
add(hud = new HUD());
}

override public function update():void {
super.update();

//HIDDEN
if (Globals.level.grpEnemies.countDead() == Globals.level.grpEnemies.length && Globals.level.roomType == 1) {
FlxG.log("Switched room type: 2");
Globals.level.roomType = 2;
hud.theResult();
}
}

//HIDDEN
}
}

Code: ('HUD')
package hud
{
import org.flixel.*;
import org.flixel.plugin.photonstorm.FlxBar;
import org.flixel.plugin.wingeraser.FlxTimerPlus;
import player.Player;
import player.OnHand;
import hud.SystemWindow;

public class HUD extends FlxGroup
{
private var frame:FlxSprite;
private var hp_bar:FlxBar;
private var sp_bar:FlxBar;
private var hp:FlxText;
private var money:FlxText;

public var timer_sec:FlxTimerPlus;
public var timer_min:Number;
private var stage_time:FlxText;

[Embed("../../assets/hud/equipment_empty.png")]
private static var equipment_slot:Class;

[Embed("../../assets/font/Fairfax.ttf", fontFamily="Fairfax", embedAsCFF="false")]
private static var fairfax:String;

private var equip:FlxSprite;
private var map_base:CircleMap;
private var cursor_player:PlayerCursor;
private var results:BattleResults;

public function HUD()
{
super();
//HIDDEN

results = new BattleResults();
add(results);

}

override public function update():void
{
//HIDDEN
}

//HIDDEN

public function theResult():void {
results.showResults();
}

}

}

Any help would be greatly appreciated!
Logged

ThemsAllTook
Administrator
Level 10
******



View Profile WWW
« Reply #1 on: November 10, 2014, 02:14:39 PM »

Are you sure setLevel() has happened before the first call to update()? My guess is that hud is uninitialized when you try to call theResult() on it.
Logged

Ingenoire
Level 0
***



View Profile WWW
« Reply #2 on: November 10, 2014, 02:30:52 PM »

setLevel() is called in the create() function and works normally.

Code: ('PlayState')
override public function create():void
{
Globals.playState = this;
FlxG.mouse.hide();
Globals._player = new Player(0, 0);
Globals._player.setPositionByTile(new FlxPoint(1, 0));
FlxG.camera.follow(Globals._player, FlxCamera.STYLE_LOCKON);
setLevel(ForestLand);
}
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic