2016-04-27 5 views
0

さて、私はモバイルフラッシュゲームを作成しようとしています(私は主にアニメーター、ストーリーテラーです)、私はプレーヤー名の入力テキストに問題があります。私はしばしばこのサイトの役に立つヒントを読んで、私はいくつかの助けを得るためにサインアップしました。データをロードして保存するコードは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 
} 

答えて

0

このエラーのいくつかの詳細を持っていいだろう。どのラインが実際にこのエラーを投げているかのように。

しかし、それがなくてもすぐに奇妙に見えるものはほとんどありません。

var playerName:int; 
// And few lines below 
playerName = txtPlayer; 
// Few more lines below 
var txtPlayer:TextField = new TextField(); 

あなたがplayerNameを宣言しているようなので、あなたが数値を格納するintとして見えるが、その後txtPlayerは、TextFieldです。だからplayerName = txtPlayer;あなたはInt値としてTextFieldを格納しようとしていますが、これはうまくいきません。私はこの部分がコンパイルされているかさえわからないO :

私も

if(saveDataObject.data.characterName = playerName == null) 

を見ることができ、それはようなものです。 playerName == nullチェックを行いたい(true/falseを返す)し、それをsaveDataObject.data.characterNameに代入しますか?

+0

さて、エラーの原因となった正確な2行をズームインしただけで、この後に質問を編集して明確にします。ありがとうございましたが、今、私には2つの質問があります。 playerNameはスコア保持コードの修正コードから作成されたので、数字のセットとは意味があります。 playerNameを子出力txtPlayerの表示値として保存できるようにするコードのバージョンは何ですか? saveDataObject.data.characterNameをplayerNameに代入するのは完全にはわかりません。 –

+0

Ok、** **第1のもの**私は変数の名前を変更することから始めます。なぜなら、これは現在非常に混乱しているからです。私が 'playerName'を見ると、それは... um ... Player Name?だから、もしそれがスコアであると思われるなら、それを 'playerScore'と命名することをお勧めします。そして今、それが何であるか、なぜそれがIntであるかは明らかです。 ** 2番目の**削除 'playerName = txtPlayer; '。私はそこで何がやっているのかは分かりませんが、とにかく 'loadData1()'関数で設定しましたか? – 3vilguy

+0

'playerName'はPlayer nameを意味しますが、スコアコードを貼り付けてコピーし、名前コードに変更しようとしました。私は 'playerName = txtPlayer;' to 'loadData1()'名前の関数としてPlayerの名前を設定できる必要があります。申し訳ありませんが、私は他の人の投稿を読んでいるのですが、私が必要なものを見つけることができませんでした... –

関連する問題