Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can instantiate the Snake class file in your intro, using code like the following on frame 100:</p> <pre><code>var game:Snake = new Snake(); addChild(game); </code></pre> <p>assuming your document class is called <code>SnakeGame</code>. You may have to make a few changes in <code>SnakeGame</code> for this to work, however. The <code>stage</code> and <code>root</code> properties of <code>SnakeGame</code> will be null in the constructor when using this method. This is different behavior from it's was the document class (or placed directly on the stage) -- <code>stage</code> and <code>root</code> are already initialized. So if you do any actions to either <code>root</code> or <code>stage</code> in the constructor, you must change this or you will get an error. To fix this, listen for the <code>ADDED_TO_STAGE</code> event in <code>Snake</code>:</p> <pre><code>public function Snake() { addEventListener(Event.ADDED_TO_STAGE, onAddedToStage); } public function onAddedToStage(event:Event):void { removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage); // stage+root are now valid, put your init code here } </code></pre> <p>Alterantively, you could link the <code>Snake</code> class to an empty MovieClip symbol and place that directly on the stage on frame 100. First, create an empty MovieClip by going to Window->Library and clicking the +. In the Create New Symbol dialog, check "Export for ActionScript" and type in <code>Snake</code> in the Class field under Linkage. Now you can drag that MovieClip directly onto the stage on frame 100 and it hopefully will work without changes to the code.</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