I'm starting to mess around with Flash at work (2004 MX), and I've run across a question easier to get answered here by people who know Flash then by searching the web. :p
I have an FLA where I have an image in the background, and a rectangle stretching from top to bottom in a layer above the image, set as the mask for the image. Thus, only the part of the image "covered" by the mask rectangle shows through. Along the timeline, I've set keyframes for the rectangle, positioned it differently in those keyframes, and motion tweened it so that it moves nicely from one keyframe to the next.
However, I'd like to be able to have an actionscript that will automatically make the rectangle move in an erratic fashion along the horizontal. Something along the lines of the following pseudo-code:
// set 3 random keyframes
$targetframe[1] = rand(0, last_frame);
$targetframe[2] = rand(0, last_frame);
$targetframe[3] = rand(0, last_frame);
function moveRectangle($frame) {
$speed = rand(1, 5); // number of pixels to shift each repositioning
$dir = rand(+, -); // set direction of movement along x axis, plus or minus
while (frame.current < $frame) {
if (rectangle.position.x < 1) $dir = "+"; // if the rectangle is beyond the left border, change directions
if (rectangle.position.x > movie.width) $dir = "-"; // if the rectangle is beyond the right border, change directions
if ($dir == "+") {
rectangle.position.x = rectangle.position.x + $speed;
} else {
rectangle.position.x = rectangle.position.x - $speed;
}
}
}
moveRectangle($targetframe[1]);
moveRectangle($targetframe[2]);
moveRectangle($targetframe[3]);
Wow, that turned out to be more complex than I thought. I hope it's understandable.