simple actionscript problem

stalkio

New Member
Messages
45
Reaction score
0
Points
0
Hello all. . I am trying to get a simple calculation going in flash....

I have created an input text box (variable name: ageVAR) and a dynamic text box (variable name: LuckyNumVAR) on the first frame of the same layer. Also there I have put a button and in the 'action button' section my code is:

[HIGHLIGHT="Actionscript"]on (press) {
LuckyNumVAR = Number (ageVAR) + 2;
}
[/HIGHLIGHT]

however when I test the movie, rather than doing the calculation it reads
in the dynamic text box. I cannot figure out why - does anyone have any ideas>?
 

patmanbofh

New Member
Messages
2
Reaction score
0
Points
0
Hello S!
Flash has some weird and wonderful implementations!!! Best approach is to explicitly declare and assign variables and methods.

The following function should work:
===================================================

on(press)
{
//Work Variable
var nCalcNo:Number=0;

//Initialise the work variable to the input value
nCalcNo = Number(ageVAR.text);

//Increment the work variable by 2
nCalcNo += 2

//Transfer the calculated value back to the input box
LuckyNumVAR.text = String(nCalcNo);

}

=======================================================

Regards!!
 

stalkio

New Member
Messages
45
Reaction score
0
Points
0
Thanks patmanbofh ... also turns out the following works:

Code:
on (release) {
    dynamictext_instancename.text = Number (inputtext_instancename.text) + 2;
 }

. . . not sure why it needs the text extension but there we have it for present and future reference...
 
Top