?
Solved

Click button and increse numbers in TextField

Posted on 2009-07-09
13
Medium Priority
?
274 Views
Last Modified: 2013-11-11
I have done a search but may not be asking the correct way.  I would like to be able to click on a button and it increases the number in a TextField.  Example, I press button and the TextField changes from 100 to 101.
0
Comment
Question by:boblandess
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
  • +1
13 Comments
 
LVL 37

Expert Comment

by:CyanBlue
ID: 24816644
Something like this???

CyanBlue
someButton.onPress = function ()
{
   yourTextField.text = parseInt(yourTextField.text)++;
}

Open in new window

0
 

Author Comment

by:boblandess
ID: 24816794
I am getting the error message listed below.
Left side of assignment operator must be variable or property.
 
This your code modified with my instance names inserted.
this.bezel01.btn_NXT01.onPress = function ()
{
   myTextField2.text = parseInt(myTextField2.text)++;
}
0
 
LVL 22

Expert Comment

by:rascalpants
ID: 24817739
use this...

this.bezel01.btn_NXT01.onPress = function ()
{
  myTextField2.text = Number( myTextField2.text )++;
}


maybe that will work for you...

rp
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 37

Expert Comment

by:CyanBlue
ID: 24818645
Change this line...
       myTextField2.text = parseInt(myTextField2.text)++;

to these lines...
       var n:Number = parseInt(myTextField2.text);
       myTextField2.text = n++;

CyanBlue
0
 

Author Comment

by:boblandess
ID: 24822294
rascalpants I still get the same error message with the mod to your code.

CyanBlue I got it to work using your code below.

var n:Number = parseInt(myTextField2.text);
this.bezel01.btn_NXT01.onPress = function ()
{
       myTextField2.text = n++;
}  

One thing I did not mention, because I did not realize that it would matter, is that the TextField is not be pre-populated.  The user enters a number into the TextField and then may use the btn_NXT01 button to advance the number that appears.  The TextField data is saved to a SLO when exiting the frame.  When I click the btn_NXT01 button it fills the myTextField2 with NaN

//fills myTextField2 with data input to myTextFieldOne
this.LLS01_btn.onPress = function(){
 _root.myTextField2.text = _root.myTextFieldOne.text
  _root.myTextFieldOne.text = _root.myTextFieldBlank.text
};

//code for saving TextField data
this.return_btn.onPress = function(){
 editSatcomPresets_so.data.TextField2 = myTextField2.text;
  editSatcomPresets_so.data.TextField8 = myTextField8.text;
   gotoAndStop("dat", 15);
}

//fills TextField data with data from editSatcomPresets shared object
stop();
editSatcomPresets_so = SharedObject.getLocal("editSatcomPresets_so");
 myTextField2.text = editSatcomPresets_so.data.TextField2
  myTextField8.text = editSatcomPresets_so.data.TextField8

onEnterFrame = arr;
onEnterFrame = setTextFormatGlobal;
var n:Number = parseInt(myTextField2.text);
 
this.bezel01.btn_NXT01.onPress = function ()
{
       myTextField2.text = n++;
} 
 
 
 
this.LLS02_btn.onPress = function(){
if ( _root.editSatcomPreset01Screen01.fivekDed25kDed._currentframe < 2) {_root.editSatcomPreset01Screen01.fivekDed25kDed.gotoAndStop(2);
}
else{_root.editSatcomPreset01Screen01.fivekDed25kDed.gotoAndStop(1);
}
}
 
 
this.LLS03_btn.onPress = function(){
if ( _root.editSatcomPreset01Screen01.chanFreq01._currentframe < 2) {_root.editSatcomPreset01Screen01.chanFreq01.gotoAndStop(2);
}
else{_root.editSatcomPreset01Screen01.chanFreq01.gotoAndStop(1);
}
}
 
 
this.LLS01_btn.onPress = function(){
	   _root.myTextField2.text = _root.myTextFieldOne.text
   _root.myTextFieldOne.text = _root.myTextFieldBlank.text
};
 
 
this.LLS04_btn.onPress = function(){
	   _root.myTextField8.text = _root.myTextFieldOne.text
   _root.myTextFieldOne.text = _root.myTextFieldBlank.text
};
 
 
this.RLS01_btn.onPress = function(){
	_root.myTextField2.text = _root.myTextFieldBlank.text
	_root.myTextField8.text = _root.myTextFieldBlank.text
};
 
//saves textField data to editSatcomPresets_so
this.return_btn.onPress = function(){
	editSatcomPresets_so.data.TextField2 = myTextField2.text;
	editSatcomPresets_so.data.TextField8 = myTextField8.text;
	gotoAndStop("dat", 15);
}
 
 
//fills textField data with data from editHfPresets shared object
stop();
editSatcomPresets_so = SharedObject.getLocal("editSatcomPresets_so");
myTextField2.text = editSatcomPresets_so.data.TextField2
myTextField8.text = editSatcomPresets_so.data.TextField8

Open in new window

0
 
LVL 22

Expert Comment

by:rascalpants
ID: 24823556
there error you are getting must be becaues you have not named an instance properly.

also, you have modified the code, so that all you are doing is increasing a value that is only set at runtime...

if you want to increment a number that is in a text box, you need to take the value of that number inside of the onPress function and increment it there.


rp
0
 

Author Comment

by:boblandess
ID: 24823802
I'm very certain the instance name is correct.   If I change the line of your code, myTextField2.text = parseInt(myTextField2.text)++; ,  to do something else like go to another frame it works which is one of the reasons I am certain that the instance names are correct.
I beleive the reason your code is not working is that the left side of the assignment operator must be variable or property and not an instance name.
Using CyanBlues code it does work if the textField is already populated.  
0
 
LVL 22

Expert Comment

by:rascalpants
ID: 24823877
can you trace out myTextField2.text in the onPress function...  before the increment?

trace( myTextField2.text  );

and what do you get?


rp
0
 
LVL 37

Expert Comment

by:CyanBlue
ID: 24823952
Both lines should be inside the onPress handler, and that code should work as long as your textField myTextField2 exists on stage when you click the button even if you are populating the textField with the script...

CyanBlue
0
 
LVL 2

Expert Comment

by:jockejocke
ID: 24832823
Why not test if the value is set when the user clicks? If not, display some kind of alert or do nothing.
this.bezel01.btn_NXT01.onPress = function ()
{
	var t = myTextField2.text;
	if (t.length > 0)
	{
		var n:Number = parseInt(t);
		myTextField2.text = n++;
	}
	else
	{
		trace("Oops, number is not set");
	}
} 

Open in new window

0
 

Author Comment

by:boblandess
ID: 24838638
jockejocke,
I inserted your code and when there is nothing in myTextField2 it returns "Oops, number is not set".  When I enter a number into myTextField2 it does not advance the number nor does it return "Oops, number is not set".  
0
 
LVL 2

Accepted Solution

by:
jockejocke earned 1000 total points
ID: 24838825
I wrote that answer a little bit to quick i guess. Here are a more robust example. I also added digit validation, so if the value in the textbox is not numeric, it won't try to add to it..
Cheers
this.bezel01.btn_NXT01.onPress = function ()
{
        var t:String = myTextField2.text;
        if (t.length > 0)
        {
				if (n = (parseInt(t)+1))
				{
	                myTextField2.text = n.toString();
				}
				else
				{
					trace("Oops, user did not enter a number");
				}
        }
        else
        {
                trace("Oops, number is not set");
        }
}

Open in new window

0
 

Author Closing Comment

by:boblandess
ID: 31601742
Works exactly as needed.  Thanks for the help.  That made my day.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
Suggested Courses
Course of the Month9 days, 11 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question