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: Virtual Corners

...
@author  DcTurner

Drag the green handles to change the perspective
Get Adobe Flash player
by MrDcTurner 08 Mar 2009
// forked from MrDcTurner's Virtual Corners
package  
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
        import gs.TweenLite;
        import gs.easing.*;
	
	/**
	 * ...
	 * @author  DcTurner

         *  Drag the green handles to change the perspective
	 */

        [SWF(frameRate=60)]

	public class Main extends Sprite
	{
		public static const numberOfShapes:int = 20;
		public static var stepArray:Array = [];
		public static const shapeColour:uint = 0x000000;
                public var container:Sprite;
		public var node1:Sprite;
		public var node2:Sprite;
                public var isDragging:Boolean=false;
                public var draggingSprite:Sprite;
		
		private var distX:Number;
		private var distY:Number;
		
		public function Main() 
		{
			addEventListener(Event.ADDED_TO_STAGE, addedToStage);
		}
		
		private function addedToStage(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, addedToStage);
                        container = new Sprite();
                        addChild(container);
			setupNodes();
                        addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
			run();
		}
		
		private function run():void
		{
			for (var i:int = 0; i <= numberOfShapes * 2; i++) {
				stepArray.push(new Sprite());
			}
			addEventListener(Event.ENTER_FRAME, render);
		}
		
		private function render(e:Event):void 
		{
			container.graphics.clear();
			container.graphics.lineStyle(1, 0x000000);
			container.graphics.beginFill(0x000000);
			distX = node1.x - node2.x;
			distY = node1.y - node2.y;
			
			var node1X:Number = node1.x;
			var node1Y:Number = node1.y;
			
			//  render the shapes
			for (var i:int = numberOfShapes-1; i >= 0; i--) {
				var myX:Number = node1X - (distX / numberOfShapes) * i;
				var myY:Number = node1Y - (distY / numberOfShapes) * i;
				var targetStep:Sprite = stepArray[i] as Sprite;
				targetStep.x = myX;
				targetStep.y = myY;
				//graphics.drawCircle(targetStep.x, targetStep.y, 2);
			}
			bottomRow();
			topRow();
			
                        // rotate the container
                        //container.rotationX+=.2;
                        
                        if (isDragging){
                            draggingSprite.x = mouseX;
                            draggingSprite.y = mouseY;
                        }
		}
		
		
		
		private function topRow():void
		{
			var odd:Boolean = true;
			for (var i:int = numberOfShapes; i >= 0 ; i--) {
				if (odd) {
					container.graphics.moveTo((stage.stageWidth / numberOfShapes) * (i), 0);
					container.graphics.lineTo(stepArray[i].x,stepArray[i].y);
					container.graphics.lineTo(stepArray[i+1].x,stepArray[i+1].y);
					container.graphics.lineTo((stage.stageWidth / numberOfShapes) * (i+1), 0);
					odd = false;
				}else {
					odd = true;
				}
			}
		}
		private function bottomRow():void
		{
			var odd:Boolean = true;
			for (var i:int = numberOfShapes-2; i >= 0 ; i--) {
				if (odd) {
					container.graphics.moveTo((stage.stageWidth / numberOfShapes) * (i), stage.stageHeight);
					container.graphics.lineTo(stepArray[i].x,stepArray[i].y);
					container.graphics.lineTo(stepArray[i+1].x,stepArray[i+1].y);
					container.graphics.lineTo((stage.stageWidth / numberOfShapes) * (i+1), stage.stageHeight);
					odd = false;
				}else {
					odd = true;
				}
			}
		}
		
		private function setupNodes():void
		{
			//  node1
			node1 = newNode();
			node1.x = stage.stageWidth / 3;
			node1.y = (stage.stageHeight / 3) * 2;
			//  node2
			node2 = newNode();
			node2.x = (stage.stageWidth / 3)*2;
			node2.y = stage.stageHeight / 3;
		}
		
		private function newNode():Sprite
		{
			var tempSprite:Sprite = new Sprite();
			//  node gfx
			tempSprite.graphics.beginFill(0x00FF00);
			tempSprite.graphics.drawCircle( 0,0,5);
			tempSprite.graphics.beginFill(0x00BB00);
			tempSprite.graphics.drawCircle( 0,0,3);
			container.addChild(tempSprite);
			//  node interaction
			tempSprite.buttonMode = true;
			tempSprite.addEventListener(MouseEvent.MOUSE_OVER, nodeMouseOverHandler);
			tempSprite.addEventListener(MouseEvent.MOUSE_OUT, nodeMouseOutHandler);
			tempSprite.addEventListener(MouseEvent.MOUSE_DOWN, nodeMouseDownHandler);
			return tempSprite;
		}
		private function nodeMouseOverHandler(e:MouseEvent):void 
		{
			var tempNode:Sprite = e.target as Sprite;
			TweenLite.to ( tempNode, .4, { scaleX:2, scaleY:2, ease:Bounce.easeOut } );
		}
		private function nodeMouseOutHandler(e:MouseEvent):void 
		{
			var tempNode:Sprite = e.target as Sprite;
			TweenLite.to ( tempNode, .4, { scaleX:1, scaleY:1, ease:Bounce.easeOut } );
		}
		private function nodeMouseDownHandler(e:MouseEvent):void 
		{
			var tempNode:Sprite = e.target as Sprite;
                        draggingSprite = tempNode;
                        isDragging = true;
		}
		private function mouseUpHandler(e:MouseEvent):void 
		{
			//var tempNode:Sprite = e.target as Sprite;
                        draggingSprite = null;
                        isDragging = false;
		}
}
}