flash on 2010-4-7
3D imports
Tweener: http://code.google.com/p/tweener/
/**
* Copyright lewis_c1986 ( http://wonderfl.net/user/lewis_c1986 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/rOcK
*/
package {
import flash.display.*;
import flash.events.*;
import flash.text.*;
//3D imports
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.view.BasicView;
import org.papervision3d.events.InteractiveScene3DEvent;
import org.papervision3d.materials.MovieMaterial;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.primitives.Plane;
//Tweener: http://code.google.com/p/tweener/
import caurina.transitions.Tweener;
public class PanelFlip extends MovieClip
{
private var view: BasicView;
private var planeGroup: DisplayObject3D;
private var frontPlane: Plane;
private var backPlane: Plane;
private var _frontBox: MovieClip;
private var _backBox: MovieClip;
private var _frontTF: TextField;
private var _backTF: TextField;
private var _fstring: String;
private var _bstring: String;
private var _fmc: Sprite;
private var _bmc: Sprite;
private var _frontPlane: MovieMaterial;
private var _backPlane: MovieMaterial;
public function PanelFlip()
{
//
_fstring = "Click to Flip!!!";
_bstring = "Click to Flip Again!!!";
//this will hold both your planes in a group
planeGroup = new DisplayObject3D();
view = new BasicView(1024, 768,true, true);
view.camera.zoom = 0;
view.viewport.interactive = true;
addChild(view);
//create movieClips then pass those to buildPlanes
createContent();
buildPlanes(_frontBox,_backBox);
}
private function createContent():void{
//make two sides to test
//front movieClip
_frontBox = new MovieClip();
_frontBox.graphics.beginFill(0x0099ff);
_frontBox.graphics.drawRoundRect(0,0,400,400,10);
_frontBox.graphics.endFill();
//back movieClip
_backBox = new MovieClip();
_backBox.graphics.beginFill(0xff0099);
_backBox.graphics.drawRoundRect(0,0,400,400,10);
_backBox.graphics.endFill();
//front textField
_frontTF = makeTF(_fstring,350,200,20,0xFFFFFF,true,false,false);
_frontTF.x = 10;
_frontTF.y = 20;
_backTF = makeTF(_bstring,350,200,20,0xFFFFFF,true,false,false);
_backTF.x = 10;
_backTF.y = 20;
_frontBox.addChild(_frontTF);
_backBox.addChild(_backTF);
}
private function buildPlanes(_fr:MovieClip,_bk:MovieClip):void
{
_fmc = _fr;
_bmc = _bk;
//front plane
_frontPlane = new MovieMaterial(_fmc,true,true,true);
_frontPlane.smooth = true;
_frontPlane.interactive = true;
frontPlane = new Plane(_frontPlane);
frontPlane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, planeClickedHandler, false, 0, true);
//back plane
_backPlane = new MovieMaterial(_bmc,true,true,true);
//smooth out the text
_backPlane.smooth = true;
_backPlane.interactive = true;
backPlane = new Plane(_backPlane);
backPlane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, planeClickedHandler, false, 0, true);
planeGroup.addChild(frontPlane);
/*
rotate the plane in the "back" so it
looks like the back side of the front
*/
backPlane.rotationY = 180;
planeGroup.addChild(backPlane);
frontPlane.z = 1;//puts the frontPlane in front of the backPlane
view.scene.addChild(planeGroup);
view.startRendering();
//animate camera zoom
Tweener.addTween( view.camera, {zoom: 100, time: .5,delay:1, transition:"easeoutexpo"} );
}
private function planeClickedHandler(e:InteractiveScene3DEvent):void {
if (! Tweener.isTweening(planeGroup)) {
var targetRotation:Number = (planeGroup.rotationY <180) ? 180 : 0;
Tweener.addTween(planeGroup, { time:2, transition:'easeinoutback',rotationY: targetRotation } );
}
}
//create a textfield
private function makeTF(_str:String,_w:Number,_h:Number,sz:Number,col:Number,_multi:Boolean,embed:Boolean,_select:Boolean):TextField {
//textField format
var _txtfmt:TextFormat = new TextFormat();
_txtfmt.font = "Helvetica";
_txtfmt.size = sz;
_txtfmt.bold = true;
_txtfmt.color = col;
//textField
var _tf:TextField = new TextField();
_tf.type = TextFieldType.INPUT;
_tf.embedFonts = embed;
_tf.selectable = _select;
_tf.multiline = _multi;
if(_multi == true) _tf.wordWrap = true;
_tf.defaultTextFormat = _txtfmt;
_tf.text = _str;
_tf.width = _w;
_tf.height = _h;
addChild(_tf);
return _tf;
}
}
}