0

I'm currently trying to add the resulting XML (xmlResult) to a textbox that is on the stage. I did try using MovieClip(root).[instancename].text = ..... however it didn't work - null object reference? Any suggestions? Thanks!

package  {

public class ChatHistory extends MovieClip {

    public function ChatHistory()
    {
        //constructor
    }
    public function getChatText() {
          var loader:URLLoader = new URLLoader();
          loader.addEventListener( Event.COMPLETE, requestComplete);
          var requestURL:URLRequest = new URLRequest("http://localhost:80/chathistory.xml");
          requestURL.method = URLRequestMethod.GET;
          loader.load(requestURL);
    }

    private function requestComplete( event:Event ):void {
      try {
        var xmlResult:XML = new XML(event.target.data);
        trace(xmlResult);
      } catch ( e:TypeError ) {
          trace(e.message);
      }
    }
}
}    
Jonathan
  • 61
  • 1
  • 6
  • The example of what you tried isn't clear to me, make sure the name is a string: `MovieClip(root).["instancename"].text` – kapex Jan 01 '12 at 22:39
  • I was simply using the [instancename] as a place holder - in the code i used: MovieClip(root).textBox.text = ... – Jonathan Jan 01 '12 at 23:36
  • Alright, I didn't notice that extra dot so I assumed it was the array access operator. You could try using the `stage` property of your movieclip, but in many cases this kind of problem arises by using a wrong name or by trying to access objects like they were properties of the stage when they are only children of the stage. – kapex Jan 01 '12 at 23:46

1 Answers1

0

I tried this and it worked, perhaps this can enlighten you:

import flash.text.TextField;
import ik_fla.MainTimeline;

TextField(MainTimeline(stage.getChildAt(0)).getChildByName('myTxt')).text = "weeee";

or you can avoid imports by using Object cast instead:

Object(Object(stage.getChildAt(0)).getChildByName('myTxt')).text = "weeee";
Fabricio
  • 7,705
  • 9
  • 52
  • 87