Trying to change the value of a boolean in another class.
Main class:
package
{
import flash.display.MovieClip;
import flash.events.Event;
import LvlCheck; // I imported the class that has the booleans
public class GameManager extends MovieClip
{
public var lvlCheck:LvlCheck; //declared other class
public function GameManager()
{
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
private function onAddedToStage(event:Event):void
{
lvlCheck = new LvlCheck();
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(event:Event):void
{
if (!_gotJewel)
{
if (_player.hitTestObject(_jewel))
{
_jewel.hideGem();
_gotJewel = true;
trace("got jewel");
}
}
if (_gotJewel)
{
if (_player.hitTestObject(_spawn))
{
_gotJewel = false;
resetLevel();
trace("reset");
lvlCheck.lvl01 = true; //HERE IS WHERE I SET IT TO TRUE
}
}
}
}
I stripped most of the irrelevant code to make it easier to read. Everything in the EnterFrame handler is just so that when the player grabs the jewel and touches exit you "win" and this is where I want it to change the boolean to true.
Here is the other class it is trying to change the boolean in:
package
{
import flash.display.Sprite;
import flash.events.Event;
public class LvlCheck extends Sprite
{
public var lvl01:Boolean;
public function LvlCheck()
{
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
public function onAddedToStage(event:Event):void
{
lvl01 = false;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
public function onEnterFrame(event:Event):void
{
if (lvl01)
{
trace("lvl1 active");
}
}
}
}
I plan to eventually put the level booleans in an array but first I want to figure this out as it is more simple to me (still learning arrays/loops).
Game worked fine before adding in this new code. It works now. But the trace function in the LvlCheck class doesn't fire in it's EnterFrame handler.
What am I missing... Guess I'm still rusty in understanding how classes communicate to one another....