[Flash Basic theory Lesson 07] Make control slider [StartDrag]

Source: Internet
Author: User
Tags range relative

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.