好吧,我正在做一个拖放到目标的小游戏应用程序。我在 dropArray 上命名了 4 个对象,在 hitArray 上命名了 4 个目标,以及与 soundArray 上命名的对象数组相对应的 4 个音频文件。
4 个音频文件应该开始同步(同时),但音量会被调低,所以当一个物体击中目标时,它会调高相应音频文件的音量。
对象正确捕捉到目标。我想出了如何同时启动所有音频文件(也许这不是最好的方法)。
该应用程序的目标是 4 个音频文件对应于歌曲的每个乐器。当你放下让说“dragJuan”到“dragJuan_t”时,“voz.mp3”必须开始发声。音频文件是声乐、吉他、贝斯和鼓。因此,当 4 个音频文件一起播放时,一首歌曲就完成了,这应该在 4 个对象在其目标中时发生。
此应用程序位于 Flash CS6 文件的一帧上。我总共有 8 个框架,其中包含演示文稿的不同页面,只有第二个框架包含这个应用程序。
问题:
1)当一个物体击中目标时,所有的音频文件都会被调高,当它离开目标时会调低。我只需要每个对象打开其相应的音频文件,当它超出其目标时,音量会再次降低。
2)当我单击一个按钮转到我想要的任何帧时,比如说项目的第 4 帧,已单击的 dropArray 对象仍保留在舞台上,并在其帧上的位置拖放。我尝试将 aremoveChild(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);
}
}