【发布时间】:2016-04-27 12:17:10
【问题描述】:
好的,所以我正在尝试创建一个移动 Flash 游戏(我主要是一名动画师,一个讲故事的人),但我在输入玩家姓名的文本时遇到了问题。我经常在这个网站上阅读有用的提示,所以我注册以获得一些帮助。我用来加载和保存数据的代码是 saveDataObject,但据我所知,输入文本必须与包代码一起使用。我试图将其转换为函数 var,但随后出现这些错误。我不确定如何使用 Package 类代码,而且我读过的所有内容都令人困惑。通过教程和论坛,我几乎是自学了所有关于代码的知识,所以如果没有以我能理解的方式解释,我将无法做到......
如果我不清楚,这是代码部分(错误行分开):
var playerName:int;
init(); // this line goes directly beneath the variables
function f_1(init):void
{ // call once to set everything up
saveDataObject = SharedObject.getLocal("DataBattle/character/name"); // give the save data a location
-
playerName = txtPlayer;
-
function addName(e:TouchEvent):void
{
var myTextBox1:TextField = new TextField();
var txtPlayer:TextField = new TextField();
var myText:String = "Cyan";
function CaptureUserInput()
{
captureText();
}
function captureText():void
{
myTextBox1.type = TextFieldType.INPUT;
myTextBox1.background = true;
addChild(myTextBox1);
myTextBox1.text = myText;
myTextBox1.addEventListener(TextEvent.TEXT_INPUT, textInputCapture);
}
function textInputCapture(event:TextEvent):void
{
var str:String = myTextBox1.text;
createOutputBox(str);
}
function createOutputBox(str:String):void
{
txtPlayer.background = false;
txtPlayer.x = 200;
addChild(txtPlayer);
txtPlayer.text = str;
}
-
if(saveDataObject.data.characterName = playerName == null)
-
{ // checks if there is save data
trace("No Player data yet."); // if there isn't any data on the computer...
saveDataObject.data.characterName = playerName; // ...set the savedScore to 0
}
else
{
trace("Player data found."); // if we did find data...
loadData1(); // ...load the data
}
function loadData1():void
{
playerName = saveDataObject.data.characterName; // set the current score to the saved score
trace("Data Loaded!");
}
}
}
function saveData(e:TouchEvent):void
{
saveDataObject.data.characterName = playerName; // set the saved score to the current score
trace("Data Saved!");
saveDataObject.flush(); // immediately save to the local drive
trace(saveDataObject.size); // this will show the size of the save file, in bytes
}
【问题讨论】:
标签: actionscript-3 flash textbox