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

Progression4をControllerとして使う練習

Progression4の練習。

シーンとかページとかとはちょっと違う構成、
例えば3D空間を移動するなどの時に
Progression4をControllerとして使うとすると、
どうしたらいいんだろう。

試行錯誤中
Get Adobe Flash player
by umhr 02 Feb 2010
/**
 * Copyright umhr ( http://wonderfl.net/user/umhr )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/qHLw
 */

/*
Progression4の練習。

シーンとかページとかとはちょっと違う構成、
例えば3D空間を移動するなどの時に
Progression4をControllerとして使うとすると、
どうしたらいいんだろう。

試行錯誤中


*/
package {
	import flash.display.*;
	import flash.geom.PerspectiveProjection;
	import flash.geom.Point;
	
	import jp.progression.*;
	import jp.progression.config.*;
	import jp.progression.debug.*;
	
	public class progression extends Sprite {
		
		public var manager:Progression;
		
		public function progression() {
			
			stage.transform.perspectiveProjection = new PerspectiveProjection();
			stage.transform.perspectiveProjection.projectionCenter = new Point(465/2,465/2);
				
			Progression.initialize( new BasicAppConfig() );
			manager = new Progression( "index", stage, IndexScene );
			
			//Debugger.addTarget( manager );
			
			manager.goto( manager.root.sceneId );
		}
	}
}



import flash.display.*;
import flash.events.MouseEvent;

import jp.progression.casts.*;
import jp.progression.commands.*;
import jp.progression.commands.display.*;
import jp.progression.commands.lists.*;
import jp.progression.commands.managers.Goto;
import jp.progression.commands.net.*;
import jp.progression.commands.tweens.*;
import jp.progression.data.*;
import jp.progression.events.*;
import jp.progression.executors.ExecutorObjectState;
import jp.progression.scenes.*;

class IndexScene extends SceneObject {
	private var _view:View;
	public function IndexScene() {
//		var btnIndex:CastButton = new CastButton();
//		btnIndex.graphics.beginFill(0x0000FF);
//		btnIndex.graphics.drawRect( 0, 0, 40, 18 );
//		btnIndex.graphics.endFill();
//		btnIndex.id = "btnIndex";
//		btnIndex.addEventListener(MouseEvent.CLICK, clickHandler);
		stage.addEventListener(MouseEvent.CLICK, clickHandler);
		var sp:CastSprite = new CastSprite();
		sp.id = "sqIndex";
		_view = new View();
		_view.x = 465/2;
		_view.y = 465/2;
		sp.addChild(_view);
	}
	
	protected override function atSceneLoad():void {
		manager.addEventListener(ProcessEvent.PROCESS_START, onProcessStart);
		addCommand(
			//"Progression 4",
			new AddChild( container, "sqIndex" ),
			//new AddChild( container, "btnIndex" ),
			function():void {
				for (var i:int = 0; i < 6; i++) {
					var SO:SceneObject = new SceneObject("s"+String(i));
					addScene(SO);
				}
			}
		);
	}
	private function onProcessStart(event:ProcessEvent):void {
		for (var i:int = 0; i < 6; i++) {
			if(manager.destinedSceneId == manager.root.scenes[i].sceneId){
				_view.pitchStep(i);
			}
		}
	}
	protected override function atSceneInit():void {
		addCommand();
	}
	protected override function atSceneGoto():void {
		addCommand();
	}
	private function clickHandler(e:MouseEvent):void {
		if (manager.state > ExecutorObjectState.IDLING) {
			manager.stop();
		}
		if (manager.current.next) {
			manager.goto(manager.current.next.sceneId);
		} else {
			manager.goto(manager.root.scenes[0].sceneId);
		}
	}
}

import org.libspark.betweenas3.BetweenAS3;
import org.libspark.betweenas3.easing.*;
import org.libspark.betweenas3.tweens.ITween;

import flash.display.Sprite;
class View extends Sprite{
	private var _canvas:ViewSprite;
	private var _t:ITween;
	private var _currentStep:int;
	public function View():void{
		_canvas = new ViewSprite();
		this.addChild(_canvas);
	}
	public function pitchStep(step:int):void{
		var degree:Number = (step/6)*360;
		if(((_currentStep/6)*360-degree)<-180){
			degree = -360+degree;
		}else if(((_currentStep/6)*360-degree)>180){
			degree = 360+degree;
		}
		if (_t != null) {
			_t.stop();
			if(_canvas.rotationY-degree > 180){
				degree = 360+degree;
			}
		}
		_t = BetweenAS3.tween(_canvas, { rotationY:degree}, null, 0.3, Cubic.easeOut);
		_t.onComplete = function():void{_canvas.rotationY = (degree+360)%360};
		_t.play();
		_currentStep = step;
	}
}
import flash.geom.PerspectiveProjection;
import flash.geom.Point;
import flash.geom.Vector3D;
class ViewSprite extends Sprite{
	public function ViewSprite():void{
		this.z = 0;
		var colors:Array = [0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0x00FFFF, 0xFF00FF];
		for (var i:int = 0; i < 6; i++) {
			var sp:Sprite = new Sprite();
			sp.graphics.beginFill(colors[i],0.4);
			sp.graphics.drawRect(-100,-100,200,200);
			sp.graphics.endFill();
			sp.z = 100-200*(i/5);
			this.addChild(sp);
		}
	}
	override public function get rotationY():Number{
		return super.rotationY;
	}
	override public function set rotationY(value:Number):void{
		super.rotationY = (value+360)%360;
		zSort(this);
	}
	private function zSort(target:DisplayObjectContainer):void {
		if(!target.root){return};
		var n:int = target.numChildren;
		var array:Array = [];
		var reference:Array = [];
		for (var i:int = 0; i < n; i++) {
			var poz:Vector3D = target.getChildAt(i).transform.getRelativeMatrix3D(this.root.stage).position;
			var point:Point = stage.transform.perspectiveProjection.projectionCenter;
			array[i] = poz.subtract(new Vector3D(point.x,point.y,-stage.transform.perspectiveProjection.focalLength)).length;
			reference[i] = target.getChildAt(i);
		}
		var temp:Array = array.sort(Array.NUMERIC | Array.RETURNINDEXEDARRAY);
		for (i = 0; i < n; i++) {
			target.setChildIndex(reference[temp[i]],0);
			if(reference[temp[i]].numChildren > 1){
				zSort(reference[temp[i]]);
			}
		}
	}
}