Flash Input Text problem

  • vraol
  • Born
  • Born
  • vraol
  • Posts: 4

Post 3+ Months Ago

Hi: I have a very simple question. Its so simple that it makes me feel foolish to set it up, but it has been boggling me for a while. I have a flash app. that has an input text box (var = muc), and has an action script,

var mc:String ="0231"
btn.onRelease = function() {

if (String(muc)==String(mc))
{gotoAndStop(2);
}else {
gotoAndStop(3);}


please note: Here muc is the var name assigned to the input text field. btn is the instance name of the submit button.

All, I want to do is to verify if the input text in the text field variable(muc) is the same as a fixed number/string. However, when I trace, both values show exactly the same, but the if loop does not work even if both values are the same. any suggestions?

I am working with actionscript 2.0 btw.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23454
  • Loc: Woodbridge VA

Post 3+ Months Ago

Are you testing to see if it matches an exact string? Or the number of characters?

If you are testing to see if, for example, they typed 4 characters, then something like this should work. The syntax below is without error, but I didn't bother to test it.

Code: [ Select ]
// Set the max characters  (if not set, the maxChars property has the null value -no limit- )
muc.maxChars=5  //where 5 is the total number of characters you are testing for
 
 
muc.onChanged=function(){
   // We use the trace to test the results 
   trace("Used "+this.length+" of "+this.maxChars+ " characters")
     if (this.length==this.maxChars) {
         btn.onRelease = gotoAndStop(2);
     }
     else {
         btn.onRelease = gotoAndStop(3);
     }
}
  1. // Set the max characters  (if not set, the maxChars property has the null value -no limit- )
  2. muc.maxChars=5  //where 5 is the total number of characters you are testing for
  3.  
  4.  
  5. muc.onChanged=function(){
  6.    // We use the trace to test the results 
  7.    trace("Used "+this.length+" of "+this.maxChars+ " characters")
  8.      if (this.length==this.maxChars) {
  9.          btn.onRelease = gotoAndStop(2);
  10.      }
  11.      else {
  12.          btn.onRelease = gotoAndStop(3);
  13.      }
  14. }
  • vraol
  • Born
  • Born
  • vraol
  • Posts: 4

Post 3+ Months Ago

No, I want to test that the strings are identical, for example, in this case, I want to test if the input variable muc is identical to (0231) to the declared string variable mc (0231). I have tried every which way I could, even changed from string to number as variable type, but somehow, although the values show up identical on trace, the if loop does not execute correctly.
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

well I don't think its finding the mc variable, but also your not getting the input text.

correct code would be...

Code: [ Select ]
var mc:String ="0231"
btn.onRelease = function() {

if (this._parent.textfieldInstanceName.text ==this._parent.mc)
{gotoAndStop(2);
}else {
gotoAndStop(3);}
  1. var mc:String ="0231"
  2. btn.onRelease = function() {
  3. if (this._parent.textfieldInstanceName.text ==this._parent.mc)
  4. {gotoAndStop(2);
  5. }else {
  6. gotoAndStop(3);}


assuming that the textfield and the variable are on the same level as the btn
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23454
  • Loc: Woodbridge VA

Post 3+ Months Ago

I was just testing this myself and arrived at the same conclusion.
Given your variable name this works. This time I tested to make sure

Code: [ Select ]
stop();
var mc:String ="0231"
btn.onRelease = function() {
 
if (this._parent.muc.text == this._parent.mc)
{gotoAndStop(2);
}else {
gotoAndStop(3);}
}
  1. stop();
  2. var mc:String ="0231"
  3. btn.onRelease = function() {
  4.  
  5. if (this._parent.muc.text == this._parent.mc)
  6. {gotoAndStop(2);
  7. }else {
  8. gotoAndStop(3);}
  9. }


btw, make sure you aren't applying that to the button itself. You should apply linkage to the button with an identifer as btn and export for action script then put your script in frame one.
  • vraol
  • Born
  • Born
  • vraol
  • Posts: 4

Post 3+ Months Ago

Hi:

Thanks for your input. I tried your suggestions also, and applied your code to the frame. However, my problem was not resolved. I have uploaded the sample .fla file. If it is not asking too much, could you please take a look at it and point out where my error is? I will be highly appreciative.

http://www.yponder.com/vijay/muc.fla

Thank you
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23454
  • Loc: Woodbridge VA

Post 3+ Months Ago

OK here is your fixed file
http://www.atnoproductions.com/ozzu/muc-fixed.fla

There were several issues.

First of all note I didn't alter the action script that graphixboy and I posted in your first frame.

Problem 1:
The action script is looking for an instance name for your text input field (and you don't have one) not a variable name, so your muc:String variable isn't necessary so remove it and add an instance name of muc (*side note - I don't believe you need to data-type your variables in the variable field to begin with. You data-type them in the action script -- as far as I understand just type your variable name in the variable field when you need to)

Problem 2:
Your button had the wrong linkage identifier. Your linkage identifier was "bar blue". Change that to "btn" (recommended to not have spaces in your linkage identifier anyway)

Problem 3:
You had your text input set to Multiline. That didn't work. When I set it to single line it worked. I have no idea why that is, but when I set it to single line it worked. If you need it to be Multiline then you still have a problem. (*side note I also disabled auto-kern which you had enabled. You typically don't need auto-kern).

Problem 4 is unrelated to your current problem, but you would run up against it so here it is

Problem 4:
In Frame 2 your action script is btn2.onRelease, but your instance name is btn1. Change the script to match your instance, and all works like a charm.

I think I covered all of it.
  • vraol
  • Born
  • Born
  • vraol
  • Posts: 4

Post 3+ Months Ago

Ok, I see exactly where the problems were. I had tried to use the instance name instead of the variable name for the input text at one point, but I guess since it was set as multi line, that it did not work, so I changed it back.

Thanks a lot and I appreiciate your help!

Post Information

  • Total Posts in this topic: 8 posts
  • Users browsing this forum: No registered users and 6 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.