all groups > flash actionscript > july 2004 >
You're in the

flash actionscript

group:

Simple ActionScript problem



Simple ActionScript problem reldruH
7/29/2004 8:14:40 PM
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
Re: Simple ActionScript problem Jack.
7/29/2004 8:24:06 PM
try -
num = (_parent.inputField.text*1)+3;
_parent.outputField.text = num;

hth
Re: Simple ActionScript problem reldruH
7/29/2004 8:35:17 PM
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?
Re: Simple ActionScript problem Jack.
7/29/2004 8:44:42 PM
[quoted text, click to view]

you were setting the left side as a Number, effectively 4 = 4+3;
hence the error, whereas variable num = 4+3 is OK,

hth

Re: Simple ActionScript problem reldruH
7/29/2004 8:54:47 PM
Re: Simple ActionScript problem speedlab1
7/29/2004 9:48:01 PM
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.
Re: Simple ActionScript problem reldruH
7/30/2004 12:38:34 AM
Re: Simple ActionScript problem navslakra
7/30/2004 5:29:09 AM
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.......
Re: Simple ActionScript problem mandingo
7/30/2004 5:45:45 AM
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



Re: Simple ActionScript problem PLGanesh
7/30/2004 6:07:15 AM
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.

Re: Simple ActionScript problem reldruH
7/30/2004 8:07:08 PM
THANK YOU!

AddThis Social Bookmark Button