Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flash 同步声音_Flash_Actionscript 3_Actionscript_Flash Cs4 - Fatal编程技术网

Flash 同步声音

Flash 同步声音,flash,actionscript-3,actionscript,flash-cs4,Flash,Actionscript 3,Actionscript,Flash Cs4,似乎我的声音是不同步的,我播放movieclip的时间越长,它就越不同步。没什么太复杂的,只是一些基本的射击声音,每次我击中空格键时都会发出。我的代码如下: package com.objects{ import flash.display.MovieClip; import flash.media.Sound; import flash.media.SoundChannel; import flash.net.URLRequest; import fl

似乎我的声音是不同步的,我播放movieclip的时间越长,它就越不同步。没什么太复杂的,只是一些基本的射击声音,每次我击中空格键时都会发出。我的代码如下:

package com.objects{

    import flash.display.MovieClip;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.net.URLRequest;
    import flash.events.Event;

    public class Avatar extends gameObject implements IKiller{

        public var targets:Array;
        public var delay:Number = 3000;
        public var weapon:Number = 1;
        private var fireSound:Sound;
        private var fireSound2:Sound;
        private var systems:Array;
        private var ext:Number = -1;
        private var channelTracer:SoundChannel;
        private var channelCount:Number = 0;


        public function Avatar():void
        {
            systems = new Array();
            channelTracer = new SoundChannel();
            var soundUrl = new URLRequest("com/images/mashingun_darkt.mp3");
            fireSound = new Sound();
            fireSound.load(soundUrl);

            var soundUrl = new URLRequest("com/images/mashingun_light.mp3");
            fireSound2 = new Sound();
            fireSound2.load(soundUrl);

            rotation = -90;
            lastTime = getTime();
            targets = new Array();
        }

        private function soundFinished(e:Event):void {
            channelCount--;
            trace(channelCount);
        }


        public function get Systems():Array
        {
            return systems;
        }

        override public function Attack(dir:Number = -40):void
        {
            switch(weapon){

                case 1:                 
                    var bullet1:Bullet = new Bullet();
                    bullet1.wielder = this;
                    bullet1.x = x + 35;
                    bullet1.y = y + 30;
                    bullet1.bulletDir = rotation;
                    eApi.addGameChild(bullet1);

                    var bullet2:Bullet = new Bullet();
                    bullet2.bulletDir = rotation;
                    bullet2.wielder = this;
                    bullet2.x = x - 35;
                    bullet2.y = y + 30;
                    eApi.addGameChild(bullet2);

                    var rand = Math.ceil(Math.random() * 100);
                    if (rand < 50) {
                        channelTracer = fireSound.play();
                        //RndSound = RndSound+50;
                    } else {
                        channelTracer = fireSound2.play();

                    }
                    channelTracer.addEventListener(Event.SOUND_COMPLETE, soundFinished);
                    channelCount++;
                    trace(channelCount);

                break;
                case 2:
                    if((getTime() - lastTime) > delay)
                    {
                        var missle = new Missile();
                        missle.shootOut *=  ext;
                        ext *= -1;
                        missle.x = x;
                        missle.y = y;
                        trace(ext);
                        missle.wielder = this;
                        eApi.addGameChildAt((eApi.numChildren - 2),missle);
                        lastTime = getTime();
                    }
                break;
                case 3:
                    var bullet1:Bullet = new Bullet();
                    bullet1.wielder = this;
                    bullet1.x = x + 35;
                    bullet1.y = y + 30;
                    bullet1.bulletDir = -80;
                    eApi.addGameChild(bullet1);

                    var laser = new StingerLaser();
                    laser.laserDir = -90;
                    laser.wielder.push(this);
                    laser.x = x + 20;
                    laser.y = y + -3;
                    eApi.addGameChild(laser);

                    var laser2 = new StingerLaser();
                    laser2.laserDir = -90;
                    laser2.wielder.push(this);
                    laser2.x = x + -20;
                    laser2.y = y + -3;
                    eApi.addGameChild(laser2);

                    var bullet2:Bullet = new Bullet();
                    bullet2.bulletDir = -100;
                    bullet2.wielder = this;
                    bullet2.x = x - 35;
                    bullet2.y = y + 30;
                    eApi.addGameChild(bullet2);
                break;              
                case 4:
                    if((getTime() - lastTime) > delay)
                    {
                        var missle1 = new Missile();
                        missle1.shootOut =  2;
                        missle1.x = x;
                        missle1.y = y;
                        missle1.wielder = this;
                        eApi.addGameChildAt((eApi.numChildren - 2),missle1);

                        var missle2 = new Missile();
                        missle2.shootOut =  -2;
                        missle2.x = x;
                        missle2.y = y;
                        missle2.wielder = this;
                        eApi.addGameChildAt((eApi.numChildren - 2),missle2);
                        lastTime = getTime();
                    }
                break;
                case 5:
                    if((getTime() - lastTime) > delay)
                    {
                        var side:Number = 1;
                        for(var i = 0; i < 20; i+=2)
                        {
                            var missle1 = new Missile();
                            missle1.shootOut =  (i+2) * side;
                            side *= -1;
                            missle1.straightShot = true;
                            missle1.x = x;
                            missle1.y = y;
                            missle1.wielder = this;
                            eApi.addGameChildAt((eApi.numChildren - 2),missle1);
                        }
                        lastTime = getTime();
                    }
                break;
                default:
            }
        }

        public function Hit(dmg:Number = .01):void {
            if(health > 0)
                health -= dmg;

            if(health < 0)
                health = 0,trace("dead");
        }

        override public function updateObject():void
        {

        }
    }
}
包com.objects{
导入flash.display.MovieClip;
导入flash.media.Sound;
导入flash.media.SoundChannel;
导入flash.net.URLRequest;
导入flash.events.Event;
公共类化身扩展游戏对象实现IKiller{
公共var目标:数组;
公共var延迟:数字=3000;
公共var武器:编号=1;
私人声音:声音;
私人音箱2:声音;
私有var系统:数组;
私有变量ext:Number=-1;
专用var信道跟踪器:SoundChannel;
私有变量channelCount:Number=0;
公共函数Avatar():void
{
systems=新数组();
channelTracer=新的SoundChannel();
var soundUrl=newurlrequest(“com/images/mashingun_darkt.mp3”);
fireSound=新声音();
fireSound.load(soundUrl);
var soundUrl=newurlrequest(“com/images/mashingun_light.mp3”);
fireSound2=新声音();
fireSound2.加载(soundUrl);
旋转=-90;
lastTime=getTime();
目标=新数组();
}
私有函数soundFinished(e:事件):无效{
信道计数--;
跟踪(信道计数);
}
公共函数get Systems():数组
{
返回系统;
}
重写公共函数攻击(dir:Number=-40):无效
{
开关(武器){
案例1:
变量bullet1:Bullet=新Bullet();
bullet1.Welver=这个;
bullet1.x=x+35;
1.y=y+30;
bullet1.bulletDir=旋转;
eApi.addGameChild(bullet1);
变量bullet2:Bullet=newbullet();
bullet2.bulletDir=旋转;
bullet2.持用者=此;
bullet2.x=x-35;
2.y=y+30;
eApi.addGameChild(bullet2);
var rand=Math.ceil(Math.random()*100);
如果(兰特<50){
channelTracer=fireSound.play();
//RndSound=RndSound+50;
}否则{
channelTracer=fireSound2.play();
}
channelTracer.addEventListener(Event.SOUND_COMPLETE,soundFinished);
channelCount++;
跟踪(信道计数);
打破
案例2:
if((getTime()-lastTime)>延迟)
{
var导弹=新型导弹();
导弹射击*=分机;
ext*=-1;
导弹x=x;
导弹y=y;
跟踪(ext);
Missel.Welver=这个;
eApi.addGameChildAt((eApi.numChildren-2),misse);
lastTime=getTime();
}
打破
案例3:
变量bullet1:Bullet=新Bullet();
bullet1.Welver=这个;
bullet1.x=x+35;
1.y=y+30;
bullet1.bulletDir=-80;
eApi.addGameChild(bullet1);
var激光=新的StingerLaser();
激光。激光红外线=-90;
激光。持用者。推(这个);
激光,x=x+20;
激光,y=y+-3;
eApi.addGameChild(激光);
var laser2=新的StingerLaser();
laser2.laserDir=-90;
激光2。持用者。推(这个);
激光器2.x=x+-20;
激光器2.y=y+-3;
eApi.addGameChild(激光2);
变量bullet2:Bullet=newbullet();
bullet2.bulletDir=-100;
bullet2.持用者=此;
bullet2.x=x-35;
2.y=y+30;
eApi.addGameChild(bullet2);
打破
案例4:
if((getTime()-lastTime)>延迟)
{
var missle1=新导弹();
失误1.枪战=2;
missle1.x=x;
错误1.y=y;
missle1.Welver=这个;
eApi.addGameChildAt((eApi.numChildren-2),missle1);
var missle2=新导弹();
米斯利2。枪战=-2;
missle2.x=x;
missle2.y=y;
missle2.Welver=这个;
eApi.addGameChildAt((eApi.numChildren-2),missle2);
lastTime=getTime();
}
打破
案例5:
if((getTime()-lastTime)>延迟)
{
var侧:数字=1;
对于(变量i=0;i<20;i+=2)
{
var missle1=新导弹();
错1.枪战=(i+2)*方;
边*=-1;
missle1.straightShot=正确;
missle1.x=x;
错误1.y=y;
missle1.Welver=这个;
eApi.addGameChildAt((eApi.numChildren-2),missle1);
package {
    import flash.display.MovieClip;
    import flash.events.*;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.net.URLRequest;

    public class test extends MovieClip
    {
        private var fireSound:Sound;
        private var fireSound2:Sound;
        private var aKeyPress:Array;

        public function test():void
        {
            aKeyPress = new Array();
            var soundUrl = new URLRequest("com/images/mashingun_darkt.mp3");
            fireSound = new Sound();
            fireSound.load(soundUrl);

            var soundUrl = new URLRequest("com/images/mashingun_light.mp3");
            fireSound2 = new Sound();
            fireSound2.load(soundUrl);
            addEventListener(Event.ENTER_FRAME, loop);
            stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownListener);
            stage.addEventListener(KeyboardEvent.KEY_UP,keyUpListener);
        }
        private function keyDownListener(e:KeyboardEvent) {
            //trace("down e.keyCode=" + e.keyCode);         
            aKeyPress[e.keyCode]=true;
        }

        private function keyUpListener(e:KeyboardEvent) {
            //trace("up e.keyCode=" + e.keyCode);
            aKeyPress[e.keyCode]=false;
        }
        public function loop(e:Event):void
        {
            if (aKeyPress[32]){//Right
                    var rand = Math.ceil(Math.random() * 100);
                    if (rand < 50) {
                        fireSound.play();
                        //RndSound = RndSound+50;
                    } else {
                        fireSound2.play();
                    }
            }
        }
    }
}
private var channelTracer:SoundChannel;
private var channelCount:number = 0;
//...

private function soundFinished(e:Event):void {
channelCount--;
trace(channelCount);
}

//...

var rand = Math.random() * 100;
if (rand < 50) {
channelTracer = fireSound.play();
} else {
channelTracer = fireSound2.play();
}
channelTracer.addEventListener(Event.SOUND_COMPLETE, soundFinished);
channelCount++;
trace(channelCount);