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

forked from: 画像をドラッグ出来るように調整(ループ機能付き)

画像をマウスでドラッグしてください
Bitmapを動かさずに中のピクセルだけ移動させています。
Get Adobe Flash player
by q.kensuke 14 Aug 2011
    Embed
// forked from rsakane's 画像をドラッグ出来るように調整(ループ機能付き)
/*
 * 画像をマウスでドラッグしてください
 * Bitmapを動かさずに中のピクセルだけ移動させています。
 */
package
{
    import flash.display.Sprite;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.display.Loader;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.Matrix;
    import flash.geom.Point;
    import flash.geom.Rectangle;
    import flash.net.URLRequest;
    import flash.system.LoaderContext;
    import flash.system.Security;
 
    [SWF(frameRate = 120)]
    public class Main extends Sprite
    {
        private const WIDTH:int = 465;
        private const HEIGHT:int = 465;
        
        private var bd:BitmapData;
        private var copybd:BitmapData;
        private var posX:int;
        private var posY:int;
        
        public function Main()
        {
            Security.loadPolicyFile("http://farm3.static.flickr.com/crossdomain.xml");
            var loader:Loader = new Loader();
            loader.contentLoaderInfo.addEventListener(Event.INIT, initHandler);
            loader.load(new URLRequest("http://farm3.static.flickr.com/2047/2280715132_f0a72c1088.jpg"), new LoaderContext(true));
        }
 
        private function initHandler(event:Event):void
        {
            var loader:Loader = event.currentTarget.loader;
 
            var matrix:Matrix = new Matrix();
            matrix.scale(WIDTH / loader.width, HEIGHT / loader.height);
 
            bd = new BitmapData(WIDTH, HEIGHT);
            bd.draw(loader, matrix);
            addChild(new Bitmap(bd));
            
            copybd = bd.clone();
            stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
            stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
        }
        
        private function onMouseDown(event:MouseEvent):void
        {
            posX = mouseX;
            posY = mouseY;
            
            stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
        }
        
        private function onMouseMove(event:MouseEvent):void
        {
            move(mouseX - posX, mouseY - posY);
            posX = mouseX;
            posY = mouseY;
        }
        
        private function onMouseUp(event:MouseEvent):void
        {
            stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
        }
        
        private function move(tx:int, ty:int):void
        {
            if (tx != 0)
            {
                bd.scroll(tx, 0);
                if (tx > 0) bd.copyPixels(copybd, new Rectangle(WIDTH - tx, 0, tx, 465), new Point());
                else bd.copyPixels(copybd, new Rectangle(0, 0, -tx, 465), new Point(WIDTH + tx));
                copybd = bd.clone();
            }
            
 
        }
    }
}