
Untitled
By: a guest on
Aug 17th, 2012 | syntax:
None | size: 2.94 KB | hits: 12 | expires: Never
ffj-- Timeline vcam, paste into first frame of movieclip
import flash.display.*;
import flash.events.*;
import flash.geom.*;
public class VCamera extends Sprite {
public function VCamera() {
addEventListener(Event.ADDED_TO_STAGE,added);
addEventListener(Event.REMOVED_FROM_STAGE,removed);
addEventListener(Event.RENDER,onRend);
if(stage) {
added();
}
visible=false;
trace("new cam");
}
private function added(e:Event=null):void {
if(parent.blendMode==BlendMode.NORMAL) {
//if there isn't any blendmode set yet,
//set it as layer so that possible alpha rendering actually looks good
parent.blendMode="layer";
}
addEventListener(Event.ENTER_FRAME,eFrame,false,0,true);
stage.invalidate();
}
private function removed(e:Event):void {
removeEventListener(Event.ENTER_FRAME,eFrame,false);
parent.transform.matrix=new Matrix();
parent.transform.colorTransform=new ColorTransform();
parent.alpha=1;
}
private function eFrame(e:Event):void {
stage.invalidate();
}
private function onRend(e:Event):void {
//set up the movement/rotation data
//first make a copy so that we don't corrupt the camera position
//the getter returns a copy for us, we don't risk messing it up
var t:Matrix=transform.matrix;
//then just invert it, leaving us with the exact matrix we need to
//get the parent into the position the camera should be in
t.invert();
//do the moving
parent.transform.matrix=t;
//people want to use these too
parent.transform.colorTransform=transform.colorTransform;
parent.blendMode=blendMode;
parent.filters=filters;
parent.alpha=this.alpha;
}
}