Making It Work...
Copy the ActionScript below.
ball.onpress=function()
{ball.startDrag(false,5,186,150,186);d=1;};
ball.onrelease=function()
{stopDrag();d=0;};
onmousemove=function()
{if ((_ymouse>212) || (_ymouse<184))
{stopDrag();d=0;}
else{
if (d==1){
disp=ball._x;
block._width=disp;
block._height=disp;}
}};
Click Frame > ActionScript and paste the code into the dialog box, then click "OK".
Save the .sfd.
Using the Slider...
Click the green Preview button to see it work. Dragging the dot left or right should size the rectangle up or down. The value displayed in the edit field is the width and height of the rectangle derived from the "x" coordinate of the ball.
How It Works...
In the first block of code, note that the "y" value for the drag area is set at 186 for both the start and end values. This keeps the dot from moving vertically thus keeping it on the track. The "x" values for the drag area are set at 5 and 150. This sets the horizontal limits for the StartDrag() command. The rectangle is resized according to the horizontal position of the dot. Drag it to position 100, and the rectangle sizes up to 100 x 100. Drag the dot left to 25, and the rectangle downsizes accordingly.
The second code block stops drag action when you release the mouse. Note that in the next code block, there is an "if" statement. This checks the vertical position of the mouse pointer. If it gets too far above or below the dot, drag is disabled. I used this due to a quirk in ActionScript's "ondragout()" command. It's possible for the mouse to temporarily outrun the dot if you move it too quickly, thereby stopping the drag action before you're ready. Trust me, this is irritating. The "if" statement is a workaround for the problem. The remaining lines of code update the display and resize the rectangle. The "d" variable disables the resize when you release the mouse. Otherwise, you'd get a new value when you release the mouse button.
It's also possible to use the slider's values as percentages. This would, for example, allow you to resize an image while keeping it properly scaled. This is a good bit more complex than the example above and as such I didn't use it for this tutorial. Suffice it to say that almost any property which can be adjusted programmatically with ActionScript can be set dynamically with a slider. Zoom, font size, colors, etc. Click here for an "extreme" example of the slider at work.
Download Flash Designer source projects:
t1035.zip (12 kb)
|