Skip to main content
Known Participant
January 17, 2013
Answered

How can I put Locale.loadString("IDS_001") into button.label

  • January 17, 2013
  • 1 reply
  • 2346 views

I am retrieving the Locale from the system, and need to place the fields of the Array into their respective places.

One of these being for example,


IDS_001

This works, and returns what I'd probably expect. Although why it returns multiple instances I can't yet figure.

          public var vIDS_001:String;

          Locale.autoReplace = true;
           
                 var localeName:String = LocaleID.DEFAULT;
                 var nf:StringTools = new StringTools(localeName);
                               trace("Actual local ID: " + nf.actualLocaleIDName);
           var defLang:String = nf.actualLocaleIDName;          
                                          trace( "Last Operation Status: " + nf.lastOperationStatus );  
                    
           Locale.setDefaultLang(defLang);
           Locale.setLoadCallback(localeCallback);
           //Locale.addXMLPath("defLang", "../en/PinPointPremium_en.xml");
                      Locale.addXMLPath("defLang", "../" + defLang + "/PinPointPremium_" + defLang + ".xml");
           
           function localeCallback(success:Boolean) {
            if (success) {
                // trace(Locale.stringIDArray); // IDS_GREETING
                 trace(Locale.loadString("IDS_001"));
                 var vIDS_001 = (Locale.loadString("IDS_001"));
                 trace("+++" + vIDS_001);
            } else {
                 trace("unable to load XML");
            }
           }


Actual local ID: en-GB
Last Operation Status: noError
PinPoint the Entered Address
+++PinPoint the Entered Address
PinPoint the Entered Address
+++PinPoint the Entered Address
Test Movie terminated.

This is the button code, and I'm trying to figure out how to get that IDS_001 information into the btnGPS.label. No matter what I try, it errors out

             btnGPS = new Button();
          btnGPS.width = stage.stageWidth - 20;
          btnGPS.height = 25;
          btnGPS.x = 10;
          btnGPS.alpha = 0.9;
                // btnGPS.label = "PinPoint My Current Location";
          btnGPS.setStyle("textFormat", btnFormat);
          btnGPS.y = stage.stageHeight - 46;
          btnGPS.addEventListener(MouseEvent.CLICK, btnGPSMouseClickHandler);
          addChild(btnGPS);

None of these following work in place of the original

          
                //btnGPS.label = Locale.loadString("IDS_001");
          //btnGPS.label = IDS_001;
                //btnGPS.label = vIDS_001;

Theoretically, loading the Locale XML file should populate the occurences of IDS_001 - but I'm totally lost now. Been looking at this for a few days and now can't see the real picture. Does anyone have any idea how I solve this please ... I know this is so simple, but I can't get it.

thanks

This topic has been closed for replies.
Correct answer moccamaximum

ok, I need to get back on track.

The app works and is fine. No problem with buttons etc. It's localization.

.... and this works - finally

//*************************************

private static var loc:String = null;

private static var my_txt:String = null;

//***************************************************************

// Checking for LocaleID for globalization.

// Localization stuff. AS3 2013. (using latest CS6 Flash Pro, AIR and Flex SDK libraries)

// This example is based on the iPhone/iPad, iOS Template in CS6

                              // get the system language. That's al lwe need. What language is the user using

                              loc = Capabilities.language;

                              // if it's en-GB for example, make en_GB

                              // loc = loc.replace("-","_");

                              trace("The default system: " + loc);

                              loc = "de";

                              trace("The new system: " + loc);

                              // you can add individual paths for each language like this

                              Locale.addXMLPath("en", "en/PinPointPremium_en.xml");

                              Locale.addXMLPath("de", "de/PinPointPremium_de.xml");

                              // or set your language to the system default and use that

               // I put the system language into 'loc'

                              Locale.addXMLPath(loc, loc + "/PinPointPremium_" + loc + ".xml");

                              Locale.setLoadCallback(localeCallback);

                              Locale.loadLanguageXML(loc);

                                        function localeCallback(success:Boolean) {

                                                  if(success){

                                                            //var my_txt:String = Locale.loadString("IDS_001");

                                                            my_txt = Locale.loadString("IDS_001");

                                                            trace("The IDS_001 field is: " + my_txt);

                                                            // returns "PinPoint der eingegebenen Adresse" which is ok

                                                            } else {

                                trace("unable to load XML");

                      }

                                        }

/* Output

The default system: en-GB

The new system: de

The IDS_001 field is: PinPoint der eingegebenen Adresse

*/

Part 2 is the Button. AND is is this that is tricking me.

I repeat - how do I put the contents of IDS_001 into btnGPS.local with

IF I can put 'loc' into the label, with

btnGPS.label = loc;

why can't I do this

btnGPS.label = Locale.loadString("IDS_001");

//**************************************

btnGPS = new Button();

btnGPS.width = stage.stageWidth - 20;

btnGPS.height = 25;

btnGPS.x = 10;

btnGPS.alpha = 0.9;

//btnGPS.label = "PinPoint My Current Location";

// ==============================================

// This actually works - it places "de" into the button. as it should

  btnGPS.label = loc;

// this doesn't put the contents into the label

//btnGPS.label = Locale.loadString("IDS_001");

btnGPS.setStyle("textFormat", btnFormat);

btnGPS.y = stage.stageHeight - 46;

btnGPS.addEventListener(MouseEvent.CLICK, btnGPSMouseClickHandler);

addChild(btnGPS);

//********************************


I tested this:

Locale.setLoadCallback(localeCallback);

Locale.loadLanguageXML("en");

function localeCallback(success:Boolean):void

{

    if (success)

    {

        btn.label = Locale.loadString("IDS_001");

    }

    else

    {

    }

}

and it works for me, with a buttoncomponent named "btn" on stage.

The moment I take this line out of the callback-function I get the same errors as you:

TypeError: Error #2007: Parameter text must be non-null.

    at flash.text::TextField/set text()

    at fl.controls::LabelButton/set label()

1 reply

Inspiring
January 17, 2013

matter what I try, it errors out

What are the errors you are getting?

Known Participant
January 17, 2013

I have made a few minor changes,

But essentially the same. With just btnGPS.label = IDS_001; I get the following ( the btnGPS.label is on line 405, and the IDS_001 is declared as a public string in  the declarations section.

null
TypeError: Error #2007: Parameter text must be non-null.
     at flash.text::TextField/set text()
     at fl.controls::LabelButton/set label()
     at PinPointPremium()

If I use this:  btnGPS.label = Locale.loadString("IDS_001");  I get the same.

If I comment out the btnGPS.label entirely, the movie runs fine and completes. The slightly modified code is below this output. ---- and why the thing is outputting the output twice I don't know either. What a mission this is turning out to be.

null
IDS_023,IDS_003,IDS_020,IDS_017,IDS_014,IDS_002,IDS_005,IDS_021,IDS_024,IDS_007,IDS_009,IDS_011,IDS_019,IDS_001,IDS_012,IDS_013,IDS_018,IDS_015,IDS_004,IDS_016,IDS_006,IDS_022,IDS_010,IDS_008
PinPoint the Entered Address
+++PinPoint the Entered Address
Two instances of IDS_001
IDS_023,IDS_003,IDS_020,IDS_017,IDS_014,IDS_002,IDS_005,IDS_021,IDS_024,IDS_007,IDS_009,IDS_011,IDS_019,IDS_001,IDS_012,IDS_013,IDS_018,IDS_015,IDS_004,IDS_016,IDS_006,IDS_022,IDS_010,IDS_008
PinPoint the Entered Address
+++PinPoint the Entered Address
Two instances of IDS_001

=========================

          Locale.autoReplace = true;
           
         var localeName:String = LocaleID.DEFAULT;
         var nf:StringTools = new StringTools(localeName);
                    //trace("Actual local ID: " + nf.actualLocaleIDName);
           var defLang:String = nf.actualLocaleIDName;          
                  //trace( "Last Operation Status: " + nf.lastOperationStatus );  
                    
           var i:Number;  
           Locale.setDefaultLang(defLang);
           Locale.setLoadCallback(localeCallback);
 
           Locale.addXMLPath("defLang", "../" + defLang + "/PinPointPremium_" + defLang + ".xml");
           

                 trace(Locale.loadString("IDS_001"));
          
           function localeCallback(success:Boolean) {
            if (success) {
                trace(Locale.stringIDArray); // IDS_GREETING
                 trace(Locale.loadString("IDS_001"));
                 IDS_001 = (Locale.loadString("IDS_001"));
                 trace("+++" + IDS_001);
                 trace("Two instances of IDS_001");
            } else {
                 trace("unable to load XML");
            }
           }
           

Inspiring
January 17, 2013

Make sure you follow the instructions how to set up your String Table to the letter:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl/lang/Locale.html

Better, even: post a screenshot of the table, with the ID IDS_001 visible and the Options Window open.

In german it looks like this: