actionscript-3 - 删除阵列AS3中每个对象的前一帧对象并使每个文件静音一个音频文件

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

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

这4个音频文件应开始同步(同时),但应降低音量,因此当一个物体击中目标时,它会提高相应音频文件的音量。

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

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

该应用程序位于Flash CS6文件的一帧中。我总共有od 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);
                }
        }

最佳答案

我已经解决了其余对象存在的问题。我只是拿走所有对象,然后将它们转换为影片剪辑即可。我在音频部分还是有问题!

关于actionscript-3 - 删除阵列AS3中每个对象的前一帧对象并使每个文件静音一个音频文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18045632/

相关文章:

apache-flex - 在 Flex 中列表为空时显示的背景图像

php - 从Flash发送JSON到PHP

flash - 在 FF 中,按键滞后于鼠标

android - 音频在Android中无法正常工作

java - SWT:影响拖放手势的检测(或者:如何查询键盘)

xml - atom feed xmlns 属性搞乱了 AS3 的 XML 解析?

vba - WAV音频文件播放完毕后,VBA Powerpoint自动播放下一张幻灯片

c++ - 在C++中与alsa-lib同时播放 '.wav'音频的简单示例?

jQuery UI - 拖放后不能立即工作

HTML5 原生 Drag 'n' Drop - 检测取消