I want to transfer the variables score from GameScreen.as to GameOverScreen.as.
The method from GameOverScreen.as is called getScore(score:Number), that doesn't update the finalScore from the constructor of GameOverScreen.as.
Is there the way to ensure that the finalScore has the same value as the scorePoints from the GameScreen.as? (P.S I tried finding the answer but there's no avail.)
Here's the code:
GameScreen.as
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.net.SharedObject;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.text.*;
/**
* ...
* @author xxxx
*/
public class GameScreen extends MovieClip
{
private var mainClass:main;
private var enemy:Enemy;
private var timer:Timer;
public var scorePoints:Number;
public var gameOverScreen:GameOverScreen;
private var debugValue:Number;
public function GameScreen(passedClass:main)
{
mainClass = passedClass;
gameOverScreen = new GameOverScreen();
enemy = new Enemy();
addChild(enemy);
debugValue = 1;
scorePoints = 0;
addEventListener(Event.ADDED_TO_STAGE, onAdd);
ClickToWinButton.addEventListener(MouseEvent.CLICK, clickToWin);
}
private function clickToWin(e:MouseEvent):void
{
scorePoints += 50;
}
private function onAdd(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, onAdd);
init();
}
private function init():void
{
addEventListener(Event.ENTER_FRAME, gameScreenProgress);
}
public function gameScreenProgress(e:Event):void
{
ScoreText.text = "Score: " + scorePoints;
if (enemy.hitTestPoint(mouseX, mouseY, true))
{
mainClass.showGameOver();
gameOverScreen.getScore(scorePoints);
enemy.removeEnemy();
}
}
}
}
GameOverScreen.as
package
{
import flash.events.Event;
import flash.display.MovieClip;
import flash.net.SharedObject;
import flash.text.*;
/**
* ...
* @author xxxx
*/
public class GameOverScreen extends MovieClip
{
private var mainClass:main;
private var gameScreen:GameScreen;
public var finalScore:Number;
public function GameOverScreen()
{
ScoreText.text = "" + finalScore;
}
public function getScore(score:Number)
{
finalScore = score;
trace(finalScore);
}
}
}