V-Cams are an extremely useful peice of flash scripting. They are flash cameras that can be used in sidescrolling games instead of moving a large background.
First, make a Box the size of your canvas. Make sure it is filled with a colour of about 25 % alpha.
Convert it to a movie clip with the instance name : "Cam" without the quotes.
Add a new layer, and make a small circle in the middle of your box. That should also have low alpha.
Add yet another layer, and add this script:
function camControl():Void {
parentColor.setTransform(camColor.getTrans
form());
var scaleX:Number = sX/this._width;
var scaleY:Number = sY/this._height;
_parent._x = cX-(this._x*scaleX);
_parent._y = cY-(this._y*scaleY);
_parent._xscale = 100*scaleX;
_parent._yscale = 100*scaleY;
}
function resetStage():Void {
var resetTrans:Object = {ra:100, rb:0, ga:100, gb:0, ba:100, bb:0, aa:100, ab:0};
parentColor.setTransform(resetTrans);
_parent._xscale = 100;
_parent._yscale = 100;
_parent._x = 0;
_parent._y = 0;
}
// make frame invisible
this._visible = false;
// Capture stage parameters
var oldMode:String = Stage.scaleMode;
Stage.scaleMode = "exactFit";
var cX:Number = Stage.width/2;
var cY:Number = Stage.height/2;
var sX:Number = Stage.width;
var sY:Number = Stage.height;
Stage.scaleMode = oldMode;
// create color instances for color
// transforms (if any).
var camColor:Color = new Color(this);
var parentColor:Color = new Color(_parent);
// Make the stage move so that the
// v-cam is centered on the
// viewport every frame
this.onEnterFrame = camControl;
// Make an explicit call to the camControl
// function to make sure it also runs on the
// first frame.
camControl();
// If the v-cam is ever removed (unloaded)
// the stage, return the stage to the default
// settings.
this.onUnload = resetStage;
Now, to change the position of everything in the frame, just move the V-cam, this is a great way to reduce lag in games with a large background
To make something stay in the same position, it must be in a movie clip, and have the same center square as the V-cam, and simple add this script to the movieclip
onClipEvent(enterFrame){
_x = _root.Cam._x;
_y = _root.Cam._y;
}