Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You need to listen for the Event.INIT from the class when it is created. (If you are not embedding a symbol using the Embed metatag then Flash takes a few milliseconds to initialize the loaded movieclip). This does not seem to be a problem if the Flash IDE swf/swc does not contain any actionscript)</p> <p>The issue is sometimes it can be really quick, so it fires the INIT event before you get a chance to attach the event listener to the object. so you can't just attach it after you instantiate the object.</p> <p>A work around is to embed the swf as a byte array, then use the loader class to load the embedded bytes (This lets you set the event listener before calling load).</p> <p>e.g.</p> <pre><code>[Embed(source="assets.swf", mimeType="application/octet-stream")] private var assetBytes:Class; private var clip:MovieClip; private var loader:Loader; public function LoadBytesExample() { loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.INIT, onAssetLoaded); loader.loadBytes(new assetBytes()); } private function onAssetLoaded(e:Event):void { var loader:Loader = (e.currentTarget as LoaderInfo).loader; (e.currentTarget as LoaderInfo).removeEventListener(Event.INIT, onAssetLoaded); clip = loader.content as MovieClip; this.addChild(clip); clip.someTextField.text = "HELLO WORLD"; } </code></pre> <p>Sorry for the formatting, just wrote that off the top of my head</p> <p>And the syntax for embedding the symbol (You won't need to load this via a loader as the actionscript in the external swf/swc is stripped).</p> <pre><code>[Embed(source="assets.swf", symbol="somesymbol")] private var assetSymbol:Class; private var clip:MovieClip; public function LoadSymbolExample() { clip = new assetSymbol(); clip.sometext.text = "Hello World"; } </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