Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The problem is you have a callback for the textLoaded, but you aren't waiting for it to load, before you call the getter(). Try this first:</p> <pre><code>public function get getter():String { if(test) { return test.questionText; } else { return "Data not available"; } </code></pre> <p>but you can also pass a function reference to the Question class to pass the value back when it's loaded. You might want to think about preloading the questions in any event.</p> <pre><code>public class Question extends Sprite { private var test:String; private var callback:Function; public function Question(_callback:Function) { this.callback = _callback; // xml var urlReq:URLRequest = new URLRequest("./files/multiplechoice.xml"); var urlLoad:URLLoader = new URLLoader(); urlLoad.addEventListener(Event.COMPLETE, textLoaded); urlLoad.load(urlReq); } private function textLoaded(e:Event):void { urlLoad.removeEventListener(Event.COMPLETE, textLoaded); XML.ignoreWhitespace = true; var xml:XML = new XML(e.target.data); // check if loaded this.callback(xml); } } // in the main class private function multiHandler(e:MouseEvent):void { // if button clicked make a Question object var q:Question = new Question(this.questionCallback); } public function questionCallback(xml:XML):void // get the value from the xml var tField:TextField = new TextField(); tField.text = &lt;&lt;parsed xml....&gt;&gt;; container.addChild(tField); } </code></pre> <p>You might want to make the textfield and question class properties and not keep the scope local to the functions so you access to them as well.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload