• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Empty textField

Explorer ,
Apr 12, 2010 Apr 12, 2010

Copy link to clipboard

Copied

In flash IDE i put a dynamic text with yourGuessText instance name.

I need something like: if user not enter something to this field trace("need enter something");

How i can do it?

i have code but its not working:

else if (Number(yourGuessText.text.length()) == 0) // what need write here?
               {
                    trace("need enter something");
               }

planing then user will write numbers...

TOPICS
ActionScript

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 12, 2010 Apr 12, 2010

Copy link to clipboard

Copied

Try...

else if(yourGuessTest.length == 0)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 12, 2010 Apr 12, 2010

Copy link to clipboard

Copied

don't see any errors but still not working as i need.

code:

public function checkingYourGuess(e:MouseEvent):void
          {
               if (guessNumber == Number(yourGuessText.text))
               {
                    outputText.text = "You are GUESS!!!";
                    trace("Guess!");
                    points += 100;
                    trace("Player earn: " + points + " points!");
                    trace("+++++++++++++++++++++++++");
                    trace("go to the next level?");
                    nextLevelBtn.visible = true;
                    guessBtn.visible = false;
                    winGame();
               }
               else if (guessNumber > Number(yourGuessText.text))
               {
                    points -= 20;
                    pointsView.text = String(points);
                    trace("-20 points, need MORE");
                    outputText.text="need MORE, try again please";
               }
               else if (guessNumber < Number(yourGuessText.text) && (Number(yourGuessText.text)<= lastGuessNumber))
               {
                    points -= 20;
                    pointsView.text = String(points);
                    trace("-20 points, need LESS");
                    outputText.text="need LESS, try again please";
               }
               else if (Number(yourGuessText.text) > lastGuessNumber)
               {
                    outputText.text = "enter number from 1 to " + lastGuessNumber;
                    trace("enter number from 1 to " + lastGuessNumber);
               }
               else if (yourGuessText.length == 0) // what need write here?
               {
                    trace("need enter something");
               }
          }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 12, 2010 Apr 12, 2010

Copy link to clipboard

Copied

As long as yourGuessText is a single line textfield (meaning "multiline" is not selected for it), that code will work

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 12, 2010 Apr 12, 2010

Copy link to clipboard

Copied

gn.png

upload image preview (start .swf and click to Guess button) and see -20

also all code here:

package {

     import flash.events.*;
     import flash.display.*;
     import flash.text.TextField;

     public class GuessNumber extends MovieClip
     {
          var guessNumber:Number;
          var points:Number = 0;     
          var level:Number = 1;
          var lastGuessNumber:Number = 5;
          
          //constructor
          public function GuessNumber()
          {
               generateNumber();
          }
          
          public function generateNumber(e:Event = null):void
          {
               gotoAndStop('gameScreen');
               trace("****** Welcome Screen *********");
               pointsView.text = "0";
               levelView.text = "1";
               addEventListener(Event.ADDED_TO_STAGE, startGuess);
               startGuess();
               //howToPlay_mc.visible = false;
               //moreGames_mc.visible = false;
               //thanks_mc.visible = false;
               //howToPlayBtn(MouseEvent.CLICK, howToPlayScreen);
               //moreGamesBtn(MouseEvent.CLICK, moreGamesScreen);
               //thanksBtn(MouseEvent.CLICK, thanksScreen);
          }
          
          /*public function howToPlayScreen(event:MouseEvent):void
          {
               howToPlay_mc.visible = true;
          }
          public function moreGamesScreen(event:MouseEvent):void
          {
               moreGames_mc.visible = true;
          }
          public function thanksScreen(event:MouseEvent):void
          {
               thanks_mc.visible = true;
          }*/
          
          public function startGuess(e:Event = null):void
          {
               //lastGuessNumber = 5;
               trace("**** Starting Guess ****");
               guessBtn.enabled = true;
               guessBtn.visible = true;
               nextLevelBtn.enabled = false;
               nextLevelBtn.visible = false;
               levelNumbers.text = "Guessed number betwen 1 and " +  lastGuessNumber;
               trace("Guessed number beetween 1 and " + lastGuessNumber);
               yourGuessText.text = "";
               levelView.text = String(level);
               trace("Now Level: " + level);
               pointsView.text = String(points);
               trace("Player Points: " + points);
               
               guessNumber=Math.ceil(Math.random()*lastGuessNumber);
               trace("Guessed number: " + guessNumber);
               
               removeEventListener(Event.ADDED_TO_STAGE,startGuess);
               guessBtn.addEventListener(MouseEvent.CLICK,checkingYourGuess);
          }
          
          public function checkingYourGuess(e:MouseEvent):void
          {
               if (guessNumber == Number(yourGuessText.text))
               {
                    outputText.text = "You are GUESS!!!";
                    trace("Guess!");
                    points += 100;
                    trace("Player earn: " + points + " points!");
                    trace("+++++++++++++++++++++++++");
                    trace("go to the next level?");
                    nextLevelBtn.visible = true;
                    guessBtn.visible = false;
                    winGame();
               }
               else if (guessNumber > Number(yourGuessText.text))
               {
                    points -= 20;
                    pointsView.text = String(points);
                    trace("-20 points, need MORE");
                    outputText.text="need MORE, try again please";
               }
               else if (guessNumber < Number(yourGuessText.text) && (Number(yourGuessText.text)<= lastGuessNumber))
               {
                    points -= 20;
                    pointsView.text = String(points);
                    trace("-20 points, need LESS");
                    outputText.text="need LESS, try again please";
               }
               else if (Number(yourGuessText.text) > lastGuessNumber)
               {
                    outputText.text = "enter number from 1 to " + lastGuessNumber;
                    trace("enter number from 1 to " + lastGuessNumber);
               }
               else if (yourGuessText.length == 0) // what need write here?
               {
                    trace("need enter something");
               }
          }
          
          public function winGame():void
          {
               pointsView.text = String(points);
               level += 1;
               if (level == 4)
               {
                    youAreWinner();
                    trace("You are winner!!!!!");
                    pointsView.text = String(points);
                    trace("Player earn: " + points + " points." );
                    level = 1;
                    points = 0;
                    lastGuessNumber = 5;
               }
               else{lastGuessNumber += 10;}
               
               nextLevelBtn.enabled=true;
               guessBtn.enabled=false;
               nextLevelBtn.addEventListener(MouseEvent.CLICK, playAgain);
          }
          
          public function playAgain(event:MouseEvent):void
          {
               trace("yes");
               outputText.text = "";
               startGuess();
          }
          
          public function youAreWinner():void
          {
               gotoAndStop('finishScreen');
               nextLevelBtn.visible = false;
               guessBtn.visible = false;
               playAgainBtn.addEventListener(MouseEvent.CLICK, generateNumber);
          }
          
     }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 12, 2010 Apr 12, 2010

Copy link to clipboard

Copied

What are the properties of the textfield?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 12, 2010 Apr 12, 2010

Copy link to clipboard

Copied

input text

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 12, 2010 Apr 12, 2010

Copy link to clipboard

Copied

find unswer

need move code for empty field to top and put return

code:

public function checkingYourGuess(e:MouseEvent):void
          {
            if (yourGuessText.length == 0)
               {
                    trace("need enter something");
                    outputText.text="please enter a number beetween 1 and " + lastGuessNumber;
                    return;
               }               
               
               if (guessNumber == Number(yourGuessText.text))
               {
                    outputText.text = "You are GUESS!!!";
                    trace("Guess!");
                    points += 100;
                    trace("Player earn: " + points + " points!");
                    trace("+++++++++++++++++++++++++");
                    trace("go to the next level?");
                    nextLevelBtn.visible = true;
                    guessBtn.visible = false;
                    winGame();
               }
               else if (guessNumber > Number(yourGuessText.text))
               {
                    points -= 20;
                    pointsView.text = String(points);
                    trace("-20 points, need MORE");
                    outputText.text="need MORE, try again please";
               }
               else if (guessNumber < Number(yourGuessText.text) && (Number(yourGuessText.text)<= lastGuessNumber))
               {
                    points -= 20;
                    pointsView.text = String(points);
                    trace("-20 points, need LESS");
                    outputText.text="need LESS, try again please";
               }
               else if (Number(yourGuessText.text) > lastGuessNumber)
               {
                    outputText.text = "enter number from 1 to " + lastGuessNumber;
                    trace("enter number from 1 to " + lastGuessNumber);
               }          
          }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 12, 2010 Apr 12, 2010

Copy link to clipboard

Copied

Did you try trace(yourGuessText.text.length()); to see whats going on?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 12, 2010 Apr 12, 2010

Copy link to clipboard

Copied

Sorry I wrote Did you try trace(yourGuessText.text.length());  to see whats going on?

I was copying your original code which treated length as a method when it's really a property.

I ment to write trace(yourGuessText.text.length);

Maybe the fix is to just write length as a property.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 13, 2010 Apr 13, 2010

Copy link to clipboard

Copied

LATEST

after

trace(yourGuessText.text.length);

i see

0

zero in output window

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines