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 2009-8-13

A quick demo to test a concept...
* Nothing special + dirty code
Get Adobe Flash player
by iNFlex 23 Aug 2009
    Embed
/**
 * Copyright iNFlex ( http://wonderfl.net/user/iNFlex )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/l5yI
 */

/* 
 * A quick demo to test a concept...
 * Nothing special + dirty code
 */
package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.events.Event;
    
    public class FlashTest extends Sprite {
        public static var console:TextField; // Well, no trace here :(

        private var controller:Controller;
        public function FlashTest() {
            // write as3 code here...
            console = new TextField();
            addChild(console);
            console.appendText("Up and Running!\n");
            
            //addChild(new Thumb());
            controller = new Controller();
            controller.x = 100;
            controller.y = 200;
            addChild(controller);
            
            addEventListener(Event.ENTER_FRAME, enterFrame);
        }
        
        private function enterFrame(e:Event):void
        {
            controller.update();
        }
    }
}

import flash.display.Sprite;
import flash.events.MouseEvent

class Controller extends Sprite
{
    private var thumbs:Thumb;
    private var focused:Thumb;
    
    public function Controller()
    {
        createThumbs();
        addEventListener(MouseEvent.MOUSE_OVER, mouseOver);
        addEventListener(MouseEvent.MOUSE_OUT, mouseOut);
    }
    
    public function update():void
    {
        /*var current:Thumb = thumbs;
        while(current != null && current.next != null)
        {
            current.x += (current.next.x - current.next.distanceFromCenter - 20 - current.x - current.distanceFromCenter) * 0.5;
            current.update();
            current = current.next;
        }
        current.update();
        thumbs.next.scaleX = thumbs.next.scaleY += 0.005;*/
        
        const spacing:Number = 20;
        const ease:Number = 0.5;
        
        var current:Thumb = thumbs;
        var fixed:Thumb = current.next;
        
        while (current != focused || fixed != null)
        {
            current.x += (fixed.leftEdge - spacing - current.rightEdge) * ease;
            current.update();
            
            current = fixed;
            fixed = fixed.next;
        }
    }
    
    private function mouseOver(e:MouseEvent):void
    {
        e.target.enlarge = true;
        focused = e.target as Thumb;
    }
    
    private function mouseOut(e:MouseEvent):void
    {
        e.target.enlarge = false;
    }
    
    private function createThumbs():void
    {
        var current:Thumb = new Thumb();
        addChild(current);
        thumbs = current;
        
        for (var i:int = 1; i < 4; ++i)
        {
            var newThumb:Thumb = new Thumb();
            newThumb.x = newThumb.width * i;
            current.next = newThumb;
            current = newThumb;
            addChild(newThumb);
        }
    }
}

class Thumb extends Sprite
{
    public var next:Thumb;
    public var enlarge:Boolean;
    
    public function Thumb()
    {
        init();
    }
    
    public function update():void
    {
        var targetScale:Number = enlarge ? 1.3 : 1;
        scaleX = scaleY += (targetScale - scaleX) * 0.3;
    }
    
    private function init():void
    {
        graphics.beginFill(0xFFFFFF * Math.random());
        graphics.drawRect(-50, -35, 100, 70);
        graphics.endFill();
    }
    
    public function get leftEdge():Number
    {
        return x - width / 2;
    }
    
    public function get rightEdge():Number
    {
        return x + width / 2;
    }
    
    
    
}