views:

332

answers:

2

I want to view all of the frames from within a MovieClip concurrently on the stage, however I am struggling to extract the individual frame information from the MovieClip.

I have managed to load an external SWF into a MovieClip and view the frames sequentially with the following code:

    <mx:HBox id="hbox"></mx:HBox>

<mx:Script>
    <![CDATA[
        import mx.controls.SWFLoader;

        public var loader:SWFLoader = new SWFLoader();
        public var myMovieClip:MovieClip = new MovieClip();

        public function init():void {
            loader.addEventListener(Event.COMPLETE, handleLoaded);
            loader.load('assets/test_document.swf');    
        }

        public function handleLoaded(e:Event):void {
            var myMovieClip:MovieClip = e.currentTarget.content as MovieClip;
            myMovieClip.stop();

            hbox.addChild(loader);
        }
    ]]>
</mx:Script>

What is the most efficient way to view ALL of the frames on the screen?

Thanks in advance.

A: 

Easiest way is to just load the SWF clip.totalFrames times, gotoAndStop each instance to a different frame, and add them all to the stage in some meaningful way. Usually your browser will cache the SWF after the first load and so this isn't as horrendous as you might think.

The alternative solution is to gotoAndStop to each frame and then

var bitmapData:BitmapData = new BitmapData(clip.width, clip.height, true);
bitmapData.draw(clip);

but there are a lot of things that go wrong here -- you have to do this on an enter_frame loop instead of a for loop (otherwise you just get the 2nd frame totalFrames times, you have to have the right security settings to be able to use the draw function, if your clip has weird registration points the bitmaps will clip...

Cory Petosky
I would have thought the first solution would bloat exponentially (totalFrames*totalFrames) in memory usage but if not awesome!Will try it out, thanks.
Hamish
A: 

Do you mean ALL of the frames at the same time ? like:

function getClipAsBitmaps(clip:MovieClip):ArrayCollection{
    var data:ArrayCollection = new ArrayCollection();
    var frames:int = clip.totalFrames;
    for(var i:int = 1 ; i <= frames;  i++){
        clip.gotoAndStop(i);
        trace(i);
        var bitmapData:BitmapData = new BitmapData(clip.width,clip.height,true,0x00FFFFFF);
        bitmapData.draw(clip);
        data.addItem({source:new Bitmap(bitmapData),label:'frame: ' + i});
    }
    return data;
}

tileList.dataProvider = getClipAsBitmaps(star);

Note: MovieClip transforms are igonored

George Profenza
IIRC, this won't actually work. You'll get `totalFrames` copies of frame 1 of the clip. The `gotoAndStop` isn't actually complete until the next `ENTER_FRAME` event fires.
Cory Petosky
I tested in flash before posting with DataProvider instead of ArrayCollection and a 10 frames long animation. I got 10 images with the content of each frame(not 10 copies of frame1). I'm not sure I understand what you mean
George Profenza
This solution worked well for me thanks
Hamish