Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To answer the more general question: importing is the preferred way of including external files. In my opinion the <code>include</code> statement should be only used when nothing else will do as it makes things a bit more difficult to debug if something goes wrong and makes code usually more difficult to read and comprehend. Assaf's description of what <code>import</code> and <code>include</code> do is correct.</p> <p>And then for the more specific problem you seem to have: you're probably trying to do the <code>testing.init();</code> right there in the <code>&lt;script&gt;</code> block -- try putting it in a method. You should only have things like <code>import</code> statements and member declarations (variables, functions) directly in the script block and statements like this within functions.</p> <p>You're seeing that error message because when you're calling the <code>init()</code> method of this object, it hasn't been created yet -- that statement will be executed when the definition of the class that your MXML file represents is loaded; what you want is to have it executed when a particular instance of this class has been created, and you can do that by calling it in the constructor of the class (this is, as far as I know, not possible when you're writing a class using MXML, so read on:) or for example in a handler function for the <code>FlexEvent.CREATION_COMPLETE</code> (or <code>creationComplete</code> in terms of MXML tag attributes) event (see the example below.)</p> <p>Try something like this:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="800" height="600" creationComplete="creationCompleteHandler();" &gt; &lt;mx:Script&gt; &lt;![CDATA[ import lib.Journal; public var testing:Journal = new Journal(); private function creationCompleteHandler():void { testing.init(); } ]]&gt; &lt;/mx:Script&gt; &lt;/mx:Application&gt; </code></pre>
 

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