Graphics Programs Reference
In-Depth Information
27
28
29
30
31
32
33
34
35
36
37
checkTheMouse = function()
{
cursor_mc._x = _xmouse;
cursor_mc._y = _ymouse;
moveAmount = Math.abs(_xmouse - centerX)/speedFactor;
if (_xmouse < centerX-10) { panLeft() }
else if (_xmouse > centerX+10 ) { panRight() }
else dontPan();
}
Step 6: Pan from anywhere on the Stage
What we have done so far is to create panning movement based on the center of the
Stage. We now want to be able to pan the background both left and right by pressing the
mouse button down and dragging from anywhere on the Stage. The way this will work is
to record the starting location of the cursor when the mouse button is first pressed down
as shown.
7
8
9
10
11
12
13
14
15
16
17
18
var speedFactor:Number = 20; // used to control panning speed
var startX:Number = 0; // initial dragging _xmouse position
var startY:Number = 0; // initial dragging _ymouse position
// define the panorama actions
pano_mc.onPress = function()
{
pressed = true;
Mouse.hide();
startX = _xmouse;
startY = _ymouse;
}
Next, we will measure how far the cursor moves while it is held down so that we can
move the image in proportion to that amount. The only thing we need to do is to replace
centerX with startX in the checkTheMouse handler.
Save and test your movie. You should be able to start dragging the cursor from any-
where on the Stage. As you do, the movement of the panorama should start out slowly
and increase speed as you drag farther from the initial cursor location.
 
Search WWH ::




Custom Search