Exporting frame from external swf to Javascript


My approach to this would be:

-Use AS3 for the reason lukevanin commented:

Just remember that AS3 can load an AS2 SWF, but an AS2 SWF cannot load an AS3 SWF, so you actually achieve greater compatibility (with your content) if you publish AS3

-Use a proxy file to fetch the swf file to get around sandbox violation issues (although if the swf loads external resources and uses relative paths it might get a bit more complex)

-Take a snapshot of the frame ( see George Profenza's solution )

-Encode the image using base64 and send that** to a JS method, and then decode to get the image.

** I'm pretty sure there are no size limitations...


I am trying to capture a still frame from an (any) external swf file, by using my own flash movie as a proxy to load it and hand information regarding the Stage onto javascript. I want to keep it as wide compatible as possible, so I went with AS2 / Flash 8 for now.

The script works fine in the Flash debugger, i.e. the

trace(flash2canvasScreenshot.getPixel(w, h).toString(16));

returns the correct pixel color, where as:

ExternalInterface.call("sendToJS",flash2canvasScreenshot.getPixel(w, h).toString(16));

in the published movie doesn't.

This method can obviously be quite slow for large flash (dimension wise) movies, as it iterates every single pixel. If someone has any better methods in mind, feel free to share, but as said, the problem I am facing is that I am getting differentiating results in debugging and publishing, with the pixel information not getting fetched when published.

import flash.display.BitmapData;
import flash.external.*;

var myLoader:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();

mclListener.onLoadInit = function(target_mc:MovieClip)

        var stageW = Stage.width;
        var flash2canvasScreenshot:BitmapData = new BitmapData(stageW, Stage.height, false, 0x00000000);
        var pixels:Array = new Array();

        for (w = 0; w <= stageW; w++)
            trace(flash2canvasScreenshot.getPixel(w, h).toString(16)); // this gives correct color value for the pixels in the debugger
            ExternalInterface.call("sendToJS",flash2canvasScreenshot.getPixel(w, h).toString(16)); // this just returns the bitmap default color, 0 in this case.
            for (h = 0; h <= Stage.height; h++)
                var pixel = flash2canvasScreenshot.getPixel(w, h).toString(16);




myLoader.loadClip("http://i.cdn.turner.com/cnn/cnnintl_adspaces/2.0/creatives/2010/6/9/21017300x250-03.swf", 0);
//myLoader.loadClip("https://s.ytimg.com/yt/swfbin/watch_as3-vflJjAza6.swf", 0);

//myLoader.loadClip(_level0.flash2canvasurl, _root.mc);