我需要帮助,因为我想创建一个显示分数的游戏结束屏幕。但是,有一个错误阻止我将分数从 theplayclass.as 转移到 thegameoverclass.as。有没有办法将值传递给另一个影片剪辑而不会导致任何错误。
我参考了这个网站的源代码:http ://www.emanueleferonato.com/2008/12/17/designing-the-structure-of-a-flash-game-as3-version/
这是错误
C:\Users\xxx\Downloads\Migrate\test\theplayclass.as,第 54 行,第 41 列 1067:将 playclass 类型的值隐式强制转换为不相关的 main 类型。
主文件
package
{
import flash.display.MovieClip;
import flash.events.Event;
public class main extends MovieClip
{
public var playClass:theplayclass;
public var gameOverClass:thegameoverclass;
public function main()
{
showWin();
}
public function showWin()
{
playClass = new theplayclass(this);
addChild(playClass);
}
public function showGameOver()
{
gameOverClass = new thegameoverclass(this);
addChild(gameOverClass);
removeChild(playClass);
playClass = null;
}
}
}
游戏类.as
package
{
import flash.display.MovieClip;
import flash.events.*;
public class theplayclass extends MovieClip
{
private var mainClass:main;
var gameScore:Number;
var gameOverScore:thegameoverclass;
public function theplayclass(passedClass:main)
{
mainClass = passedClass;
scoreText.text ="0";
gameScore = 0;
win.addEventListener(MouseEvent.CLICK, showwinFunction);
next.addEventListener(MouseEvent.CLICK, showgameoverFunction);
addEventListener(Event.ADDED_TO_STAGE, addToStage);
addEventListener(Event.ENTER_FRAME, changeScore);
}
public function addToStage(e:Event):void
{
this.x = 0;
this.y = 0;
}
private function showwinFunction(e:MouseEvent):void
{
gameScore+=50;
}
private function changeScore(e:Event):void
{
scoreText.text =""+gameScore;
}
public function showgameoverFunction(e:MouseEvent)
{
mainClass.showGameOver();
gameOverScore = new thegameoverclass(this);
gameOverScore.setTextScore(gameScore);
}
}
}
游戏结束类.as
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.*;
public class thegameoverclass extends MovieClip
{
var mainClass:main;
var scorePoints:Number;
public function thegameoverclass(passedClass:main)
{
mainClass = passedClass;
finalScore.text = "test";
}
public function setTextScore(textToSet:Number)
{
finalScore.text = ""+scorePoints;
}
}
}