さて、私はモバイルフラッシュゲームを作成しようとしています(私は主にアニメーター、ストーリーテラーです)、私はプレーヤー名の入力テキストに問題があります。私はしばしばこのサイトの役に立つヒントを読んで、私はいくつかの助けを得るためにサインアップしました。データをロードして保存するコードはsaveDataObjectですが、私が知る限り、入力テキストはパッケージコードと共に使用する必要があります。関数varに変換しようとしましたが、これらのエラーが発生します。私は、パッケージのクラスコードを使用する方法が不明で、私が読んだことはすべて混乱しています。私はチュートリアルやフォーラムでコードについて知っているすべてのことについてかなり教えているので、理解できる方法で説明されていなければ、私はそれをすることはできません...text.flashの型の値の暗黙の強制:無関係のIntへのTextField
コードのセクションはif私は(エラーラインが分離)明確ではありませんでした:
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
-
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;
}
-
playerName = txtPlayer;
-
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
}
さて、エラーの原因となった正確な2行をズームインしただけで、この後に質問を編集して明確にします。ありがとうございましたが、今、私には2つの質問があります。 playerNameはスコア保持コードの修正コードから作成されたので、数字のセットとは意味があります。 playerNameを子出力txtPlayerの表示値として保存できるようにするコードのバージョンは何ですか? saveDataObject.data.characterNameをplayerNameに代入するのは完全にはわかりません。 –
Ok、** **第1のもの**私は変数の名前を変更することから始めます。なぜなら、これは現在非常に混乱しているからです。私が 'playerName'を見ると、それは... um ... Player Name?だから、もしそれがスコアであると思われるなら、それを 'playerScore'と命名することをお勧めします。そして今、それが何であるか、なぜそれがIntであるかは明らかです。 ** 2番目の**削除 'playerName = txtPlayer; '。私はそこで何がやっているのかは分かりませんが、とにかく 'loadData1()'関数で設定しましたか? – 3vilguy
'playerName'はPlayer nameを意味しますが、スコアコードを貼り付けてコピーし、名前コードに変更しようとしました。私は 'playerName = txtPlayer;' to 'loadData1()'名前の関数としてPlayerの名前を設定できる必要があります。申し訳ありませんが、私は他の人の投稿を読んでいるのですが、私が必要なものを見つけることができませんでした... –