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

XML to BetweenAS3 その2

XMLからBetweenAS3の設定
*	serial・parallel対応
*	
*	タグ説明
*	tween
*	  トゥイーンの作成
*	start(省略可)
*	  開始パラメータの設定
*	  相対値($)も使用化
*	end
*	  終了時のパラメータの設定
*	  startと同じプロパティを設定してくれるとうれしい。
*	time(省略可)
*	  トゥイーンの時間指定
*	  小数値でも安心のはず
*	easing(省略可)
*	  BetweenAS3のイージングをそのまま記述でおk
*	
*	serial
*	  tween・serial・parallelで作成したトゥイーンを直列化
*
Get Adobe Flash player
by yasohachi 26 Apr 2010
    Embed
/**
 * Copyright yasohachi ( http://wonderfl.net/user/yasohachi )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/89ve
 */

// forked from yasohachi's XML to BetweenAS3
/**
 *	XMLからBetweenAS3の設定
 *	serial・parallel対応
 *	
 *	タグ説明
 *	tween
 *	  トゥイーンの作成
 *	start(省略可)
 *	  開始パラメータの設定
 *	  相対値($)も使用化
 *	end
 *	  終了時のパラメータの設定
 *	  startと同じプロパティを設定してくれるとうれしい。
 *	time(省略可)
 *	  トゥイーンの時間指定
 *	  小数値でも安心のはず
 *	easing(省略可)
 *	  BetweenAS3のイージングをそのまま記述でおk
 *	
 *	serial
 *	  tween・serial・parallelで作成したトゥイーンを直列化
 *	
 */

package {
    import flash.display.Sprite;
    [SWF(backgroundColor="0x000000")]
    public class XMLTween extends Sprite {
    		public var xml:XML = 
    			<tweens>
    				<serial>
    					<parallel>
						<tween>
							<start><$x>200</$x></start>
							<end><$x>-200</$x></end>
							<time>1.5</time>
							<easing>Bounce.easeOut</easing>
						</tween>
						<tween>
							<start><$y>-200</$y></start>
							<end><$y>200</$y></end>
							<time>2</time>
							<easing>Cubic.easeIn</easing>
						</tween>
					</parallel>
					<parallel>
						<tween>
							<start><$x>0</$x></start>
							<end><x>100</x></end>
							<time>1</time>
							<easing>Bounce.easeIn</easing>
						</tween>
						<tween>
							<start><$y>0</$y></start>
							<end><$y>-200</$y></end>
							<time>3</time>
							<easing>Cubic.easeIn</easing>
						</tween>
					</parallel>
				</serial>
			</tweens>
		
        public function XMLTween() {
            var box:Box = new Box();
            box.x = 230;
            box.y = 230;
            this.addChild(box);
            var xmlc:XMLCommand = new XMLCommand(xml,box);
            xmlc.tweens.stopOnComplete = false;
            xmlc.tweens.play();
        }
    }
}

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

import flash.accessibility.Accessibility;
class XMLCommand{
	public var tweens:ITween;
	public function XMLCommand(xml:XML,target:Object){
		tweens = makeTweens(xml,target);
	}
	
	private function makeTweens(xml:XML,target:Object):ITween{
		var it:ITween;
		if(xml.hasOwnProperty("serial")){
			it = BetweenAS3.serialTweens(makeList(xml.serial[0],target));
		}else if(xml.hasOwnProperty("parallel")){
			it = BetweenAS3.parallelTweens(makeList(xml.parallel[0],target));
		}else{
			it = makeTween(xml.tween[0],target);
		}
		
		return it;
	}
	
	private function makeParallel(xml:XML,target:Object):ITween{
		
		return BetweenAS3.parallelTweens(makeList(xml,target));
	}
	
	private function makeSerial(xml:XML,target:Object):ITween{
		return BetweenAS3.serialTweens(makeList(xml,target));
	}
	
	private function makeTween(xml:XML,target:Object):ITween{
		var strObj:Object = null;
		var endObj:Object = null;
		var easing:IEasing = null;
		var time:Number = 1.0;
		if(xml.hasOwnProperty("start")){
			strObj = makeStatus(xml.start[0]);
		}
		if(xml.hasOwnProperty("end")){
			endObj = makeStatus(xml.end[0]);
		}
		if(xml.hasOwnProperty("time")){
			time = Number(xml.time[0]);
		}
		if(xml.hasOwnProperty("easing")){
			easing = makeEasing(xml.easing[0]);
		}
		
		return BetweenAS3.tween(target,endObj,strObj,time,easing);
	}
	
	private function makeList(xml:XML,target:Object):Array{
		var value:Array = [];
		var item:XML;
		var list:XMLList = xml.children();
		for each(item in list){
			switch(item.name().localName){
				case "serial":
					value.push(makeSerial(item,target));
					break;
				case "parallel":
					value.push(makeParallel(item,target));
					break;
				case "tween":
					value.push(makeTween(item,target));
					break;
			}
		}
		return value;
	}
	
	private function makeStatus(xml:XML):Object{
		var list:XMLList = xml.children();
		var obj:Object = {};
		var node:XML;
		for each(node in list){
			var prop:String = node.name().localName;
			obj[prop] = Number(node.toString());
		}
		
		return obj;
	}
	
	private function makeEasing(xml:XML):IEasing{
		var str:Array = xml.toString().split(".");
		var type:String = str[0];
		var easing:String = str[1];
		var eClass:Class;
		switch(type){
			case "Back":
				eClass = Back;
				break;
			case "Bounce":
				eClass = Bounce;
				break;
			case "Cubic":
				eClass = Cubic;
				break;
			case "Circ":
				eClass = Circ;
				break;
			case "Circular":
				eClass = Circular;
				break;
			case "Elastic":
				eClass = Elastic;
				break;
			case "Expo":
				eClass = Expo;
				break;
			case "Exponential":
				eClass = Exponential;
				break;
			case "Linear":
				eClass = Linear;
				break;
			case "Physical":
				eClass = Physical;
				break;
			case "Quad":
				eClass = Quad;
				break;
			case "Quadratic":
				eClass = Quadratic;
				break;
			case "Quart":
				eClass = Quart;
				break;
			case "Quartic":
				eClass = Quartic;
				break;
			case "Quint":
				eClass = Quint;
				break;
			case "Quintic":
				eClass = Quintic;
				break;
			case "Sine":
				eClass = Sine;
				break;
			default:
				eClass = Bounce;
		}
		
		return eClass[easing];
	}
}

import flash.display.Sprite;
class Box extends Sprite
{
	public function Box():void{
		
		var r:uint = randomUint();
		var g:uint = randomUint();
		var b:uint = randomUint();
		var color:uint = (r << 16) | (g << 8) | b;
		this.graphics.beginFill(color);
		this.graphics.drawRect(-10,-10,20,20);
		this.graphics.endFill();
	}
	
	private function randomUint():uint{
		var num:uint = 0x80 + int(Math.random()*1000) % 0x80;
		
		return num;
	}
}