10 Replies Latest reply on Mar 26, 2013 6:01 AM by moccamaximum

    Newbie Problem


      I have been working on a extremely simple translator, with a template my friend has provided me with. Though I have quickly run into an issue, though it is the only issue, it is a severe one.


      This is sections of my code;


      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)


      sInput = searchAndReplace(sInput, "hello", "achuta");

      sInput = searchAndReplace(sInput, "a", "do");

      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.




      There is more to it, but it's to long to post everything, regardless this leads to a good example.


      So in my translator I would type Hello, which would then turn out the word, "Dochutdo" This is because the A's in Achuta are being converted by another word translation. I have been digging around but have not been able how to make this match case sensitive due to my lack of knowledge. I went around on the internet but couldn't find anything helpful in my case.


      Does anyone know what I would have to change about this code in order to make all these words case sensitive to not effects letters individually within other words?

        • 1. Re: Newbie Problem
          Ned Murphy Adobe Community Professional & MVP

          Your queston at the end of your description is not clear to me.  Can you give an example that demonstrates what you do/don't want.

          • 2. Re: Newbie Problem
            Mallind Level 1

            Alrighty, I have trouble to clarify this, but I'll try.

            Another example, would be this.

            English > Random Translation


            But Butch, we can't!


            But is translated to Av

            Butch is translated to Ian


            Now, because Butch has 'But' in the name, it will falsely translate Butch to (Av)Ian. I am trying to prevent this.


            What I am trying to learn is how to make my code more sensitive to word placement so it HAS to be its own word.


            A great way to see this sort of thing is CTRL+F and search for "But" you'll see butch can be partially highlighted if you don't have match case on.

            • 3. Re: Newbie Problem

              The best way to do that is with regular expressions.


              You can pass a regular expression to String.split instead of an actual String and you can make that case insensitive.


              Here is a good article:




              Let me know if you need further explanation.

              • 4. Re: Newbie Problem
                Ned Murphy Adobe Community Professional & MVP

                I don't see where the case comes into play in your problem.  If you want to test the whole word then do that and don't test for portions of it. 


                As2 does not support regular expressions in case you are trying to chase that down.

                • 5. Re: Newbie Problem
                  Nabren Level 3

                  Ah, dang. I need to learn more about AS2 - I figured it would have had at least that much. Ignore my post then, haha!

                  • 6. Re: Newbie Problem
                    Mallind Level 1

                    As I said it's a translator, so these words are completely different entities.

                    A is translated to "Do"

                    and Hello is Achuta


                    This is my .SWF



                    Basically since this is a translator, when you type a sentance like hello there, it translates to "dochutdo bure" However, this is supposed to ACTUALLY translate to "achuta bure"

                    So the issue is that if one of the words to be translated is within another word IE; (but)ch, or (a)chut(a), it will not only translate the word once to the precise word I need. It will also translate the words within the translation itself.


                    If it was match-sensitive, the translated term "Do" would ONLY appear if "A" was alone and was not part of a word. Example of what I want;  hello a  >> achuta do

                    However, due to the translation of string a to do, it forms the entire translation to go haywire, resulting in; hello a >> dochutdo do


                    I'm not trying to test portions, I'm trying to create a translator you type into and it translates back.


                    By the way, thanks for the help thus far. To summarize, the primary issue is that it's translating words within other words, when I want them to be treated as seperate entities.

                    • 7. Re: Newbie Problem
                      Nabren Level 3

                      Yep, regular expressions are perfect for what you are trying to do - just too bad you can't use them. Unless you are able to use AS3?

                      • 8. Re: Newbie Problem
                        Mallind Level 1

                        I am using Macromedia Flash MX, so I don't believe I am able to code in AS3, I looked at the site, though to be honest. I have alot of trouble finding what I am looking for.

                        Is there simply no way to make FLA coding find a distinct difference between a full string and a partial then? Am I forced to use AS3?

                        • 9. Re: Newbie Problem
                          Ned Murphy Adobe Community Professional & MVP

                          I still do not see where case fits into the scheme.  I also do not understand the logic behind what you are doing where you first translate to what you want and then you take what you translated and translate it again.  I think the problem you might be having is in your own reasoning of what the translator is trying to do.


                          If hello gives you achuta, why do you then take achuta and translate it again... it is already translated  ?

                          1 person found this helpful
                          • 10. Re: Newbie Problem
                            moccamaximum Level 5

                            your problem lies in this line:


                            tmp = a.split(b)


                            what you want to do is separating the words from each other by using the the space betweeen them:


                            tmp= a.split(" ");


                            now you have each word in an array, now go throw this array and have a lookuptable for the corresponding translations,


                            var language1 = ["hello","a"];

                            var language2 = ["achuta","do"];


                            function translateFromTo(_input,_language1,_language2){

                              tmp = _input.split(" ");

                            //this will be the text in your outputwindow

                              result = "";

                            //if you input "a hello a" this will give you an array of ["a","hello","a"]

                            for (var i=0;i<tmp.length;i++){

                            index1 = _language1.indexOf(tmp[i]);

                            result += language2[index1]+" ";


                            return result;



                            trace(translateFromTo("a hello a",language1,language2));

                            //do achuta do