Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 17th, 2012  |  syntax: None  |  size: 2.94 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ffj-- Timeline vcam, paste into first frame of movieclip
  2.  
  3.         import flash.display.*;
  4.         import flash.events.*;
  5.         import flash.geom.*;
  6.                
  7.         public class VCamera extends Sprite {
  8.                
  9.                 public function VCamera() {
  10.                         addEventListener(Event.ADDED_TO_STAGE,added);
  11.                         addEventListener(Event.REMOVED_FROM_STAGE,removed);
  12.                         addEventListener(Event.RENDER,onRend);
  13.                        
  14.                         if(stage) {
  15.                                 added();
  16.                         }
  17.                        
  18.                         visible=false;
  19.                        
  20.                         trace("new cam");
  21.                 }
  22.                
  23.                 private function added(e:Event=null):void {
  24.                         if(parent.blendMode==BlendMode.NORMAL) {
  25.                                 //if there isn't any blendmode set yet,
  26.                                 //set it as layer so that possible alpha rendering actually looks good
  27.                                 parent.blendMode="layer";
  28.                         }
  29.                         addEventListener(Event.ENTER_FRAME,eFrame,false,0,true);
  30.                         stage.invalidate();
  31.                        
  32.                 }
  33.                
  34.                 private function removed(e:Event):void {
  35.                         removeEventListener(Event.ENTER_FRAME,eFrame,false);
  36.                         parent.transform.matrix=new Matrix();
  37.                         parent.transform.colorTransform=new ColorTransform();
  38.                         parent.alpha=1;
  39.                 }
  40.                        
  41.                
  42.                 private function eFrame(e:Event):void {
  43.                         stage.invalidate();
  44.                 }
  45.                
  46.                 private function onRend(e:Event):void {
  47.                        
  48.                         //set up the movement/rotation data
  49.                         //first make a copy so that we don't corrupt the camera position
  50.                         //the getter returns a copy for us, we don't risk messing it up
  51.                         var t:Matrix=transform.matrix;
  52.                        
  53.                         //then just invert it, leaving us with the exact matrix we need to
  54.                         //get the parent into the position the camera should be in
  55.                         t.invert();
  56.                        
  57.                         //do the moving
  58.                         parent.transform.matrix=t;
  59.                        
  60.                         //people want to use these too
  61.                         parent.transform.colorTransform=transform.colorTransform;
  62.                         parent.blendMode=blendMode;
  63.                         parent.filters=filters;
  64.                         parent.alpha=this.alpha;
  65.                        
  66.                 }
  67.         }