# Loading XML data into dynamic text field using a class

**URL:** <https://forum.kirupa.com/t/loading-xml-data-into-dynamic-text-field-using-a-class/309276>\
**Category:** flash\
**Created:** [May 11, 2010, 11:28am UTC](https://forum.kirupa.com/t/loading-xml-data-into-dynamic-text-field-using-a-class/309276 "2010-05-11T11:28:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![flashrocket](https://avatars.discourse-cdn.com/v4/letter/f/3ab097/32.png) [@flashrocket](https://forum.kirupa.com/u/flashrocket)\
**Post date:** [May 11, 2010, 11:28am UTC](https://forum.kirupa.com/t/loading-xml-data-into-dynamic-text-field-using-a-class/309276/1 "2010-05-11T11:28:06Z")

</div>

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.
