删除先前的帧对象,并在阵列AS3中为每个对象静音一个音频文件

时间:2013-08-04 17:33:09

标签: actionscript-3 audio drag-and-drop flash-cs6

好吧,我正在做一个拖放到目标的小游戏应用程序。我在dropArray上有4个对象,在hitArray上有4个目标,4个音频文件对应于soundArray上命名的对象数组。

4个音频文件应该开始同步(同时)但音量调低,所以当一个物体击中目标时,它会调高相应音频文件的音量。

对象正确捕捉到目标。我想出了如何同时启动所有音频文件(也许这不是最好的方式)。

该应用程序的目标是4个音频文件对应于歌曲的每个乐器。当你放下让“dragJuan”到“dragJuan_t”时,“voz.mp3”必须开始响起。音频文件是Vocal,吉他,贝斯和鼓。因此,当4个音频文件一起播放时,一首歌曲就完成了,当4个对象在目标中时就会发生这种情况。

此应用程序位于Flash CS6文件的一个框架上。我总共有8帧与不同的演示页面,只有第二帧包含这个应用程序。

问题:

1)当一个物体击中目标时,所有音频文件都会在其超出目标时被调高并调低。我只需要每个对象都会调出相应的音频文件,当它超出目标时,音量会再次下降。

2)当我点击一个按钮转到我想要的任何帧时,让我们说项目的第4帧,已经点击的dropArray对象仍然在舞台上拖放,就像它在框架上的位置一样。我尝试在下一帧的第一个放置一个removeChild(dragJuan);,它只能用我放的第一个dropArray对象,如果我放入4个对象(每个对象都带有removeChild();)它只适用于第一个对象,另外3个没有。

感谢您提供给我的任何帮助或建议!我是ActionScript的新手,这是一个功课,不知道如何让它工作!

干杯, Monojorge

SoundMixer.stopAll();
stop();

import flash.net.URLRequest;
import flash.media.Sound;
import flash.media.SoundTransform;
import flash.media.SoundChannel;
import flash.media.SoundMixer;
import flash.events.Event;

var hitArray:Array = new Array(dragJuan_t,dragBeto_t,dragFil_t,dragMono_t);
var dropArray:Array = new Array(dragJuan,dragBeto,dragFil,dragMono);
var soundArray:Array = new Array("voz.mp3","bateria.mp3","bajo.mp3","guitarra.mp3");
var positionsArray:Array = new Array();
var songController:SoundChannel;
var sTransform:SoundTransform;

var audioFile:URLRequest=new URLRequest(soundArray[0]);
var audioFile2:URLRequest=new URLRequest(soundArray[1]);
var audioFile3:URLRequest=new URLRequest(soundArray[2]);
var audioFile4:URLRequest=new URLRequest(soundArray[3]);

var song:Sound = new Sound();
var song2:Sound = new Sound();
var song3:Sound = new Sound();
var song4:Sound = new Sound();

song.load(audioFile);
song2.load(audioFile2);
song3.load(audioFile3);
song4.load(audioFile4);

songController = song.play(0, 9999);
songController = song2.play(0, 9999);
songController = song3.play(0, 9999);
songController = song4.play(0, 9999);

trace (soundArray);

SoundMixer.soundTransform = new SoundTransform(0);

//This adds the mouse down and up listener to the drop instances
//and add the starting x and y positions of the drop instances
//into the array.

for (var i:int = 0; i < dropArray.length; i++)
{
        dropArray[i].buttonMode = true;
        dropArray[i].addEventListener(MouseEvent.MOUSE_DOWN, mdown);
        dropArray[i].addEventListener(MouseEvent.MOUSE_UP, mUp);

        positionsArray.push({xPos:dropArray[i].x, yPos:dropArray[i].y});
}



//This drags the object that has been selected and moves it;
//to the top of the display list. This means you can't drag
//this object underneath anything.

function mdown(e:MouseEvent):void
{
        e.currentTarget.startDrag();
        setChildIndex(MovieClip(e.currentTarget), numChildren - 1);
}

//This stops the dragging of the selected object when the mouse is
//released. If the object is dropped on the corresponding target
//then it get set to the x and y position of the target. Otherwise
//it returns to the original position.
function mUp(e:MouseEvent):void
{

        var dropIndex:int = dropArray.indexOf(e.currentTarget);
        var target:MovieClip = e.currentTarget as MovieClip;

        target.stopDrag();

        if (target.hitTestObject(hitArray[dropIndex]))
        {
                target.x = hitArray[dropIndex].x;
                target.y = hitArray[dropIndex].y;
                square_mc.addEventListener(Event.ENTER_FRAME, fl_RotateContinuously);

                SoundMixer.soundTransform = new SoundTransform(1);
                // This is turning up the volume of all audio files and I just need to turn up the volume of the audio that corresponding to the object array.

                trace(target);

        }
        else
        {
                target.x = positionsArray[dropIndex].xPos;
                target.y = positionsArray[dropIndex].yPos;

                SoundMixer.soundTransform = new SoundTransform(0);
                // This is turning down the volume of all audio files and I just need to turn down the volume of the audio that corresponding to the object array.

        }


}


function fl_RotateContinuously(event:Event)
        {
                square_mc.rotation +=  10;
                if (square_mc.rotation == 180)
                {
                        square_mc.removeEventListener(Event.ENTER_FRAME, fl_RotateContinuously);
                }
        }

1 个答案:

答案 0 :(得分:0)

我已经修复了剩余对象的问题。我只需要拍摄所有对象并将它们转换为电影剪辑,就是这样。我仍然有音频部分的问题!