PDA

View Full Version : Text loaded from an XML file dissapears when the text is animated



ChillDown
December 20th, 2008, 10:16 AM
I've loaded a text from an .xml file into a flash animation. The .xml file
can contain different translations of the text in several languages.
However during development the text is initially written in English inside flash. Once the language.xml file is loaded the text changes into the proper language.

The .xml file is loaded through a document class script.

The problem is though, as soon as i start to animate the text, to move it, then the text loses its translation which it loaded from the xml file and reverts back to the initial english text.

I'd like to know how to fix this, but i don't know why it happens in the first place.

Here's the document class, which loads the translation from the xml file into the text. Not sure if the document class script is even the problem though, because it works initially. The problem starts when animating the text.



package {
import flash.display.*;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.*;
import flash.text.TextField;

public class LoadLanguage extends MovieClip {
private var languageText:XML;

public function LoadLanguage() {
loadLanguageFile();
}

public function loadLanguageFile() {
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("language.xml");
loader.addEventListener(Event.COMPLETE, completeLoadingLanguageFile);
loader.load(request);
}

public function completeLoadingLanguageFile(event:Event) {
var loader:URLLoader = URLLoader(event.target);
languageText = XML(loader.data);
replaceText();
}

public function replaceText(){
weat.text = languageText.website.indexPhp.flashElement.frame5. weAt;
}
}
}

ChillDown
December 21st, 2008, 04:05 AM
Could it be that the text reverts back to the initial english text, because the xml file is loaded only once at the beginning because it's being done in the document class?

Because when i animated the text i use the keyframes with the english text. However, i thought that once the translation from the xml file has been injected into the text-objects that should be the end of it, causing the text to stay translated even during animation. Yet this seems not the case. It almost looks as if i have to inject the translated text into the text objects every time i set a keyframe for that text. But isn't that tedious? I'm sure i'm doing something wrong and have overlooked something. I'm not sure what to do to fix it.

EViL-Bites
December 21st, 2008, 04:28 AM
It would depend on your document setup and the way In which you animated the textfield. Since you animated the textfield on the timeline its quite possible that you've cahnged the text on one instance of the textfield and its being replaced by another instance during the animation. My suggestion is that you use a tweening engine to animate the text its more efficient for simple animations.

A more common problem (which you don't seem to have) is disappearing text which usually means the swf does not contain the glyphs for animating the text. Easily solved by embedding the font in the swf which is unfortunately expensive in terms of size or a better option is using flex to create swf's to act as font libraries with specific character sets and loading them at runtime.

Well that sounds about right I hope it helps :red:

ChillDown
December 21st, 2008, 06:11 AM
I'm not sure if it's being replaced by another instance, i don't think it is, because the instance name of the text is the same throughout the animation. However it somehow seems as if the original text is "remembered" in the following frames and therefor the loaded text from the xml file is then negated or overwritten.

I have thought about creating a new object of the document class in which the xml file is loaded in every frame of the animation. So that when the object of the document class is created, then the xml data is re-loaded and re-injected into the text instance which is being animated.

However i've tried to do this, but i think i did it wrong. As i got an error. This is what i tried in a framescript to accomplish that:

var loadxmlObject:LoadLanguage = new LoadLanguage();

The document class is called LoadLanguage as you can see in the code above. However this didn't work and i have no idea why. The error code i got was:

Error: Error #2136: The SWF file contains invalid data.

ChillDown
December 21st, 2008, 02:33 PM
Here's another throw at the problem.
When you place a dynamic text on the stage and give that text an instance name, then you can easily access that text via instanceName.text right?
However once you start animating that text using a motion tween, then the text suddenly becomes nested in the tween, so instanceName.text wouldn't work anymore, correct?
In order to get it to work i might have to try something like tweenX.instanceName.text = "my xml loaded text;

However i have no idea how to access a tween. A tween has no instance name right, or at least you can't give it one through the property inspector.
So what i want to try now is access the tween through as3 as intended the above example. Does anyone know how to do something like that?

ChillDown
December 21st, 2008, 05:01 PM
I think the issue has been solved. Someone on another forum came up with the solution. I'll post it here too for future reference for other people.

Aparantly the issue was caused due to frames storing the initial text and using that text instead of the text loaded from the xml file to animate the dynamic text.

Now here's the solution. To prevent the loaded text from the xml file to be replaced with the initial text one should place the dynamic text in a movieclip and animate the movieclip rather than the dynamic text itself. Then once it has been animated you can access the dynamic text in the movieclip through AS3 using myMovieClip.dynamicTextInstance.text = textLoadedFromXML;

This way the text loaded from the xml file will not disappear and will not be replaced by the initial text even during animation