Solved

Click button and increse numbers in TextField

Posted on 2009-07-09
13
251 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
  • 5
  • 3
  • 3
  • +1
13 Comments
 
LVL 37

Expert Comment

by:CyanBlue
Comment Utility
Something like this???

CyanBlue
someButton.onPress = function ()

{

   yourTextField.text = parseInt(yourTextField.text)++;

}

Open in new window

0
 

Author Comment

by:boblandess
Comment Utility
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
Comment Utility
use this...

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


maybe that will work for you...

rp
0
 
LVL 37

Expert Comment

by:CyanBlue
Comment Utility
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
Comment Utility
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
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:boblandess
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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 250 total points
Comment Utility
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
Comment Utility
Works exactly as needed.  Thanks for the help.  That made my day.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now