topical media & game development

talk show tell print

actionscript-embed-VariableLevelEmbedDemo.ax

actionscript-embed-VariableLevelEmbedDemo.ax [swf] flex


  package {
    import flash.display.*;
    import flash.events.*;
    import mx.core.MovieClipAsset;
    import mx.core.MovieClipLoaderAsset;
    import mx.core.SpriteAsset;
    import mx.core.BitmapAsset;
    import mx.core.ByteArrayAsset;
  
    public class @ax-actionscript-embed-VariableLevelEmbedDemo extends Sprite {
      [Embed(source="actionscript-embed-embeds-photo.jpg")]
      private var Photo:Class;
  
      [Embed(source="actionscript-embed-embeds-line.svg")]
      private var actionscript_embed_SVGLine:Class; 
  
      [Embed(source="actionscript-embed-embeds-fp9app.swf")]
      private var actionscript_embed_FP9App:Class;
  
      [Embed(source="actionscript-embed-embeds-fp8app.swf", symbol="Ball")]
      private var actionscript_embed_FP8Ball:Class;
  
      [Embed(source="actionscript-embed-embeds-fp9app.swf", mimeType="application/octet-stream")]
      private var actionscript_embed_FP9BinaryData:Class;
  
      public function @ax-actionscript-embed-VariableLevelEmbedDemo () {
        // Variable-level bitmap
        var photo:BitmapAsset = new actionscript_embed_Photo();
        addChild(photo);
  
        // Variable-level SVG
        var line:SpriteAsset = new actionscript_embed_SVGLine();
        addChild(line);
  
        // Variable-level FP8 SWF Symbol
        var fp8ball:MovieClipAsset = new actionscript_embed_FP8Ball();
        addChild(fp8ball);
  
        // Variable-level FP9 SWF
        var fp9app:MovieClipLoaderAsset = new actionscript_embed_FP9App();
        addChild(fp9app);
        
        // To access a symbol's class or regular class in the embedded .swf,
        // wait for the embedded .swf file to initialize
        Loader(fp9app.getChildAt(0)).contentLoaderInfo.addEventListener(
                                                          Event.INIT, 
                                                          fp9appInitListener);
  
        // Variable-level binary data (FP9 SWF)
        var fp9binarydata:ByteArrayAsset = new actionscript_embed_FP9BinaryData();
        var loader:Loader = new Loader();
        loader.loadBytes(fp9binarydata);
        addChild(loader);
  
        // To access a symbol's class or regular class in the embedded .swf,
        // wait for the embedded .swf file to initialize
        loader.contentLoaderInfo.addEventListener(Event.INIT, 
                                                  fp9binarydataInitListener);      
      }
      
      private function fp9appInitListener (e:Event):void {
        // Obtain a reference to the Ball symbol from the embedded .swf file
        var BallSymbol:Class = 
          e.target.content.loaderInfo.applicationDomain.getDefinition("Ball");
        // Make a new instance of the Ball symbol
        var ball:MovieClip = MovieClip(new BallSymbol());
        // Position the Ball instance and place it on screen
        ball.x = 220;
        ball.y = 240;
        addChild(ball);
      }
  
      private function fp9binarydataInitListener (e:Event):void {
        // Obtain a reference to the Ball symbol from the embedded .swf file
        var BallSymbol:Class = 
          e.target.content.loaderInfo.applicationDomain.getDefinition("Ball");
        // Make a new instance of the Ball symbol
        var ball:MovieClip = MovieClip(new BallSymbol());
        // Position the Ball instance and place it on screen
        ball.y = 200;
        addChild(ball);
      }
    }
  }
  


(C) Æliens 27/08/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.