Loading XML data into dynamic text field using a class

Hi,

I’m quite new to ActionScript and would be grateful for any help here.

I want to load text into a dynamic text field (called ‘about_tab’) using a class depending on the language selected (by clicking on a flag icon) by the user.

I managed to get this to work when the ActionScript was written directly in the timeline, but am having problems with doing the same thing via a class.

This is my class file:


package
{
import flash.display.SimpleButton;
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.Event;

public class ChangeLang extends SimpleButton
{
    public function ChangeLang()
    {
        addEventListener(MouseEvent.CLICK, switchLang);
        trace("ChangeLang class working");
    }
    
    public function switchLang(event:MouseEvent):void
    {
        var lang = event.target.name;
        var req:URLRequest = new URLRequest("languages/"+lang+".xml");
        var loader:URLLoader = new URLLoader();
        var substance:XML;
        
        function xmlLoaded(event:Event):void
        {
            trace("function xmlLoaded is running");
            substance = new XML(loader.data);
            [COLOR=Red]about_tab.text[/COLOR] = substance.about_lbl;
        }

        loader.addEventListener(Event.COMPLETE, xmlLoaded);
        loader.load(req);
    }
}

}


Here’s one of my XML files (the other is the same except “About” is written in German):


<substance>
<about_lbl>About</about_lbl>
</substance>


When I run it, it returns my trace statements that the class ChangeLang and the function xmlLoaded are running, but no text appears in the dynamic text field (I should/want to see the word ‘About’). I get this error message:

[COLOR=Red]1120: Access of undefined property about_tab[/COLOR]

The problem, I’m guessing, is in the part in [COLOR=Red]red[/COLOR] in my code. Do I need to declare the dynamic text field as a variable or something? I guess there’s something really simple I’m missing, so I apologize if this comes across as a stupid question :puzzled:

Thanks for any help.