Back to "flash Basic Theory Class-Catalog"
The slider has a very wide range of uses
such as: Volume control, playback control, size control, and so on, abound
Idea: 1. Determine the transverse moving range of the slider;
2. Obtain the relative position (percentage) of the slider (slider) in the control bar (bar);
3. Finally returns a variable (per), the range in 1~100, is the only variable output.
Step 1:
1. Draw a long square, save as a movie clip, instance name slider, registration point in the center;
2. Draw a control bar, save as a movie clip, instance name bar, registration point in the left;
3. Put in a picture, save as a movie clip, instance named MC.
Step 2:
Add as code:
var left = bar._x+slider._width/2;
var right = bar._x+bar._width-slider._width/2;
var bottom = top = bar._y;
//确定slider可移动的左右及上下边界
slider.onPress = function() {
this.startDrag(true, left, top, right, bottom);
};
slider.onRelease = function() {
this.stopDrag();
};
_root.onMouseMove = function() {
var per = Math.ceil((slider._x-left)/(right-left)*100);
//per(slider在bar中的相对位置)=slider的x坐标 ÷ slider移动的宽度范围
_root.mc._xscale = per;
_root.mc._yscale = per;
//最后用这个比值再去控制图片的缩放大小
};
slider.onReleaseOutside = slider.onRelease;
//鼠标在外面释放也等同于内部释放的效果
^_^ This is a very useful example, we can not use the entire control bar as a component, the future to be used only from the library to drag one on it. ^_^
Flash charge 1:startdrag ()
mc.startDrag([固定中心],[left],[top],[right],[bottom])
Fixed center: [Optional] A Boolean value that specifies whether the drag movie clip is locked to the center of the mouse position (true) or to the position where the user first clicks the movie clip (false).
Left,top,right,bottom:[the value of the coordinates relative to the parent of the movie clip to specify the constraint rectangle for the movie clip.