souggou:flash制作一个二合一按钮,开始暂停

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/29 02:03:26

常用的两种方法
1.做两个,然后visible控制显隐
2.做成MC,然后控制主场景

主场景建立一个影片剪辑实例名为my_btn,影片剪辑内放动态文本,实例名为my_txt

as如下:
var temp:Number = 0;
this.my_btn.my_txt.text = "开始";
my_btn.onPress = function():Void {
with (my_btn) {
temp%2 == 0 ? flag=ok : flag=!ok;
temp++;
if (flag) {
this.my_txt.text="开始"
}
if (!flag) {
this.my_txt.text="暂停"
}
}
};

补充:
今天早上又写了一段纯OOP概念的AS,你可以看一下.
var temp:Boolean = true;
function createTxt(txtName:String, mydepths:Number, x:Number, y:Number, width:Number, height:Number,myText:String):Void {
this.createTextField(txtName, mydepths, x, y, width, height);
with (eval(txtName)) {
text = myText;
border = false;
selectable = false;
}
}
function createBtn(mcname:String, color:String, alpha:Number, x1:Number, y1:Number, x2:Number, y2:Number, depths:Number):Void {
this.mc = createEmptyMovieClip(mcname, depths);
this.mc.lineStyle(1, color, alpha);
this.mc.beginFill(color, 100);
this.mc.lineTo(x1, y2);
this.mc.lineTo(x1, y1);
this.mc.lineTo(x2, y1);
this.mc.lineTo(x2, y2);
this.mc.endFill();
}
function SoundPlay(SoundURL:String) {
var mySound:Sound = new Sound();
mySound.loadSound(SoundURL);
mySound.onLoad=function(loaded){
if(loaded){
mySound.start(1,999)
}
}

}
function SoundStop(){
stopAllSounds()
}
createTxt("my_txt", 1, Stage.width-50, 0, 50, 20,"关 闭");
SoundPlay("http://www.zzjt.gov.cn/jeson/yqnyh.mp3");
createBtn("my_btn", "0x000099", 20, 50, 20, 0, 0, 100)
my_btn.onPress = function():Void {
with(eval(my_txt)){
text = (temp) ? SoundStop() : SoundPlay("http://www.zzjt.gov.cn/jeson/yqnyh.mp3");
text = (temp) ? text="开 始":text="关 闭"
temp = !temp;
}
};