使用"矩形"工具,在舞台上繪製一個小矩形,大約 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 是在影片剪輯動作中設定的變數。
選擇"控制">"測試影片"來使用音量滑塊。