Bob T.
Bob T.

Reputation: 261

HaxeFlixel - issue with passing FlxTypedGroup into another FlxState

After passing FlxTypedGroup into new FlxState im getting this error message from new state :

Invalid field access : length

my code :

in GameState class after certain action:

FlxG.switchState(new EvaluationState(ingredients));

please note that ingredients is FlxTypedGroup<Ingredient> and its not empty.

in EvaluationState :

var ingredients:FlxTypedGroup<Ingredient>;
public function new(i:FlxTypedGroup<Ingredient>) 
{
    super();
    ingredients = i;
}

override public function create():Void 
{
    super.create();

    for (ing in ingredients)
    {
        trace(ing.active);
    }   
}

Also im getting null in create() function after calling ingredients.members.

Does anyone know how to pass FlxTypedGroup into new FlxState without destroying it ?

Upvotes: 0

Views: 512

Answers (1)

TiagoLing
TiagoLing

Reputation: 131

It seems that your group is being destroyed in another state when the switch occurs.

How is the previous state in which "ingredients" is created? If the group is added to this last state the most likely cause is that when switching it calls "destroy()" on ingredients.

Try to remove it from the state before passing is as parameter to EvaluationState to see if this solves your problem.

currentState.remove(ingredients); //This should prevent a null members
FlxG.switchState(new EvaluationState(ingredients));

Upvotes: 2

Related Questions