Copy link to clipboard
Copied
I am new to Flash and ActionScript 3 and have been struggling with this all day and searched forums, tutorials and everywhere, but unable to solve my problem.
In my fla I have 3 frames.
In flame 3: I have 9 movieclips. On mouse click each movieclip loads text into a dynamic text field with the instance name ‘object_txt’. In the xml, each text has a section with the same name as the movieclip it belongs to (like this: <object1_mc>). This works perfectly, and all the texts are loading.
The code:
// Load text for the objects
object_txt.styleSheet = css;
stage.addChild(object_txt);
object_txt.htmlText = langData[language][objectPressed.name];
Now here is my problem:
In frame 2: I want to load a section from the same xml into a text field with the instance name of ‘history_txt’ when I enter this frame (only in this frame)
The section in the xml has the section name: <history_txt>
I have the URL loader in frame 2:
// URL loader for texts:
var urlr:URLRequest = new URLRequest("local.xml");
var loader: URLLoader = new URLLoader(urlr);
loader.addEventListener(Event.COMPLETE, completeHandler);
var langData:XML;
function completeHandler(event: Event): void
{
var loadedText: URLLoader = URLLoader(event.target);
langData = new XML(loadedText.data);
}
// Make a stylesheet for texts:
var css: StyleSheet = new StyleSheet();
css.parseCSS('h1 { color: #99CCFF; font-weight: bold; font-size: 68px; } p {font-size: 30px;}');
stage.addChild(history_txt);
history_txt.styleSheet = css;
history_txt.htmlText = langData[language] ? ; // I don’t know how to get the section from the xml
Could someone help me with this? Any help would be appreciated!
Copy link to clipboard
Copied
you should only be loading your xml file once using:
function completeHandler(event: Event): void
{
langData = XML(event.target.data);
}
then to solve your problem we'd need to understand your xml setup. if done the way you've explained you should be using
history_txt.htmlText=langData['history_txt'][event.currentTarget]; // assuming a mouseevent triggers the text displayed as indicated in your description.
or more generally,
var section:String='history_txt';
history_txt.htmlText=langData[section][event.currentTarget];
but your explanation is incomplete and there's no way to know if that's correct.
to fix your setup, show the enough lines of your xml file to understand how it's organized
Copy link to clipboard
Copied
Thanks for trying to help me, kglad.
The text in frame 2 should not load on mouseevent, but be visible when you enter this frame. (It is the text in frame 3 that loads on mouseevent, and that is working fine.)
I made an example of how the xml (local.xml) is organized (I just removed the texts for most of the movieclips). The first section - <history_txt> ... </history_txt> should be loaded in history_txt in frame 2 (the others are loading fine in frame 3):
<?xml version="1.0" encoding="UTF-8"?>
<data>
<en>
<history_txt>
<![CDATA[
<h1>bla bla</h1>
<p>bla bla</p>
]]>
</history_txt>
<coffee_mc>
<![CDATA[
<h1>bla bla</h1>
<p>bla bla</p>
]]>
</coffee_mc>
<keg_mc>
<![CDATA[
<h1>bla bla</h1>
<p>bla bla</p>
]]>
</keg_mc>
<rope_mc>
<![CDATA[
<h1>bla bla</h1>
<p>bla bla</p>
]]>
</rope_mc>
</en>
<no>
<history_txt>
<![CDATA[
<h1>bla bla</h1>
<p>bla bla</p>
]]>
</history_txt>
<coffee_mc>
<![CDATA[
<h1>bla bla</h1>
<p>bla bla</p>
]]>
</coffee_mc>
<keg_mc>
<![CDATA[
<h1>bla bla</h1>
<p>bla bla</p>
]]>
</keg_mc>
<rope_mc>
<![CDATA[
<h1>bla bla</h1>
<p>bla bla</p>
]]>
</rope_mc>
</no>
</data>
Copy link to clipboard
Copied
from the looks of that, you should have a language variable:
var language:String; // and somewhere you assign language='no' or language='en';
history_txt.htmlText=langData[language].history_txt;
Copy link to clipboard
Copied
Yes, I do have a language variable in frame 1:
var language: String;
In frame 1 I also have the movieclips representing the different languages e.g.
function playcoast(event: MouseEvent): void
{
language = "en";
(more code here)
}
I already tried your suggestion ( history_txt.htmlText=langData[language].history_txt; ) but it doesn't work...
Copy link to clipboard
Copied
use the trace function to see what you're doing wrong.
make sure langData has not been redefined (eg, var langData:XML=new XML()),
and make sure language has not been redefined.
Copy link to clipboard
Copied
Hmmm - I am tracing, and get "langData: null" in the consol. Why?
The text in frame 3 is loading, so I don't understand?
Copy link to clipboard
Copied
again, you should ONLY load once. re-read message 1.
Copy link to clipboard
Copied
It is only loaded once.
Copy link to clipboard
Copied
there's some code somewhere after the initial load that's doing something like:
langData=new XML()
i can't see your file to determine exactly what you're doing wrong, but you're doing something to cause that problem. if you just had langData defined on frame 1 and never redefined it, it would still be defined on the other frames on your timeline.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more