How can I change the language of dynamic text in a SWF using flashvars?
I have a SWF with text embedded from an external .txt file. Is there a way I can have a different file used as the text source through the embedcode (swfObject) depending on the language?
Here is my current actionscript:
myData = new LoadVars();
myData.onLoad = function() {
text_clips.project_title.text = this.projecttitle1;
};
myData.load("translatetext.txt");
var loader:MovieClipLoader = new MovieClipLoader();
loader.loadClip(_level0.projectimage1,pic1.image_holder);
This is the content of translatetext.txt:
projecttitle1=This is my translatable text
This is the embed code I'm using:
<div>
<object width="960" height="275" id="rvFlashcontent">
<param name="movie" value="lang_test_3.swf" />
<param name="wmode" value="transparent" />
<param name="flashvars" value="projectimage1=flashimages/testimage.jpg" />
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="lang_test_3.swf" width="960" height="275">
<param name="wmode" value="tra开发者_StackOverflow社区nsparent" />
<param name="flashvars" value="projectimage1=flashimages/testimage.jpg" />
<!--<![endif]-->
<h1>Alt Content</h1>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>
</div>
What I want to do is add a Flashvars parameter to name the file to load, so I can change the language:
<param name="flashvars" value="projectimage1=flashimages/image.jpg&projecttext=textfrench.txt" />
There are four languages needed so far, but this will grow so it needs to be flexible enough to let the developers add languages without getting a new SWF each time. Thanks in advance all!
Files for this question available here...
I'm not sure if you're asking how to access flashvars or how to handle multiple languages, but assuming it's the former, you can get at flashvars like so:
protected function init():void
{
var flashvars:Object = LoaderInfo(root.loaderInfo).parameters;
var myDataLoader:URLLoader = new URLLoader();
myDataLoader.addEventListener(Event.COMPLETE, onDataLoadComplete);
myDataLoader.load(new URLRequest(flashvars.projecttext));
}
protected function onDataLoadComplete(e:Event):void
{
var myDataLoader:URLLoader = URLLoader(e.target);
var myData:Object = myDataLoader.data;
// now you can do whatever you want with the contents of the file (i.e. myData)
}
== Edit ==
You need to add an event listener that will fire when the load is complete. I've edited my pseudo code above as an example...
精彩评论