Groups | Blog | Home
all groups > flash actionscript > february 2004 >

flash actionscript : Text fields for triggering actions....


mfkilner
2/20/2004 10:45:07 PM
My head is pounding from this because I have spent ages trying to figure this
out.

I have a text field which when the content is changed needs to be able to set
values for two variables depending on the content thats entered. The content of
the text field is restricted to numeric values only with a maximum of three
digits.

The two variables that need setting are [b]mark[/b] and [b]answer[/b] and the
values are to either be [b]0[/b] or [b]1[/b]. If the text entered in the text
box is [b]100[/b] then both will be set to the value of [b]1[/b]. If the
entered text is anything other than [b]100[/b] then the value of [b]mark[/b]
will be [b]0[/b] and the value of [b]answer[/b] will be [b]1[/b].

I have been trying to use the onChanged text field event but with no joy. My
latest code is below.

Any advice on what is wrong with it or a better way of doing it? I bet its
something hugely obvious but thats the way life goes.

Thanks alot,

Mark

txt.onChanged = function(change) {
if (txt == 100) {
set(mark, 1);
set(answer, 1);
} else if (txt<>100) {
set(mark, 0);
set(answer, 1);
}
};
txtListener = new Object();
txtListener.onChanged = function(change) {
if (txt == 100) {
set(mark, 1);
set(answer, 1);
} else {
set(mark, 0);
set(answer, 1);
}
};
txt.addListener(txtListener);
NSurveyor
2/21/2004 3:56:56 AM
ON [b]Frame 1[/b] Create an input text box. Set the parameters (properties
panel) to:

Variable: text
Maximum Char: 3
Character Options: Only -> Numerals (0-9)
Then use the following script for the current frame:

if (text == 100) {
mark = 1;
answer = 1;
// answer=1 is sort of pointless, since no matter what the outcome, it
still is 1.
// I would just say answer = 1 outside the if, but that doesn't matter
} else if (text <> 100) {
mark = 0;
answer = 1;
}
finally create a new frame at [b]Frame 2[/b] on the Timeline
mfkilner
2/21/2004 8:20:27 AM
That method will work partially for what I need but I need to keep the value of
answer as 0 until something is entered into the text box. After looking at the
code you suggested it looks like answer would take the value of 1 whatever
happens. Haven't tried it yet though so I could be wrong.

Thanks
AddThis Social Bookmark Button