Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Jun 2007
    Posts
    805
    Thanks
    123
    Thanked 23 Times in 23 Posts

    Detect value in textfield and then perform action

    Hi,

    This is my situation:

    I have a textbox. If the correct value is written in it, it jumps to a certain frame in my flash movie (succes). If not, it jumps to another (fail).

    How would I archieve that?

  • #2
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Interesting concept, like a password protection?

    You would need to have a function that compares the input text against the correct value. Then just have a button call this function when the user is ready to test their entry. This is something I wrote in 3 mins, might not be right but gives you a start.

    Code:
    function checkText() {
      inputText = _root.inputTextField.value;
      if (inputText == "password")
      {
        gotoAndStop(2);
      }
      else 
      {
        gotoAndStop(3);
      }
    }
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #3
    Regular Coder
    Join Date
    Jun 2007
    Posts
    805
    Thanks
    123
    Thanked 23 Times in 23 Posts
    Jeremy,
    More like a simple math-game - but interesting idea with the password, I guess you could use it for that too.

    Thank you for your suggestion, I'll try it off ASAP and report back here !

  • #4
    Regular Coder
    Join Date
    Jun 2007
    Posts
    805
    Thanks
    123
    Thanked 23 Times in 23 Posts
    Jeremy, it diden't work unfortunately. However, I just found this: http://www.webwasp.co.uk/tutorials/b...tive/index.php

  • #5
    New to the CF scene
    Join Date
    May 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Use a button?

    I see why Jeremy's code doesn't work. There's nothing to tell flash when the user is done to have flash do something. Without a button. There is a way to set the focus to a text field, something like
    stage.focus = myTextField

    Another option would be to create an onEnterFrame function and when it's running you could create a condition

    function typeSomething() {
    this.onEnterFrame = function() {
    if (stage.focus != myTextField) {
    //do something
    }else {
    this.onEnterFrame = null;
    return;
    //do something else
    }
    }
    }

    But best to do with a button so you have more control.

  • #6
    Regular Coder
    Join Date
    Jun 2007
    Posts
    805
    Thanks
    123
    Thanked 23 Times in 23 Posts
    Hmm, I still haven't made this work.

    I have a button: button_cubmit
    And a textfield: Resultat

    This is my code added to my 'actions' layer:
    Code:
    button_submit.addEventListener(MouseEvent.CLICK, subClick);
    
    function subClick(event:MouseEvent):void{
     myPass = Resultat.text;
     if(myPass == "password"){
      gotoAndStop("rigtigt");
     } else {
      gotoAndStop("forkert");
    }
    My result:
    1084: "Syntax error: Expecting rightbrace before end of program".. And my flash movie just keeps changing through all the scenes.

  • #7
    New Coder bigtiger's Avatar
    Join Date
    Oct 2005
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    I did a simple test on flash 8.
    Hmmm, it may or may not help.

    Setting frames to 20 and add two keyframes to 5 and 10.
    Place a TextField (name: txtpass) on the stage and add this as2 code in frame.

    Code:
    function do_checkpass(cf:TextField)
    {
    	var targetFrame:Number;
    	var passkey:String = 'password';
    
    	if (cf.text != passkey)
    		targetFrame = 5;
    	else
    		targetFrame = 10;
    	cf._parent.gotoAndStop(targetFrame);
    }
    
    txtpass.onChanged = function(cf:TextField)
    {
    	do_checkpass(cf);
    }
    
    stop();
    Last edited by bigtiger; 05-24-2009 at 06:07 PM.

  • #8
    Regular Coder
    Join Date
    Jun 2007
    Posts
    805
    Thanks
    123
    Thanked 23 Times in 23 Posts
    Hi there,

    I'm a bit unsure on where to add the code. I tried to add it to my button element, however, that doesn't work. The flash movie just keeps looping through all the frames. Also, I get some errors (see pic). I'm probably doing something wrong. By the way, my document is AS3
    Attached Thumbnails Attached Thumbnails Detect value in textfield and then perform action-untitled-1.jpg  

  • #9
    New Coder bigtiger's Avatar
    Join Date
    Oct 2005
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    It has big change between AS2 and AS3.
    That's why you got a lot of error messages on a as3 document.
    Actually I never worked with As3 before.
    But the basic logic should be the same.

    Just did a few search on adobe.com and found a example that show how change event of textfield work. It is simliar to as2 onChange event, but with as3 syntax.

    Can you operate MoiveClip with as3 ?
    If you do, then this code should be the only one you need to build your stuffs.

    http://help.adobe.com/en_US/AS3LCR/F...0.0/index.html

    Code example from adobe liveDoc:

    In the following example, the text that the user enters (user input) is immediately copied (echoed) into another text field with a different text format.
    Two text fields are created, one for the user input and the other (headingTextField) for the copy of the user input. A TextFormat object is also created and the default text format is assigned to the headingTextField text field. When the content of the text field is changed, the changeHandler() method is invoked, which assigns the text in the inputTextField text field to the headingTextField text field. (If the method was called for the TextEvent.TEXT_INPUT event instead of the Event.CHANGE event, the content of the user input is copied only after the user has entered more text.)

    Code:
    package {
        import flash.display.Sprite;
        import flash.text.TextField;
        import flash.text.TextFieldType;
        import flash.text.TextFormat;
        import flash.text.TextFormatAlign;
        import flash.events.Event;
        
        import flash.events.TextEvent;
        public class TextField_Event_changeExample extends Sprite {
            private var inputTextField:TextField = new TextField(); 
            private var headingTextField:TextField = new TextField(); 
            private var newFormat:TextFormat = new TextFormat();
             
            public function TextField_Event_changeExample() {
                headingTextField.x = 10;
                headingTextField.y = 10;
                headingTextField.height = 30;
                headingTextField.width = 400;
                headingTextField.background = true;
                headingTextField.backgroundColor = 0xF5F5DC;
                headingTextField.selectable = false;
     
                inputTextField.x = 10;
                inputTextField.y = 70;
                inputTextField.height = 20;
                inputTextField.width = 230;
                inputTextField.background = true;
                inputTextField.border = true;
                inputTextField.maxChars = 40;
                inputTextField.wordWrap = true;
                inputTextField.type = TextFieldType.INPUT;
                inputTextField.addEventListener(Event.CHANGE, changeHandler);
                newFormat.bold = true;
                newFormat.size = 18;
                newFormat.color = 0xFF0000;
                newFormat.align = TextFormatAlign.CENTER;
                headingTextField.defaultTextFormat = newFormat;
                this.addChild(inputTextField);
                this.addChild(headingTextField);
            }
            private function changeHandler(e:Event):void {
                headingTextField.text = inputTextField.text;
            }
        }
    }

  • #10
    Regular Coder
    Join Date
    Jun 2007
    Posts
    805
    Thanks
    123
    Thanked 23 Times in 23 Posts
    I had a look at the script. Most of it is actually pure magic as I've never worked with AS before

    However, I THINK I managed to strip it down to what I need - but what's inside the 'changeHandler is by no means correct - I really need some more assistance here if possible!

    But Bigtiger, thank you so much for your help so far!

    Code:
             function Check_Value() {
                Resultat.addEventListener(Event.CHANGE, changeHandler);
            }
    		
            function changeHandler(e:Event):void {
    
    	    var targetFrame:Number;
    	    var passkey:String = 'password';
    
    	    if (Resultat != passkey)
    		targetFrame = 5;
    	else
    		targetFrame = 10;
    	     gotoAndStop(targetFrame);
    }

  • #11
    New Coder bigtiger's Avatar
    Join Date
    Oct 2005
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi, CaptainB

    I worked with AS3 and a few pages of code example and tutorials; finally I got the following code.

    • Place the following code in a text file and save and name it as Auth.as.
      Code:
      package {
      	import flash.display.Sprite;
      	import flash.display.MovieClip;
      	import flash.text.TextField;
      	import flash.events.Event;
      	import flash.events.TextEvent;
      
      	public class Auth extends Sprite {
      		private var inputTextField:TextField = new TextField();
      		provate var m_mc:MovieClip = null;
      
      		public function Auth(mc:MovieClip) {
                  		inputTextField.x = 10;
      			inputTextField.y = 70;
      			inputTextField.height = 20;
      			inputTextField.width = 230;
      			inputTextField.background = true;
      			inputTextField.border = true;
      			inputTextField.maxChars = 40;
      			inputTextField.wordWrap = true;
      			inputTextField.type = TextFieldType.INPUT;
      			inputTextField.addEventListener(Event.CHANGE, changeHandler);
      			this.addChild(inputTextField);
      
      			this.m_mc = mc;
      		}
      
      		private function changeHandler(e:Event):void {
      			// trace('changeHandler cb');
      
      			if (this.inputTextField.text != 'password') {
      				this.m_mc.gotoAndStop(5);
      			} else {
      				this.m_mc.gotoAndStop(10);
      			}
      		}
      	}
      }
    • Create a new flash document and save it to the same location as file, Auth.as.
    • Create a new MovieClip symbol instance on the stage by converting from a drawing or create a new one.
    • Double-click the MovieClip instance on the stage to enter Edit-inplace mode.
    • Create new keyframes at frame 5 and 10 in the Timeline of the MovieClip instance, and place some identify labels on it.
    • Enter the following code in frame1 in the Timeline of the MovieClip instance.
      Code:
      var auth:Auth = new Auth(this);
      
      stop();


    It is not a good and best way to code. But it seems to be work.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •