AS 建立滑塊音量控制項實現代碼

來源:互聯網
上載者:User

使用"矩形"工具,在舞台上繪製一個小矩形,大約 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 是在影片剪輯動作中設定的變數。

選擇"控制">"測試影片"來使用音量滑塊。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.