Here's the updated Flip class using the Go tweening engine:
package com.hydrotik.bannerflip3d{/**
* @author Donovan Adams
* @version December 9, 2007
* @usage Example:<code></code>
* @description
* @history
* @sends
* @todo
*
*/import flash.display.*;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.utils.setTimeout;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.core.proto.SceneObject3D;
import org.papervision3d.events.FileLoadEvent;
import org.papervision3d.materials.BitmapFileMaterial;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;
import com.hydrotik.go.PapervisionTween;
import fl.motion.easing.*;
import org.papervision3d.core.proto.MaterialObject3D;
[Event(name="COMPLETE", type="com.hydrotik.bannerflip3d.FlipEvent")][Event(name="ON_FLIP", type="com.hydrotik.bannerflip3d.FlipEvent")]publicclass Flip extends EventDispatcher {publicstatic const VERBOSE:Boolean = true;
privatevar _scope:Sprite;
privatevar _stage:Stage;
privatevar _oCore:*;
privatevar _assetPath:String;
privatevar _materialArray:Array;
privatevar _planeArray:Array;
privatevar _array:XMLList;
privatevar _count:int = 0;
privatevar _next:int;
privatevar _prev:int;
privatevar _loader:Sprite;
privatevar _seconds:int;
//New 2.0 Privatesprivatevar renderer:BasicRenderEngine;
privatevarcamera:Camera3D;
privatevar viewport:Viewport3D;
privatevar debug : Function;
privatevar scene : Scene3D;
privatevar white : MaterialObject3D;
privatevar bg : Plane;
publicfunction Flip(scope:Sprite, stage:Stage, core:*, a:XMLList, assetPath:String = "../flashassets/", s:int = 10):void{
debug = trace;
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
_scope = scope;
_stage = stage;
_oCore = core;
_array = a;
_assetPath = assetPath;
_seconds = s;
_materialArray = [];
_planeArray = [];
scene = new Scene3D();
renderer = new BasicRenderEngine();
camera = new Camera3D();
camera.z = -100;
viewport = new Viewport3D(500,300,true);
viewport.alpha = 0;
_scope.addChild(viewport);
white = new ColorMaterial(0xFFFFFF);
setTimeout(addedToStage, 100);
}privatefunction addedToStage():void{if(VERBOSE) debug("\n\n>> Flip.addedToStage(); - args: "+[]);
_loader = new Sprite();
_loader.graphics.beginFill(0x000000);
_loader.graphics.drawRect(0, 0, 1, 4);
_scope.addChild(_loader);
_loader.x = (_stage.stageWidth/2) - 50;
_loader.y = (_stage.stageHeight/2) - 2;
for(var i:int = 0; i < _array.length(); i++){
_materialArray[i] = new BitmapFileMaterial(_array[i].attribute('src'));
_materialArray[i].oneSide = true;
_materialArray[i].smooth = true;
_materialArray[i].addEventListener(FileLoadEvent.LOAD_PROGRESS, onFileProgress);
_materialArray[i].addEventListener(FileLoadEvent.LOAD_COMPLETE, onFileComplete);
_planeArray[i] = new Plane( _materialArray[i], 300, 156, 6, 6);
scene.addChild(_planeArray[i]);
_planeArray[i].name = i.toString();
_planeArray[i].rotationY = -180;
}// PapervisionTween is extending LinearGo. PapervisionTween is a custom extension using custom syntax, running on the Go system // The init function passes the rendering info so that PapervisionTween can take care of updating the renderer
PapervisionTween.init(renderer, scene, camera, viewport);
}privatefunction onFileProgress(event:FileLoadEvent):void{if(VERBOSE) debug("\t percentage: "+Math.round((event.bytesLoaded/event.bytesTotal)*100) + "%");
var sec:Number = 100/_array.length();
_loader.width = ((_count * sec) + ((event.bytesLoaded/event.bytesTotal)* sec));
}privatefunction onFileComplete(event:FileLoadEvent):void{if(VERBOSE) debug("complete!");
//
_count++;
if(_count == _array.length()){
onImageQueueCompleteHandler();
}}privatefunction onImageQueueCompleteHandler():void{// PapervisionTween is extending LinearGo. PapervisionTween is a custom extension using custom syntax, running on the Go system var l:PapervisionTween = new PapervisionTween(_loader, {alpha:0}, 0, .2, Quintic.easeInOut, loaderFade);
l.start();
// PapervisionTween is extending LinearGo. PapervisionTween is a custom extension using custom syntax, running on the Go system var b:PapervisionTween = new PapervisionTween(_planeArray[0], {rotationY:0}, 0, 1, Quintic.easeInOut, onFlipDone);
b.start();
// PapervisionTween is extending LinearGo. PapervisionTween is a custom extension using custom syntax, running on the Go system var c:PapervisionTween = new PapervisionTween(camera, {z:-100}, 0, 1, Quintic.easeInOut, onFlipDone);
c.start();
_next = 0;
_count = -1;
bg = new Plane(white,5120,2560,10,10);
bg.y = -200;
bg.z = 500;
bg.pitch(0);
scene.addChild(bg);
dispatchEvent(new FlipEvent(FlipEvent.COMPLETE, _next, _array[0].attribute('link'), _array[0].attribute('target')));
var myTimer:Timer = new Timer(_seconds *1000);
myTimer.addEventListener(TimerEvent.TIMER, timerHandler);
myTimer.start();
}privatefunction flip(id:int):void{// PapervisionTween is extending LinearGo. PapervisionTween is a custom extension using custom syntax, running on the Go system var a:PapervisionTween = new PapervisionTween(_planeArray[_next], {rotationY:180}, 0, 1, Quintic.easeInOut, onOldFlipDone);
a.start();
// Update Data
_prev = _next;
_next = (id == _array.length() - 1) ? 0 : id + 1;
varurl:String = _array[_next].attribute('link');
var targ:String = _array[_next].attribute('target');
trace(url, targ);
dispatchEvent(new FlipEvent(FlipEvent.ON_FLIP, _next, url, targ));
// PapervisionTween is extending LinearGo. PapervisionTween is a custom extension using custom syntax, running on the Go system var b:PapervisionTween = new PapervisionTween(_planeArray[_next], {rotationY:0}, 0, 1, Quintic.easeInOut, onFlipDone);
b.start();
// PapervisionTween is extending LinearGo. PapervisionTween is a custom extension using custom syntax, running on the Go system var c:PapervisionTween = new PapervisionTween(camera, {z:-350}, 0, .5, Quintic.easeIn, onCameraHalf);
c.start();
}privatefunction onCameraHalf(event:Event = null):void{
viewport.alpha = 1;
var c:PapervisionTween = new PapervisionTween(camera, {z:-100}, 0, .5, Quintic.easeOut);
c.start();
}publicfunction timerHandler(event:TimerEvent):void{if(VERBOSE) debug("timerHandler: " + event);
_count = (_count == _array.length() - 1) ? 0 : _count + 1;
flip(_count);
}privatefunction onFlipDone(event:Event = null):void{if(VERBOSE) debug("flip done!");
}privatefunction loaderFade(event:Event = null):void{
viewport.alpha = 1;
_scope.removeChild(_loader);
}privatefunction onOldFlipDone(event:Event = null):void{if(VERBOSE) debug("old flip done!");
_planeArray[_prev].rotationY = -180;
}}}
And if you are curious here is the PapervisionTween extension of Go:
/**
* Copyright (c) 2007 Moses Gunesch, MosesSupposes.com - Donovan Adams, blog.hydrotik.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.hydrotik.go{import flash.display.DisplayObject;
import org.fuseproject.go.items.LinearGo;
import org.papervision3d.objects.DisplayObject3D;
//import flash.geom.ColorTransform;//import flash.filters.BlurFilter;//import flash.geom.Point; /**
* A basic example of how you could build a tween on LinearGo.
*/publicclass PapervisionTween extends LinearGo {// -== Public Properties ==-publicfunctiongetwidth() : Number{return _rotationY;
}publicfunctionsetwidth(value : Number) : void{if(_state == STOPPED)
_rotationY = value;
}publicfunctionget startWidth() : Number{return _startRotationY;
}publicfunctionset startWidth(value : Number) : void{if(_state == STOPPED)
_startRotationY = value;
}publicfunctiongettarget() : DisplayObject {return_target;
}publicfunctionsettarget(obj : DisplayObject) : void{if(_state == STOPPED)_target = obj;
}// -== Protected Properties ==-
protected var_target : *;
protected var _rotationY : Number;
privatestaticvar _viewport:*;
privatestaticvar _camera:*;
privatestaticvar _scene:*;
privatestaticvar _renderer : *;
privatevar _closure : Function;
privatevar debug : Function;
protected var _startRotationY : Number;
protected var _changeRotationY : Number;
protected var _startProps : Object = {};
protected var _changeProps : Object = {};
protected var _propsTo : Object = {};
publicstaticfunction init(renderer:*, scene:*, camera:*, viewport:*):void{
_renderer = renderer;
_scene = scene;
_camera = camera;
_viewport = viewport;
}// -== Public Methods ==-publicfunction PapervisionTween(target:* = null,
propsTo:Object = null,
delay:Number = NaN,
duration:Number = NaN,
easing:Function = null,
closure:Function = null){super(delay, duration, easing);
debug = trace;
_target = target;
if(closure != null) addCallback(closure);
for(var prop in propsTo){switch(prop){case"alpha":
if(_target is DisplayObject){
_propsTo[prop] = (propsTo[prop]!= undefined) ? propsTo[prop] : _target[prop];
}if(_target is DisplayObject3D){if(propsTo[prop]!= undefined){
_propsTo[prop] = propsTo[prop];
}else{_target.extra[prop] = newNumber(1);
_propsTo[prop] = _target.extra[prop] = _target.extra[prop];
}}break;
default:
_propsTo[prop] = (propsTo[prop]!= undefined) ? propsTo[prop] : _target[prop];
}}}
override publicfunctionstart() :Boolean{if(!_target)returnfalse;
var prop:String;
for(prop in _propsTo){switch(prop){case"alpha":
if(_target is DisplayObject){
_startProps[prop] = _target[prop];
}if(_target is DisplayObject3D){trace("start: "+_target.extra[prop]);
_startProps[prop] = _target.extra[prop];
}break;
default:
_startProps[prop] = _target[prop];
}}if(useRelative){for(prop in _propsTo){
_changeProps[prop] = _propsTo[prop];
}}else{for(prop in _propsTo){
_changeProps[prop] = (_propsTo[prop] - _startProps[prop]); //_propsTo[prop];}}return(super.start());
}//TODO add alpha tweening syntax when released in 2.0 update
override protected functiononUpdate(type:String) : void{for(var prop in _propsTo){switch(prop){case"alpha":
if(_target is DisplayObject3D){//var val:Number = super.correctValue(_startProps[prop] + _changeProps[prop] * _position);//_target.material.bitmap.colorTransform(_target.material.bitmap.rect, new ColorTransform(1, 1, 1, val, 0, 0, 0, 0));//_target.extra[prop] = val;
debug("Current version of Pv3D does not support alpha tweening");
}if(_target is DisplayObject)_target[prop] = super.correctValue(_startProps[prop] + _changeProps[prop]* _position);
break;
default:
_target[prop] = super.correctValue(_startProps[prop] + _changeProps[prop]* _position);
}}if(_target is DisplayObject3D) _renderer.renderScene(_scene,_camera,_viewport);
}}}
I plan on adding effects as well as the alpha property when 2.0 is able to support that. Shadows, layer effects, and more still to come!
Check the most recent Go post for updates to HydroTween
I finally got a chance to play with Moses' new AS3 tweening system "GO". It's very, very cool, and very powerful. The only drawback to this is it takes a bit more work and is a little more advanced then the average tweening engine. However for advanced developers comfortable with customizing and modifying a tweening engine, GO will be a natural solution especially for big projects.
I'm looking forward to seeing what other people come up with and how they extend the functionality of GO. This was a simple example but I plan on abstracting out the array tweening function so it can be used in other situations. Hopefully people will catch on to this and a library of extensions will develop. I think once that happens it will become very accessible to all developers.
Check the most recent Go post for updates to HydroTween
I finally got a chance to play with Moses' new AS3 tweening system "GO". It's very, very cool, and very powerful. The only drawback to this is it takes a bit more work and is a little more advanced then the average tweening engine. However for advanced developers comfortable with customizing and modifying a tweening engine, GO will be a natural solution especially for big projects.
I'm looking forward to seeing what other people come up with and how they extend the functionality of GO. This was a simple example but I plan on abstracting out the array tweening function so it can be used in other situations. Hopefully people will catch on to this and a library of extensions will develop. I think once that happens it will become very accessible to all developers.