Я сделал грубый пример, надеюсь, давая вам представление о том, как решить вашу проблему.Это помогло бы, если бы вы опубликовали часть своего кода, так как я мог бы адаптировать этот ответ к нему.В любом случае, просто скопируйте и вставьте код в корневой каталог документа, чтобы увидеть, как он работает.
package
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.media.Sound;
import flash.net.URLRequest;
public class Main extends Sprite
{
private var _leafVector:Vector.<Leaf>;
private var _nature:Nature;
private var _playButton:PlayButton;
private var _leafPlayList:LeafPlayList;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}// end function
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
var soundsXml:XML =
<sounds>
<sound name="sound1" url="sounds/sound1.mp3" />
<sound name="sound2" url="sounds/sound2.mp3" />
<sound name="sound3" url="sounds/sound3.mp3" />
<sound name="sound4" url="sounds/sound4.mp3" />
</sounds>
_leafVector = new Vector.<Leaf>();
for (var i:uint = 0; i < soundsXml.children().length(); i++)
{
var sound:Sound = new Sound(new URLRequest(soundsXml.sound[i].@url));
var leaf:Leaf = new Leaf(String(i+1), sound, soundsXml.sound[i].@name);
leaf.x = i * leaf.width;
addChild(leaf);
leaf.addEventListener(MouseEvent.MOUSE_DOWN, onLeafMouseDown);
leaf.addEventListener(MouseEvent.MOUSE_UP, onLeafMouseUp);
_leafVector.push(leaf);
}// end for
_nature = new Nature();
_nature.x = _leafVector[3].x + _leafVector[3].width;
addChildAt(_nature, 0);
_playButton = new PlayButton();
_playButton.x = _nature.x;
_playButton.y = _nature.height;
addChild(_playButton);
_playButton.addEventListener(MouseEvent.CLICK, onPlayButtonClick);
_leafPlayList = new LeafPlayList();
_leafPlayList.x = _playButton.x;
_leafPlayList.y = _playButton.y + _playButton.height;
addChild(_leafPlayList);
}// end function
private function onLeafMouseUp(e:MouseEvent):void
{
var leaf:Leaf = Leaf(e.currentTarget);
leaf.stopDrag();
if (leaf.dropTarget == _nature)
{
_leafPlayList.addLeafSound(leaf.soundName, leaf.sound);
leaf.removeEventListener(MouseEvent.MOUSE_DOWN, onLeafMouseDown);
leaf.removeEventListener(MouseEvent.MOUSE_UP, onLeafMouseUp);
}// end function
}// end function
private function onLeafMouseDown(e:MouseEvent):void
{
var leaf:Leaf = Leaf(e.currentTarget);
this.setChildIndex(leaf, this.numChildren-1);
leaf.startDrag();
}// end function
private function onPlayButtonClick(e:MouseEvent):void
{
_leafPlayList.playLeafSounds();
}// end function
}// end class
}// end package
import flash.display.Sprite;
import flash.media.Sound;
import flash.text.TextField;
internal class Leaf extends Sprite
{
private var _sound:Sound;
private var _soundName:String;
public function get soundName():String
{
return _soundName;
}// end function
public function get sound():Sound
{
return _sound;
}// end function
public function Leaf(text:String, sound:Sound, soundName:String)
{
_sound = sound;
_soundName = soundName;
graphics.lineStyle(1);
graphics.beginFill(0x00FF00);
graphics.drawCircle(25, 25, 25);
graphics.endFill();
var textField:TextField = new TextField();
textField.text = text;
textField.x = width / 2;
textField.y = height / 2;
textField.selectable = false;
addChild(textField);
}// end function
}// end class
internal class Nature extends Sprite
{
public function Nature()
{
graphics.beginFill(0xFFFF00);
graphics.drawRect(0, 0, 200, 200);
graphics.endFill();
}// end function
}// end class
internal class PlayButton extends Sprite
{
public function PlayButton()
{
graphics.lineStyle(1);
graphics.beginFill(0xFF0000);
graphics.drawRect(0, 0, 100,25);
graphics.endFill();
var textField:TextField = new TextField();
textField.text = "PLAY BUTTON";
textField.selectable = false;
addChild(textField);
}// end function
}// end class
import flash.events.Event;
import flash.media.SoundChannel;
internal class LeafPlayList extends Sprite
{
private var _soundChannel:SoundChannel;
private var _leafSoundVector:Vector.<Sound>;
private var _position:int;
private var _playListTextField:TextField;
public function LeafPlayList()
{
_playListTextField = new TextField();
addChild(_playListTextField);
_soundChannel = new SoundChannel();
_leafSoundVector = new Vector.<Sound>();
}// end function
public function addLeafSound(soundName:String, sound:Sound):void
{
_playListTextField.appendText("\n" + soundName);
_leafSoundVector.push(sound);
}// end function
public function playLeafSounds():void
{
_soundChannel.stop();
_position = 1;
_soundChannel = _leafSoundVector[_position - 1].play();
_soundChannel.addEventListener(Event.SOUND_COMPLETE, onSoundChannelSoundComplete);
}// end function
private function onSoundChannelSoundComplete(e:Event):void
{
if (!(_position == _leafSoundVector.length)) _position++
else _position = 1;
playNexLeafSound();
}// end function
private function playNexLeafSound():void
{
_soundChannel = _leafSoundVector[_position - 1].play();
_soundChannel.addEventListener(Event.SOUND_COMPLETE, onSoundChannelSoundComplete);
}// end function
}// end class