In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

[Memory Test] BitmapData.clone()

BitmapData.clone() を行った場合、dispose しなくても、メモリ使用量は増えない。
Get Adobe Flash player
by clockmaker 23 Dec 2010
    Embed
/**
 * Copyright clockmaker ( http://wonderfl.net/user/clockmaker )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/bnZi
 */

package
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.InteractiveObject;
    import flash.display.Sprite;
    import flash.events.ContextMenuEvent;
    import flash.events.Event;
    import flash.events.IEventDispatcher;

    import com.flashdynamix.utils.SWFProfiler;

    [SWF(width=465, height=465, frameRate=60)]
    public class Main extends Sprite
    {

        //----------------------------------------------------------
        //
        //   Constructor 
        //
        //----------------------------------------------------------

        public function Main()
        {
            orijinal = new BitmapData(465, 465);

            canvas = new Bitmap();
            addChild(canvas);

            addEventListener(Event.ENTER_FRAME, enterFrameHandler);

            setupSWFProfiler(this);
        }

        //----------------------------------------------------------
        //
        //   Property 
        //
        //----------------------------------------------------------

        private var canvas:Bitmap;
        private var orijinal:BitmapData;

        //----------------------------------------------------------
        //
        //   Function 
        //
        //----------------------------------------------------------

        protected function enterFrameHandler(event:Event):void
        {
            var clone:BitmapData = orijinal.clone();
            clone.perlinNoise(100 * Math.random(), 100 * Math.random(), 1, 1, false, true);
            canvas.bitmapData = clone;
        }

        private function setupSWFProfiler(context:InteractiveObject):void
        {
            SWFProfiler.init(context);
            (context.contextMenu.customItems[0] as IEventDispatcher).dispatchEvent(new ContextMenuEvent(ContextMenuEvent.MENU_ITEM_SELECT));
        }
    }
}