📄 volumecontrol.as
字号:
package com.ninemoon{
import flash.display.*;
import flash.net.NetStream;
import flash.media.SoundTransform;
import flash.events.*;
import flash.geom.Rectangle;
import com.ninemoon.Main;
public class VolumeControl extends Sprite {
private const tempo:Number=0.03;
private var soundv:SoundTransform;
private var currtvol:Number=0.6;
public function VolumeControl() {
mute_btn.visible=false;
}
public function main():void {
volumebar_mc.useHandCursor=true;
var num:Number=currtvol*backbar_mc.width;
soundv=new SoundTransform();
Main.sc.soundTransform=soundv;
soundv.volume=currtvol;
this.appvol(num);
volumebar_mc.addEventListener(MouseEvent.MOUSE_DOWN,volumebarOndown);
this.stage.addEventListener(MouseEvent.MOUSE_UP,volumeOnup);//为什么用stage做监听?
vol_btn.addEventListener(MouseEvent.CLICK,volClick);
}
private function volumebarOndown(event:MouseEvent):void {
event.currentTarget.startDrag(false,new Rectangle(backbar_mc.x,backbar_mc.y-2,backbar_mc.width,0));
this.stage.addEventListener(MouseEvent.MOUSE_MOVE,volumeOnmove);
}
private function volumeOnup(event:MouseEvent):void {
volumebar_mc.stopDrag();
this.stage.removeEventListener(MouseEvent.MOUSE_MOVE,volumeOnmove);
}
private function volumeOnmove(event:MouseEvent):void {
var num:Number=volumebar_mc.x-backbar_mc.x;
volumeactive_mc.width=num;
soundv.volume=num/backbar_mc.width;
currtvol=soundv.volume;
Main.sc.soundTransform=soundv;
}
private function volClick(event:MouseEvent):void {
mute_btn.visible=true;
event.currentTarget.visible=false;
mute_btn.addEventListener(MouseEvent.CLICK,muteClick);
this.addEventListener(Event.ENTER_FRAME,volumeOnenterframe);
}
private function muteClick(event:MouseEvent):void {
event.currentTarget.visible=false;
vol_btn.visible=true;
this.addEventListener(Event.ENTER_FRAME,volumeOnenterframe);
}
private function volumeOnenterframe(event:Event):void {
this.volMotion(mute_btn.visible);
}
private function volMotion(isb:Boolean):void {
if (isb) {
soundv.volume-=tempo;
} else {
soundv.volume+=tempo;
}
var num:Number=soundv.volume*backbar_mc.width;
this.appvol(num);
if (soundv.volume<0) {
soundv.volume=0;
Main.sc.soundTransform=soundv;
this.removeEventListener(Event.ENTER_FRAME,volumeOnenterframe);
volumebar_mc.removeEventListener(MouseEvent.MOUSE_DOWN,volumebarOndown);
} else if (soundv.volume>currtvol) {
soundv.volume=currtvol;
Main.sc.soundTransform=soundv;
this.removeEventListener(Event.ENTER_FRAME,volumeOnenterframe);
volumebar_mc.addEventListener(MouseEvent.MOUSE_DOWN,volumebarOndown);
}
}
private function appvol(num:Number):void {
volumeactive_mc.width=num;
volumebar_mc.x=backbar_mc.x+num;
Main.sc.soundTransform=soundv;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -