Copy link to clipboard
Copied
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
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/
...Copy link to clipboard
Copied
matter what I try, it errors out
What are the errors you are getting?
Copy link to clipboard
Copied
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"); } }
Copy link to clipboard
Copied
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:
Copy link to clipboard
Copied
Some other odd things caught my eye:
In one of your versions you declared a public variable:
public var vIDS_001:String;
but all the other functions and variables have no indication of visiblility (public, private,protected etc.). Normally Flash wouldn`t allow you tho place such code on the timeline.
In the same file you are then using:
var vIDS_001 = ....
later I see you corrected that mistake and wrote
vIDS_001 =....
but now the
var vidS:String has vanished
(this is what causes the message "Two instances of IDS_001" and probably why the code runs two times)
Copy link to clipboard
Copied
Hi, thanks
Ignore the vIDS_001 trace - trhat was just testing.
This is all the code and produces the output below it
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.autoReplace = true; Locale.setDefaultLang(defLang); Locale.setLoadCallback(localeCallback); Locale.addXMLPath("defLang", "../" + defLang + "/PinPointPremium_" + defLang + ".xml"); function localeCallback(success:Boolean) { if (success) { //trace(Locale.stringIDArray); // prints the array trace(Locale.loadString("IDS_001")); // prints the contents of 001 IDS_001 = (Locale.loadString("IDS_002")); trace("+++" + IDS_001); // prints the contents of 001 //trace("Two instances of IDS_001"); } else { trace("unable to load XML"); } }
Output
PinPoint the Entered Address +++Address, City, State, Zip or Latitude,Longitude PinPoint the Entered Address +++Address, City, State, Zip or Latitude,Longitude [UnloadSWF]
So obviously I'm doing something completly wrong. Are the codes loaded by the fla? or do they have to be loaded by the as script?
And why can I not get the output into btnGPS.lable ??? at all
I would think if I can get an out put from trace, and from putting it into a string variable, I should be able to populate the label, as that is only a string as well. hmmmm what a mystery.
Copy link to clipboard
Copied
In your settings window change the Replace strings option from "automatically at runtime" to "via Actionscript at runtime".
Copy link to clipboard
Copied
Are the codes loaded by the fla? or do they have to be loaded by the as script?
And why can I not get the output into btnGPS.lable ??? at all
You will notice the moment you save your fla, that Flash creates a folder in the same directory for every language you use.
All these folders, with the xml inside them have to be at the exact location where you publish the swf.
And they must also be put on the server, where you put your swf.
They are not magically remembered or compiled into the swf
Copy link to clipboard
Copied
If you plan to publish your application on the web, the locale will not help you much to get the users language.
It will only work if the swf runs actually on the users machine, not on your server.
Getting a default language inside a browser is a little more complicated, as you see here.
Copy link to clipboard
Copied
I'm trying to Locale'ize an app I have on the iPhne/iPad, so picking up the users current Local is relatively easy.
The app already runs and is in the app store, however I am now upgrading it for other languages.
The only thing the Stage is used for - the .fla file - is to hold the objects like Button, and an embedded font I use for a particular thing. It has no time line, just acts as a 'stage' to put a background image on, and then AS3 generates the buttons and a couple of stageWebViews.
To that end it uses no flash.
It works fine - so we can disregard al lthat.
Now the basic problem, is that I don't seem to be able to put the contents of IDS_001 etc into the label of btnGPS.label
I can trace it - it's obviously a string - so why can't I save it and then put it into a .label ... so basic, yet I can't remember it, or find an example.
Copy link to clipboard
Copied
Since I don`t know the specifics of your fla file at this point I must assume the following:
1.you have the right imports for your Button (since there are multiple Button classes, for instance if you have installed starling Flash will try to import starling.display.Button, not fl.controls.Button)
2.you have not wrote an own Button Class that overrides the default behaviour of the fl.controls.Button but merely styling the original one
3.You have the necessary component in your library
Try this:
Make an empty fla, drag a Button Component from the components panel on the stage and name it "btnGPS"
then add this actionscript code on the first timelineframe:
import fl.controls.Button
var btnGPS:Button = new Button();
btnGPS.width = stage.stageWidth - 20;
btnGPS.height = 25;
btnGPS.x = 10;
btnGPS.alpha = 0.9;
btnGPS.label = "PinPoint My Current Location";
btnGPS.y = stage.stageHeight - 46;
addChild(btnGPS);
compile it, and you see what happens:
The moment you create a Button via Actionscript with the same instance name, Flash completely ignores the Button with the same name that is already on stage.
It gets no label, no x,y,z-treatment whatsoever.
This is the last explanation that I can think of: somehow you have a second Button on stage that gets overriden by your Actionscript.
Copy link to clipboard
Copied
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);
//********************************
Copy link to clipboard
Copied
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()
Copy link to clipboard
Copied
Thanks for that. It works a treat. Got me going in the right direction at last.
Copy link to clipboard
Copied
http://forums.adobe.com/message/4998631#4998631
Still struggling with this after all ...
Find more inspiration, events, and resources on the new Adobe Community
Explore Now