Access Stage object (textbox) within a Custom Class
-
11-04-2021 - |
Question
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);
}
}
}
}
Solution
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";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow