我很高兴看到一些ActionScript 3.0代码示例,这些示例部署了将在Flash Pro文件中使用的任何类型的声音文件,以最终输出为SWF。
我正在使用(下面)泡泡游戏(某些类型)的Base类的代码,问题是,当弹出时,声音播放的时间有点太晚了,没有出现。
谢谢。
这是我的代码-链接到我的FLA库中的Bubbles:
package
{
import flash.display.*;
import flash.events.*;
import flash.media.Sound;
import flash.net.URLRequest;
public class BubbleBaseNew4 extends MovieClip
{
var thisBubble:MovieClip;
var navdock:MovieClip;
var thisParent:*;
private var snd:Sound = new Sound();
public function BubbleBaseNew4()
{
this.addEventListener(Event.ADDED_TO_STAGE, initialize);//off http://kb2.adobe.com/cps/838/cpsid_83815.html to do ADDED_TO_STAGE instead of ADDED
this.addEventListener(MouseEvent.CLICK, pop);
}
function initialize(event:Event):void
{
this.removeEventListener(Event.ADDED_TO_STAGE, initialize);//this causes sym_mc to be defined as an Ojbect
thisParent = event.currentTarget.parent;
navdock = thisParent.nav_mc;
thisBubble = MovieClip(this.parent.getChildByName(this.name));
this.addEventListener(Event.ENTER_FRAME, moveBubble);
var req:URLRequest = new URLRequest("my_own_twp_noise_tremolo_phaser_.mp3");
snd.load(req);
}
function moveBubble(event:Event):void
{
if(navdock != null && this.hitTestObject(navdock))
{
trace("HIT!");
this.removeEventListener(Event.ENTER_FRAME, moveBubble);
this.removeEventListener(MouseEvent.CLICK, pop);
this.parent.addChild(this);//this adds the bubble that's removed, i think.
this.parent.removeChild(thisBubble);
}
else
{
var mc:MovieClip = event.target as MovieClip;
if(currentFrame == 1)
{
mc.x = Math.random() * stage.stageWidth;
mc.y = Math.random() * stage.stageHeight;
rotation += Math.random() * -90;
}
}
}
function pop(event:MouseEvent):void
{
/*var bzp:Sound = Sound(thisParent.my_own_twp_noise_tremolo_phaser_.wav);
this.load(bzp);*/
this.removeEventListener(Event.ADDED_TO_STAGE, initialize);
this.removeEventListener(MouseEvent.CLICK, pop);
this.removeEventListener(Event.ENTER_FRAME, moveBubble);
var main:MovieClip = MovieClip(this.parent.parent);
main.increaseScore();
//mediary 'increaseScore function' variable
var main4:MovieClip = MovieClip(this.parent.parent);
main4.increaseScore4();
this.parent.removeChild(thisBubble);
snd.play();
}
}
}
最佳答案
您可以尝试两件事。第一种是将pop函数的mouseEventListener从MouseEvent.CLICK
更改为MouseEvent.MOUSE_DOWN
,这样您就不必在调用该函数之前就等待MOUSE_UP
了。
第二件事是确保修剪声音文件,以使开始时绝对没有一纳秒的沉默。 Audacity是用于此类工作的好程序。
关于flash - 在Flash Pro的ActionScript3.0中使用声音文件的代码示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9248713/