开发者

Flex 3 - Movie Clips - Viewing multiple frames on the stage

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.


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


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜