flash actionscript:
I'm trying to learn Actionscript, so I went through the tutorials that come with Flash, but now I'm trying to do something extremely simple, and I keep getting the same error message. I have one input text field, one dynamic text field, and one button on my stage. Ideally, what I want to happen is for the user to put a number in the input text field, press the calculate button and see their number +3 in the dynamic text box. On the button, my code is: on(click){ Number(this._parent.Solution_txt.text) = Number(this._parent.Test_txt.text)+3; } I keep getting the error message **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 2: Left side of assignment operator must be variable or property. Number(this._parent.Solution_txt.text) = Number(this._parent.Test_txt.text)+3; I've tried a few things, but I can't get rid of that error message. Thanks in advance for any advice
try - num = (_parent.inputField.text*1)+3; _parent.outputField.text = num; hth
Thanks. That worked perfectly. Why did it, though? I still don't understand why my code didn't work. I understand your code, even though I probably wouldn't have been able to come up with it on my own, and it seems like we were doing the same thing just in different ways. Why wasn't mine working?
[quoted text, click to view] >Left side of assignment operator must be variable or property.
you were setting the left side as a Number, effectively 4 = 4+3; hence the error, whereas variable num = 4+3 is OK, hth
I don't believe so, because the text you enter into the input field is stored as a String, so you need to use number() to convert it to a number.
You don't have to remove 'Number' from both sides of the expression, just remove it from the left side of the expression. For example: Solution_txt.text = Number(Test_txt.text)+3; //Correct Number(Solution_txt.text) = Number(Test_txt.text)+3; //Incorrect Hope it helps.......
If you read the error message it has told you what was wrong and therefore how to fix it... the left side of the equation must be a variable or a property... This means that the left hand side of the equation can't require an evaluation of any sort. Number(this._parent.Solution_txt.text) // this requires that we perform an evaluation to arrive at a result... that isn't a path to an object, a variable or a property. therefor as indicated... the correct syntax is : this._parent.Solution_txt.text = Number(this._parent.Test_txt.text)+3; cheers
Hai, All what u have to do is first u put an input type text in the layer 1, below that insert an dynamic text in the same layer 1. Now create a button, set the variable value for input type text as in1, and dynamic text as out1. Now on u'r button add the code as on(press) { out1=in1+3; } bye.
Don't see what you're looking for? Try a search.
|