Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if statement 1

Status
Not open for further replies.

faxof

Programmer
Dec 5, 2001
272
GB
hello

although i'm a competent flash newbie and competent at scriping in other languages i have never scripted in flash.

i have a red box next to a text field.
i want to allow someone to type in some text;
if the text they type is "grapefruit" then i want the red box to turn green.
any ideas?

Faxof.
 
First you need to make 2 buttons - a red one and a green one. Next you need to make a movieClip - place the red button in frame 1 of the movieClip (as well as a stop() action in frame 1), and place the green button in frame 2 of the movieClip - you don't need to bother putting a stop() action in the second frame.

Now, place the movieClip on the stage. Beside it, create an input field, and in the properties panel for the input field, change VARIABLE to "_root.input" (w/o the quotes). Now, edit the movieClip so that you can place this script on the red button in frame 1:
Code:
on (release) {
 if (_root.input.toLowerCase() == "grapefruit") {
  this.gotoAndStop(2);
 }
}
And that should do the job ... _____________________________________________________
Knowledge is attained only by seeking out that which is unknown
 
that's great - thanks
but (the inevitable but)
i wanted the box to true green when the user finished typing not when they click on the box.
and (the inevitable and)
if i wanted to make more of these text boxes and red boxes do i change the name "_root.input" to let say "_root.input2"? or am i right off the mark?

thanx for the help
Faxof
 
May I ask how you would know when I was finished typing? Regards,

oldman3.gif
 
No - you're right on the money regarding the "_root.input2", but Old is right - how are you going to know when the user has finished typing? You could change the statement on the button so that it accepts key input - that would allow the user to press ENTER when they were done and still get the same effect. You just need to change the code on the red button to this:
Code:
on (release, keyPress &quot;<Enter>&quot;) {
 if (_root.input.toLowerCase() == &quot;grapefruit&quot;) {
  this.gotoAndStop(2);
 }
}
Maybe you have some other way to know when the user has finished typing ... if so, let me know, and I'll see what I can do with it. _____________________________________________________
Knowledge is attained only by seeking out that which is unknown
 
that's right - i wanted to check the text when the user presses enter.

if i have say ten of these textboxes with green/red boxes is there a way of counting the number of green boxes and showing the result?

i have made the whole thing (quite simple) in excel using macros but i need to make it in flash, would me emailing you the excel file be of any use?

thanx

Faxof
 
If you're using MX you can try this - set the instance name of the textfield to 'input' (rather than the variable name as in the examples above). And put this script in frmae 1 of the main timeline:

input.onChanged = function() {
if (input.text.toLowerCase() == 'grapefruit') {
trace(&quot;changed&quot;);
}
};

This will trigger the trace action (or the gotoAndStop or whatever you want to put in there) as soon as the text says 'grapefruit' without the need to hit enter.
 
Um, not really. What would I do with the Excel file?!

If you have 10 boxes, and you want to count and display the number correct, use variables in the button script like this:
Code:
on (release, keyPress &quot;<Enter>&quot;) {
 if (_root.input.toLowerCase() == &quot;grapefruit&quot;) {
  _root.correct++;
  this.gotoAndStop(2);
 }
}
Then make a dynamic textfield, look in the properties panel for a box named VARIABLE, and type &quot;_root.correct&quot; in the box (w/o the &quot;&quot;). That textfield will show the number the user got correct.

If you want to be a little more firendly about it, you can make a variable which contains some banter ... in the first frame of your main timeline, type this:
Code:
_root.msg = &quot;You got &quot; + correct + &quot; out of 10 correct!&quot;;
Then change the VARIABLE in the textfield properties panel to &quot;_root.msg&quot; instead of &quot;_root.correct&quot;. _____________________________________________________
Knowledge is attained only by seeking out that which is unknown
 
thanks both of you for the help - i will look further at this over the weekend (i'm snowed at work trying to learn lotus notes scripting too)
i will feedback and award the approprite appreciation then
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top