Skip navigation
Currently Being Moderated

Show on a Text Field the number of time we click a Butoon

Feb 21, 2014 1:46 PM

Hi there ... i have been doing some works ... and my teacher told me to do a exercise ... but i am only ask for your opinion and help

 

So here the problem ... i managed to create a code to print text as soon as i click the butoon, here it is:

 

 

botao.addEventListener(MouseEvent.CLICK, mostrartexto);

function mostrartexto(event:MouseEvent){
          caixadetexto.text = "Hi there World";
}

 

So the thing now is ... that ... instead of showing the text by cliking the botoon i need to click the butoon and it must show the number of times i clicked it on the text field.

 

Meaning that ... i Click it will show me "1" or "1 click", "2" or "" clicks ... and so on.

 

So if there is someone who could help me and explaing how to do it ... or if it even is possible

 

Regards ASilva

 
Replies
  • kglad
    72,227 posts
    Jul 21, 2002
    Currently Being Moderated
    Feb 21, 2014 3:49 PM   in reply to ASilva

    use a variable to store the number of buttons clicks:

     

    var botaoClickNum:int=0;

     

     

     

    botao.addEventListener(MouseEvent.CLICK, mostrartexto);
    
    function mostrartexto(event:MouseEvent){
    botaoClickNum++;
               caixadetexto.text = botaoClickNum.toString(); }
     
    |
    Mark as:
  • kglad
    72,227 posts
    Jul 21, 2002
    Currently Being Moderated
    Feb 22, 2014 1:16 PM   in reply to ASilva

    textfields don't have a clear() method.  if you want the textfield display to clear, use:

     

    caixadetexto.text="";

     

    if you want to reset that variable, use

     

    botaoClickNum=0;

     
    |
    Mark as:
  • kglad
    72,227 posts
    Jul 21, 2002
    Currently Being Moderated
    Feb 23, 2014 3:49 PM   in reply to ASilva

    you're welcome.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points