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

drag, resize, scale9grid

Get Adobe Flash player
by cpu_t 10 May 2011
    Embed
/**
 * Copyright cpu_t ( http://wonderfl.net/user/cpu_t )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/nkIM
 */

package {
    import flash.events.Event;
    import flash.geom.Rectangle;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            // write as3 code here..
            var sp:Sprite = new Sprite();
            addChild(sp);
            sp.graphics.beginFill(0xDD0000);
            sp.graphics.drawCircle(50,50,50);
            sp.graphics.endFill();
            
            var hand:Sprite = new Sprite();
            addChild(hand);
            hand.x = 100;
            hand.y = 100;
            hand.graphics.beginFill(0xDD00);
            hand.graphics.drawRect(0,0,10,10);
            hand.graphics.endFill();
            
            sp.addEventListener("mouseDown",function(e:*):void
            {
                sp.startDrag();
            });
            sp.addEventListener("mouseUp",function(e:*):void
            {
                sp.stopDrag();
                hand.x = sp.x + sp.width;
                hand.y = sp.y + sp.height;
            });
            
            hand.addEventListener("mouseDown",function(e:*):void
            {
                hand.startDrag();
            });
            hand.addEventListener("mouseUp",function(e:*):void
            {
                hand.stopDrag();
                if(hand.x < sp.x)hand.x = sp.x;
                if(hand.y < sp.y)hand.y = sp.y;
                sp.width = hand.x - sp.x;
                sp.height = hand.y - sp.y;
            });
            hand.doubleClickEnabled = true;
            hand.addEventListener("doubleClick",function(e:*):void
            {
                hand.x = sp.x + 100;
                hand.y = sp.y + 100;
                hand.dispatchEvent(new Event("mouseUp"));
            });
            
            sp.scale9Grid = new Rectangle(20,30,60,40);
        }
    }
}