A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: How to trim text in flash MX for case sensitive inputs?

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    3

    How to trim text in flash MX for case sensitive inputs?

    Ok so I proposed a Translator system to my Thesis Project using this Tutorial: http://www.webdesign.org/flash-swish...tor.11073.html

    But I need to find a way for the inputs to be not "case sensitive" like when I input "eat" and Eat" only the "eat" text will be translated.

  2. #2
    Senior Member Steven FN's Avatar
    Join Date
    Mar 2010
    Location
    CA, USA
    Posts
    276
    You would use toLowerCase();

    Code:
    var str:String = " JOSÉ BARÇA";
    trace(str.toLowerCase()); // josé barça

  3. #3
    Registered User
    Join Date
    Sep 2012
    Posts
    3
    Thanks for the reply mate.

    I'm a bit new about this program thing so where do I put that code?

    The code looks something like this:

    bTranslate.onPress = function()
    {
    var sInput = tIn.text; //Gets the text from the first text field.
    sInput = translate(sInput); //Goes through the translator.
    tOut.text = sInput; //Sets the second text field to the translated text.
    }
    function translate(sInput)
    {
    //This is where you add how you want your text changed.
    //It should be in the format of
    //sInput = searchAndReplace(sInput, What you want changed, What you want it changed to);
    //Remember to use quotes around the text you are changing.
    sInput = searchAndReplace(sInput, "why", "y");
    sInput = searchAndReplace(sInput, "you", "u");
    sInput = searchAndReplace(sInput, "are", "r");
    sInput = searchAndReplace(sInput, "for", "4");
    sInput = searchAndReplace(sInput, "to", "2");
    return sInput;
    }
    function searchAndReplace(a, b, c) //Searches string a for b and replaces it with c
    {
    tmp = a.split(b); //Splits a into an array of values where b is.
    a = tmp.join(c); //Joins them back together with c seperating them.
    return (a); //Returns the changed string.
    }

  4. #4
    Registered User
    Join Date
    Sep 2012
    Posts
    3
    I don't where to put the code... please help. Do I do it with all the words inside? Cause it has less than 1000 words.

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

    Try this instead.

    have an input textfield called "myInputText"

    Code:
    function SetText(A, B)
    {
    	var Search = A;
    	var Replace = B;
    	var ReWrite = myInputText.text.split(Search);
    	for (i = 0; i < myInputText.text.length; i++)
    	{
    		myInputText.text = ReWrite.join(Replace);
    	}
    }
    
    function ChangeText()
    {
    	var A1:Array = ["why", "you", "are", "for", "to"];
    	var A2:Array = ["y", "u", "r", "4", "2"];
    	for (j = 0; j < A1.length; j++)
    	{
    		SetText(A1[j].toLowerCase(),A2[j]);
    		SetText(A1[j].toUpperCase(),A2[j]);
    	}
    }
    
    myInputText.onChanged = function(textField)
    {
    	ChangeText();
    };
    That works fine if it is either upper or lower case, but not a mixture (FoR , wHY, WhY)

    my hobby

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

    To answer your question

    this does the trick.

    Code:
    var sInput = myInputText.text.toLowerCase(); //Gets the text from the first text field.;
    but i was also wondering if anybody could fix my thing and make it case insensitive too.

    Thanks
    Last edited by fruitbeard; 09-05-2012 at 09:00 AM.

  7. #7
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Code:
    var sInput = tIn.text.toLowerCase(); //Gets the text from the first text field.

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