Click button and increse numbers in TextField

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.
boblandessAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CyanBlueCommented:
Something like this???

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

Open in new window

0
boblandessAuthor Commented:
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
rascalpantsCommented:
use this...

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


maybe that will work for you...

rp
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

CyanBlueCommented:
Change this line...
       myTextField2.text = parseInt(myTextField2.text)++;

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

CyanBlue
0
boblandessAuthor Commented:
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
rascalpantsCommented:
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
boblandessAuthor Commented:
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
rascalpantsCommented:
can you trace out myTextField2.text in the onPress function...  before the increment?

trace( myTextField2.text  );

and what do you get?


rp
0
CyanBlueCommented:
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
jockejockeCommented:
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
boblandessAuthor Commented:
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
jockejockeCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
boblandessAuthor Commented:
Works exactly as needed.  Thanks for the help.  That made my day.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.