Remove background and create a new one
Hi,
I'm making an AS3 game, using the ALAPCA Engine source.
I want to change the background of the scene when the timer is complete.
Normaly, you must click on the exit arrow in order to change the background.
The code is defined in the Background.as and it is like that :
private function leaveRoom(e:MouseEvent):void{
player = Engine.player;
if (Engine.playerControl){
stageRef.dispatchEvent(new Event("itemClicked"));
var thisExit = e.currentTarget;
//targetBuffer = player.returnTargetBuffer();
var underscore = thisExit.name.search("_");
var nextRoom:String = thisExit.name.substring(underscore + 1);
Engine.newBack = nextRoom;
exitPoint = "startPoint_"+nextRoom;
exitLoc[0] = currentBack[exitPoint].x;
exitLoc[1] = currentBack[exitPoint].y;
player.addEventListener("reachedPoint", reachedExit, false, 0, true);
// Make sure the player isn't already at the exit point
if (checkForExit()){
player.dispatchEvent(new Event("reachedPoint"));
} else {
player.startWalking(exitLoc[0], exitLoc[1]);
}
}
}
private function reachedExit(e:Event):void{
if (checkForExit()){
Engine.lastLocation = currentBack.name;
stageRef.dispatchEvent(new Event("changeBackground"));
}
I've made in my puzzle.as class (where all the puzzles are) that :
public function shoot(e:MouseEvent):void{
var cocoUn;
for (var i in Engine.usableItems){ // Blurgh
if (Engine.usableItems.displayName == "COCOUN")
cocoUn = Engine.usableItems;
}
cocoUn.gotoAndStop("fall");
timeCoco.start();
timeCoco.addEventListener(TimerEvent.TIMER_COMPLETE, backToJardin);
}
So when it’s finished I want to call a function name “backToJardin” that make the player return to the previous background (named "jardin"):
I've put this :
public function backToJardin(e:Event):void{
Engine.newBack = “jardin”;
stageRef.dispatchEvent(new Event(“changeBackground”));
But it is not working... Here the error :
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.laserdragonuniversity.alpaca::Engine/createBackground()
at com.laserdragonuniversity.alpaca::Engine/changeBackground()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.display::Stage/dispatchEvent()
at com.laserdragonuniversity.alpaca::Puzzle/backToJardin()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.utils::Timer/tick()
Anyone know what could be the problem ?
Here is my puzzle.as and my background.as files if it's necessary.
Thank you for your help,
Stephan