1
 var file:FileReference=new FileReference();

and then

trace (file.data);

works fine

after that I'm trying to embed received data into the scene but with no success

var ExtSWF:MovieClip;
ExtSWF = file.data.readObject() as MovieClip;
trace(ExtSWF);

returns null

but if I load it as remote file, with Loader - it works fine

var ldr:Loader = new Loader();
ldr.load(new URLRequest("ext.swf"));
......
ExtSWF = MovieClip(ldr.contentLoaderInfo.content);

Is it possible to just upload swf file and embed it into the scene, or Loader class is the only possibility to archieve this goal?

el Dude
  • 5,003
  • 5
  • 28
  • 40

1 Answers1

1

The Loader class is used to load SWF files or image (JPG, PNG, or GIF) files.

But "load" really meaning "decode format" for display. So pass your file.data bytes through the Loader using Loader.loadbytes for decoding to a valid MovieClip object.

Try

//var ExtSWF : MovieClip = new MovieClip;
//ExtSWF = file.data.readObject() as MovieClip;
var ldr : Loader = new Loader(); //# declare outside of any functions (make as public var)
ldr.loadBytes(file.data); //#use Loader to auto-decode bytes of SWF
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, on_swfLoaded );

And also have a handler function for the decoding completion...

function on_swfLoaded (evt:Event) : void
{
    var ExtSWF : MovieClip = new MovieClip;
    ldr.contentLoaderInfo.removeEventListener(Event.COMPLETE, on_swfLoaded );
    ExtSWF = ldr.content as MovieClip;

    trace(ExtSWF);
    ExtSWF.x =50; ExtSWF.y = 50; addChild(ExtSWF);
}
VC.One
  • 14,790
  • 4
  • 25
  • 57