Flash 10 3D example


fp10 3d example3D Flash Player 10 example and code using PaperSprite and the new built in 3D instead of PaperVision. The output is similar to similar to the InteractivePlanesBoard example and some of it is loosely based on this example code too.
view swf here


ActionScript
< view plain text >
  1. /**
  2. * v0.1 code by dehash.com 2009
  3. * Flash Player 10 swf using PaperSprite similar to InteractivePlanesBoard
  4. * http://www.dehash.com/?page_id=219 only using FP10 3D rather than PV3D
  5. * code loosely based on example at :
  6. * http://blog.soulwire.co.uk/code/open-source/two-sided-planes-in-flash-player-10
  7. * Released as open source under the BSD License
  8. * http://www.opensource.org/licenses/bsd-license.php
  9. */
  10.  
  11. package  {
  12.     import flash.events.Event;
  13.     import flash.events.MouseEvent;
  14.     import flash.display.Sprite;
  15.    
  16.     //http://blog.soulwire.co.uk/code/open-source/two-sided-planes-in-flash-player-10
  17.     import soulwire.display.PaperSprite;
  18.    
  19.     // http://code.google.com/p/tweener/
  20.     import caurina.transitions.Tweener;
  21.  
  22.     [SWF(width="800", height="600", backgroundColor="0xFFFFFF")]
  23.  
  24.     public class InteractivePlanesBoard10Multi2CleanedUp extends Sprite {
  25.  
  26.         private const NUM_OBJECTS:uint = 4;
  27.  
  28.         [Embed(source='add.png')]
  29.         private var pic:Class;
  30.  
  31.         private var size:uint = 100;
  32.         private var cnt:uint = 0;
  33.         private var holder:PaperSprite;
  34.  
  35.         public function InteractivePlanesBoard10Multi2CleanedUp() {
  36.             holder = new PaperSprite();
  37.             addChild(holder);
  38.             holder.x = stage.stageWidth / 2;
  39.             holder.y = stage.stageHeight / 2;
  40.  
  41.             var xOffset:Number = (NUM_OBJECTS * size) / 2;
  42.             var yOffset:Number = (NUM_OBJECTS * size) / 2;
  43.  
  44.             for (var i:int = 0; i < NUM_OBJECTS; i++) {
  45.                 for (var j:int = 0; j < NUM_OBJECTS; j++) {
  46.  
  47.                     var paperSprite:PaperSprite = new PaperSprite();
  48.                     paperSprite = new PaperSprite();
  49.                     paperSprite.x = -xOffset + (i * size * 1.2);
  50.                     paperSprite.y = -yOffset + (j * size * 1.2);
  51.  
  52.                     if(cnt%5==0){
  53.                         paperSprite.front = createPicSprite();
  54.                     }else {
  55.                         paperSprite.front = createSprite();
  56.                     }
  57.  
  58.                     paperSprite.back = createSprite()
  59.                     paperSprite.rotationY = 0;
  60.                     holder.addChild(paperSprite );
  61.  
  62.                     paperSprite.addEventListener(MouseEvent.MOUSE_OVER, planePressedHandler, false, 0, true);
  63.  
  64.                     cnt++;
  65.                 }
  66.             }
  67.  
  68.             addEventListener ( Event.ENTER_FRAME, spin );
  69.         }
  70.  
  71.         private function createSprite ():Sprite {
  72.             var sp:Sprite = new Sprite();
  73.             sp.graphics.beginFill ( Math.random() * 0xffffff );
  74.             sp.graphics.drawRect ( -size / 2, -size / 2, size, size);
  75.             sp.graphics.endFill ();
  76.             return sp;
  77.         }
  78.  
  79.         public function createPicSprite():Sprite {
  80.             var sp:Sprite = new Sprite();
  81.             var b:*= new pic();
  82.             b.width = b.height = size;
  83.             sp.addChild(b);
  84.             return sp;
  85.         }
  86.  
  87.         private function spin ( event:Event ):void {
  88.             var mX:Number = ((mouseX / stage.stageWidth) - 0.5) * 360;
  89.             var mY:Number = ((mouseY / stage.stageHeight) - 0.5) * 360;
  90.             holder.rotationY += (mX - holder.rotationY) / 140;
  91.             holder.rotationX += (mY - holder.rotationX) / 140;
  92.         }
  93.  
  94.         public function planePressedHandler(e:MouseEvent):void {
  95.             if (!Tweener.isTweening(e.currentTarget)) {
  96.                 Tweener.addTween(e.currentTarget, { time:2, delay:0, transition:'easeinoutback', rotationY: e.currentTarget.rotationY + 180 } );
  97.             }
  98.         }
  99.  
  100.     }
  101. }