ActionScript for Non-Coders
Subject:   Flash MX files
Date:   2004-09-28 11:03:14
From:   Sham_B
Response to: Flash MX files

the Flash 5 compatible file is now up at

Flash 5 doesnt support the Stage class, which the camera uses, so instead you need to define two variables on frame 1 of the main timeline as follows:

// These lines MUST be in the root timeline.
// Equate them to the stage width and height
// (Control+M or double-click on the frame rate
// value below the timeline to see them).
stageWidth = 720;
stageHeight = 480;

You also have to copy across the movie clips camFrame AND dummy into any FLA you want to use the v-cam in (the reason you need dummy is noted below).

The other problem with Flash 5 is that it doesnt support Flash MX/Flash MX2004 style events (i.e. JavaScript style callbacks), which I guess would be the main problem in converting the code over to Flash 5. Here's how I've solved this issue (there are other ways to do this, but this code keeps the script looking as much like the Flash MX 2004 version as possible).

In the camera, there is a second movie clip called dummy. Attached to this movie clip is the following code...

onClipEvent (load) {
// Initialize the v-cam...
// target and camera are the paths to the
// controlled timeline and camera clip respectively.
target = _parent._parent;
cam = _parent;
// make camera frame invisible
cam._visible = false;
// Capture stage parameters
sX = _root.stageWidth;
sY = _root.stageHeight;
cX = sX/2;
cY = sY/2;
// create color instances for color
// transforms (if any).
camColor = new Color(cam);
parentColor = new Color(target);
onClipEvent (enterFrame) {
// Make the stage move so that the
// v-cam is centered on the
// viewport every frame
scaleX = sX/_parent._width;
scaleY = sY/_parent._height;
target._x = cX-(cam._x*scaleX);
target._y = cY-(cam._y*scaleY);
target._xscale = 100*scaleX;
target._yscale = 100*scaleY;
onClipEvent (unload) {
// If the v-cam is ever removed (unloaded)
// the stage, return the stage to the default
// settings.
resetTrans = {ra:100, rb:0, ga:100, gb:0, ba:100, bb:0, aa:100, ab:0};
target._xscale = 100;
target._yscale = 100;
target._x = 0;
target._y = 0;

This is essentially the same code as the MX 2004 code, except that I use the onLoad to initialize the camera (in the MX 2004 this is done via a script on frame 1 of the camera timeline).

I've only tested the Flash 5 version for a short while, but it seems okay.

Remember, to see the finished effect, test the SWF in the browser (F12) rather than in test mode (Control+F12).