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

flash on 2012-9-17

Get Adobe Flash player
by Hrundik 17 Sep 2012
    Embed
/**
 * Copyright Hrundik ( http://wonderfl.net/user/Hrundik )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/3GeW
 */

package {
    import flash.net.URLRequest;
    import flash.display.DisplayObject;
    import flash.display.Graphics;
    import flash.display.Loader;
    import flash.display.SimpleButton;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.Point;

    public class Main extends Sprite {      
        private var circle:DisplayObject = new Sprite();
        private var targetX:int;
        private var targetY:int;
        private var speed:Number=5;
        private var speedx:Number;
        private var speedy:Number;
        private var button:SimpleButton;
        private var image:Loader;

        // for local development
        //[Embed("/tsiolkovsky12-hp.jpg")]
        //private var myimage:Class;

        public function Main() {

            image = new Loader();
            image.load(new URLRequest("http://www.google.ru/logos/2012/tsiolkovsky12-hp.jpg"));
            addChild(image);

            circle = image
              
            // creating embeded image
            //circle = new myimage();
            //addChild(circle);
           

            button = new SimpleButton(createCircle(0x00FF00), 
            createCircle(0xFF0000), createCircle(0x0000FF), createCircle(0));
            button.addEventListener(MouseEvent.CLICK, onCircleClick);
            addChild(button);

            button.x = 150;
            button.y = 150;
            
            circle.x = 100;
            circle.y = 100;              

            stage.addEventListener(MouseEvent.CLICK,onClick);
            stage.addEventListener(Event.ENTER_FRAME, onEnterFrame)
        }

        

        private function createCircle(color:uint):Sprite
        {
            var s:Sprite = new Sprite();
            var g :Graphics = s.graphics;
            g.beginFill(color);
            g.drawCircle(0,0,30);
            g.endFill();
            return s;
        }

        

        public function onCircleClick(e:MouseEvent):void
        {
            e.stopPropagation(); // stops event bubbling
        }



        public function onClick(e:MouseEvent):void {
            targetX = e.stageX;
            targetY = e.stageY;
            var p1:Point = new Point(circle.x, circle.y);
            var p2:Point = new Point(targetX, targetY);
            p1 = p2.subtract(p1);
            speedy = speed*Math.abs(p1.y/p1.x);
        }



        public function onEnterFrame(e:Event):void{
            if(circle.x < targetX)
               circle.x += speed;
            if(circle.x > targetX)
                circle.x -= speed;
            if(circle.y < targetY)
                circle.y += speedy;
            if(circle.y > targetY)
                circle.y -= speedy;    
        }
    }
}