Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Most of your ActionScript code must go inside a method; and you have code that must be put in a method. Variable definitions are okay. Import statements are okay. I think some directives, such as include are okay. But, other code must be in a method.</p> <p>This is your annotated code:</p> <pre><code>&lt;fx:Script&gt; &lt;![CDATA[ // this is a variable definition so it is good var xmlLoader:URLLoader = new URLLoader(); // these two lines are code that executes; so they must be put inside a method; something you did not do. Comment them out //xmlLoader.addEventListener(Event.COMPLETE, loadXML); // 1st error here //xmlLoader.load(new URLRequest("books.xml")); // 2nd error here // this is a variable definition so it is okay var xmlData:XML = new XML(); // this is a function definition so it is okay function loadXML(e:Event):void{ xmlData = new XML (e.target.data); } // move your executing code into a method public function load():void{ xmlLoader.addEventListener(Event.COMPLETE, loadXML); xmlLoader.load(new URLRequest("books.xml")); } ]]&gt; &lt;/fx:Script&gt; </code></pre> <p>I bet that removes your errors. However, you'll also want to / need to do something to execute that load method. When you do this depends on how the data is used in your app and the current component. But, I'd probably add a preinitialize event listener:</p> <pre><code>&lt;s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" preinitialize="load()"&gt; </code></pre> <p>If preinitialize doesn't work; I'd move the code to the initialize event. If that doesn't work; I'd go to the creationComplete event. </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