topical media & game development

talk show tell print

actionscript-distort-com-adobe-ac-controls-ViewStack3D.ax

actionscript-distort-com-adobe-ac-controls-ViewStack3D.ax [swf] flex


  package com.adobe.ac.controls
  {
          import com.adobe.ac.mxeffects.Distortion;
          import com.adobe.ac.mxeffects.DistortionConstants;
          
          import flash.display.DisplayObject;
          
          import mx.containers.Canvas;
          import mx.core.UIComponent;
          import mx.events.FlexEvent;
          
          public class @ax-actionscript-distort-com-adobe-ac-controls-ViewStack3D extends Canvas
          {
                  private var distortions : Array = new Array();
                  
                  public function @ax-actionscript-distort-com-adobe-ac-controls-ViewStack3D()
                  {
                          addEventListener( FlexEvent.CREATION_COMPLETE, initDistortions );
                  }
                  
                  private function initDistortions( event : FlexEvent ) : void
                  {                        
                          for( var i : int; i < numChildren; i++ )
                          {
                                  var child : UIComponent = UIComponent( getChildAt( i ) );
                                  initialiseBounds( child );
                                  
                                  var distort : Distortion = new Distortion( child );
                                  distort.smooth = true;
                                  distort.openDoor( 40, DistortionConstants.LEFT );
                                  distortions.push( distort );
                          }
                  }
                  
                  override protected function createChildren() : void
                  {
                          super.createChildren();
                          for( var i : int; i < numChildren; i++ )
                          {
                                  var child : UIComponent = UIComponent( getChildAt( i ) );
                                  child.x += i * 25;
                                  child.y += i * 20;                                
                          }        
                  }
                  
                  public function tilt( percentage : Number ) : void
                  {
                          var len : Number = distortions.length;
                          for( var i : int; i < len; i++ )
                          {
                                  var distort : Distortion = distortions[ i ];
                                  distort.openDoor( percentage, DistortionConstants.LEFT );
                          }
                  }
                  
                  private function initialiseBounds( texture : UIComponent ) : void
                  {                
                          var firstChild : DisplayObject = DisplayObject( getChildAt( 0 ) );
                          texture.setActualSize( firstChild.width, firstChild.height );
                          texture.validateNow();                
                  }
          }
  }


(C) Æliens 27/08/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.