当前位置:软件学习 > Flash >>

AS 创建滑块音量控件实现代码

使用"矩形"工具,在舞台上绘制一个小矩形,大约 30 像素高 10 像素宽。
选择"选择"工具并双击舞台上的形状。
按 F8 打开"转换为元件"对话框。
选择"按钮"类型,输入 volume 作为元件名称并单击"确定"。
在舞台上选中该按钮元件,在"属性"检查器中输入实例名称 handle_btn 。
选择该按钮,然后选择"修改">"转换为元件"。
选择影片剪辑行为时要小心。这将创建一个在第一帧中带有按钮的影片剪辑。

选择该影片剪辑,然后在"属性"检查器中输入 volume_mc 作为实例名称。
在主时间轴上选择第 1 帧,然后选择"窗口">"动作"。
在"动作"面板中输入下面的代码:

 代码如下 复制代码

this.createTextField("volume_txt", 10, 30, 30, 200, 20);
volume_mc.top = volume_mc._y;
volume_mc.bottom = volume_mc._y;
volume_mc.left = volume_mc._x;
volume_mc.right = volume_mc._x + 100;
volume_mc._x += 100;

volume_mc.handle_btn.onPress = function() {
    startDrag(this._parent, false, this._parent.left, this._parent.top, this._parent.right, this._parent.bottom);
};
volume_mc.handle_btn.onRelease = function() {
    stopDrag();
    var level:Number = Math.ceil(this._parent._x - this._parent.left);
    this._parent._parent.song_sound.setVolume(level);
    this._parent._parent.volume_txt.text = level;
};
volume_mc.handle_btn.onReleaseOutside = slider_mc.handle_btn.onRelease;


startDrag() 参数 left、top、right 和 bottom 是在影片剪辑动作中设置的变量。

选择"控制">"测试影片"来使用音量滑块。

补充:flash教程,动画技术 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,