Groups | Blog | Home
all groups > flash actionscript > february 2005 >

flash actionscript : Can you reference a string in ActionScript that is defined in the Strings Panel?


AnnaDegarmo
2/10/2005 9:25:04 PM
Wondering if any one has had any success in referencing a string created in the
Strings Panel in thier ActionScript.

I have a movie that has all it's strings defined in the Strings Panel, I need
to call some of these strings from the movies ActionScript and load them
dynamically into a textbox?

Doe's anyone know how this is done, or if it's even possible?

Thanks in advance!
Dennis, I Sioux
2/10/2005 10:16:17 PM
Hey Anna,

I've been working with the stringpanel aswell for a while i've been figuring
out things like this.. and i've actually just got it working..

so it is possible.. i'm just not sure what way around you have need for...

to get the stringid on the textfield.. so you can look that up in the
stringpanel?
or you want to loop through your string panel and assign every value?

Greetz,

Dennis
I Sioux
www.isioux.nl
AnnaDegarmo
2/10/2005 11:38:54 PM
Hi Dennis, many thanks for your help!

Here's what I'm looking to do...

I have a string panel populated with strings, let's say one of them is:

IDS_TEST Test String

Now if I want to use this string in my ActionScript code as follows:

TextBox.text = IDS_TEST

How do I do that? The line above doesn't seem to work, I know I'm missing
something, but not sure what. :-)

Thanks again for any help!
Dennis, I Sioux
2/11/2005 7:09:29 AM
Hey Anna,

Ah Luckly you'v asked for the easier one of the two :-D..
if you use the string panel.. the strings and if's will end up in an xml,
if the xml is loaded it will be parsed to the "Stringmap", this is a private
object of the "locale" class,
you can open the native file locale.as and make it "unprivate" .. and then you
must add to the fla it should
not load the nativa locale.as but your own.. but you need alitle sentence from
that.. that i ahve at my work.. i'll be going there in 15 min...and will arive
in about 2... so i'll make a litle post to go deeper into this in 2 hours.. :)

Greetz,

Dennis,

I Sioux
www.isioux.nl
Dennis, I Sioux
2/11/2005 9:39:22 AM
I'm at work now.. okee here goess..

-copy the native file called "locale.as" from your macromedia install file..
you will find it in the sub folder "mx"
-next to your fla/swf make a folder called "mx" and copy the "locale.as" in it
-to make sure that your fla grabs your own native file instead of the one in
the install folder you need to go to the publish window.. go to the tab "flash"
and next to the pull down for the actionscript version you are using you ahve
the button "settings" ... push that... then push the "+" button in that window
and a 2 things... one is "." and the other is "$(LocalData)/Classes" (the dot
should be the upper one in the sceme).
-Now your "locale.as" will be found before the original "locale.as" ..
-Because the Stringmap is a private object.. only visible for the locale
class... you need to go into "locale.as".. and in the variable defination at
the top change
privat static var stringMap:Object = new Object();
to
public static var stringMap:Object = new Object();
-Now you can direct to the stringmap... when de xml is parsed to the
stringmap.. it will attach variables.. with the name the same as the string
id's.. and the value the same as the textvalue...
-now you can ask a stringvalue by doing the fallowing....

stringMap = mx.lang.Locale.stringMap;
nameValue = "ID_TEST";
textValue = stringMap[nameValue]
mytextfield_txt.text = textValue ;

That's all there is to it...

Hope this helps.. been searching for answers to these questions for a long
time.. but just found them.. so funny that someone else needs it aswell:)

Best Regards,

Dennis
I Sioux,
www.isioux.nl

AnnaDegarmo
2/16/2005 8:49:21 PM
Hi Dennis,

First of all, many many thanks for all your help, it really is appreciated!

I've tried your solution but haven't been able to get it to work, hopefully
it's something simple I'm doing wrong. I've completed the setup you outlined
then I created a simple test .fla to test the solution, it consists of only 1
actionscript file containing only this:

this.createTextField("tfNewfield",1,10,10,150,30);

stringMap = mx.lang.Locale.stringMap;
nameValue = "IDS_TESTEXTRACT";
textValue = stringMap[nameValue];
tfNewfield.text = textValue;

The project also has a string table in the strings panel that consists of only
one string, here's the XML from the table:

<?xml version="1.0" encoding="UTF-8"?>

<xliff version="1.0" xml:lang="en">

<file datatype="plaintext" original="Untitled-1.fla" source-language="EN">
<header></header>
<body>
<trans-unit id="001" resname="IDS_TESTEXTRACT">
<source>TestTEST</source>
</trans-unit>
</body>
</file>

</xliff>

When I run this .fla where the text should appear I get the text "undefined".
Do I need to tell it to load the XML in the ActionScript? Hopefully I'm just
missing something simple!

Thanks again Dennis for all your help!
Dennis, I Sioux
2/22/2005 10:43:43 AM
hey Anna,

Sorry to get back to you so late... but as far as i can see (with a quick
look)..
i can't see mutch rong here..

so i'm guessing that the good locale.as isn't loaded in(your own one) .. or
that the stringMap isn't changed in the locale.as from private to public ...

what happens when you "ctrl"+shift"+"enter" the fla(run it with the debug
window.. if you play the movie then.. do you see the stringmap in
_global/mx/stringmap

have you done a trace on textValue.. and try to trace you stringMap var.. to
see if it returns [object, object]

..i'll subscribe to this topic .. so i can have a faster reply :)

Best Regards,

Dennis
AddThis Social Bookmark Button