A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: [RESOLVED] A way of detecting typing in a textbox in realtime w/o using onEnterFrame

  1. #1
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971

    resolved [RESOLVED] A way of detecting typing in a textbox in realtime w/o using onEnterFrame

    Hello guys ^_^

    Before posting for help, i always do an exhaustive research on the web. \
    This time, i need to know how to detect when typing in a textbox in realtime, without using onEnterFrame, as onEnterFrame use a lot of CPU. You type in an input textbox, and then show that in a dynamic textbox as you type.
    I already have this
    Actionscript Code:
    stop();


    var texto:String;


    textobtn.onPress=function(){
        if(texto!=""){
           
                   
    textoMC.texto=texto;
    gotoAndPlay(2);

    }
        else {
           
            trace("textbox is empty");
           
        }
    };

    But it only shows when you press a button.

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    you can do something simple like this perhaps.

    Actionscript Code:
    myTextField.onChanged = function(){
    //your function here.
    }

  3. #3
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Hahaha! Just the script that i tested yesterday, but failed.

    Actionscript Code:
    texto.onChanged=function(){
     textoMC.texto=texto;
    }

    "There is no property with the name 'onChanged' "

  4. #4
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Here is a little example for you to test the onChanged property

    Actionscript Code:
    var total = 50;// Set amount
    myDynamic.text = "Remaining : " + total;// Dynamic textField
    myInput.text = "";// Input textField
    myInput.maxChars = total;// Restrict to same as total var
    myInput.onChanged = function(textField)
    {
        myDynamic.text = "Remaining : " + (total - myInput.text.length);
        // Show remaining number each time changed
    };

    .

  5. #5
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Ok, i understand it well, but one thing, and thanks for everything.

    I'm using variable name instead of instance name, because if i use instance name, the color of my input textbox is transferred (weirdly) to my dynamic textbox. I tried specifying my textboxes colors
    Actionscript Code:
    myInputTextbox.text.TextField.color="#FFFFFF";

    myDynamicTextbox.text.TextField.color="#003366";

    But failed. So i thought "mmm variable names?" and it worked. But the onChanged seems does not work with variable name...

  6. #6
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Okay! Done.

    Actionscript Code:
    stop();


    texto.onChanged=function(){
        textoMC.texto=texto.text;
    }

    textoMC.texto.text=""

    textobtn.onPress=function(){
        if(texto.text!=""){
           
                   
           
    textoMC.texto=texto.text;
            gotoAndPlay(2);
        }
        else {
           
            trace("ok no hay nada");
           
        }
    }

    Used Instance Name again and it magically worked. Thanks

  7. #7
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    I see you managed it!!!


    Dcolor = 0x333333;
    Icolor = 0x800800;

    myDynamicTextbox.textColor = Dcolor;
    myInputTextbox.textColor = Icolor;

    var total = 50;// Set amount
    myDynamicTextbox.text = "Remaining : " + total;
    myInputTextbox.text = "";
    myInputTextbox.maxChars = total;
    myInputTextbox.onChanged = function(textField)
    {
    myDynamicTextbox.text = "Remaining : " + (total - myInputTextbox.text.length);
    myInputTextbox.textColor = Icolor;
    myDynamicTextbox.textColor = Dcolor;
    };
    Last edited by fruitbeard; 07-16-2012 at 10:47 AM.

  8. #8
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Thanks for the color textbox function is really great and I will surely need it later

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center