我要傳送的變量從GameScreen.as到GameOverScreen.as得分。傳遞變量從類類和存儲變量的ActionScript 3.0
從GameOverScreen.as方法被稱爲getScore(評分:號碼),不從GameOverScreen.as構造更新finalScore。
是否有保證finalScore具有相同的值scorePoints從GameScreen.as的方式嗎? (PS。我試着找到了答案,但有沒有用)
下面的代碼:
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);
}
}
}
它無法更新finalScore它給NAN因爲我把ScoreText.text在GameOverScreen的影片剪輯。有沒有辦法讓它改變分數?我假設將setScore(finalScore)放在構造函數中,但它有錯誤。 – Minelava
你可以添加主類的代碼嗎?我不知道我是否按照你的評論發生了什麼。 –
如果我可以通過電子郵件或收件箱向您發送代碼和fla,它會更好嗎? – Minelava