I am building a audio sequencer in as3. i have a Track class which contains a play button to play the sound once, a volume slider and 16 check boxes to turn on/off each of the 16 steps. there are 8 instances of Track on the stage. what i want to know is how to uniquely identify what button/slider/check box is being clicked on? and where do i load each sound?
boleow is my Track class
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;
public class Track extends MovieClip
{
private var soundName:Sound;
private var theChannel:SoundChannel;
private var songName:String;
public function Track()
{
// constructor code
trace("track created");
singlePlay.addEventListener(flash.events.MouseEvent.CLICK, handlePlayClick);
}
private function handlePlayClick(e:Event):void
{
trace("Play clicked");
this.play();
}
public function setSoundName(theName:String):void
{
this.songName = theName;
soundName = new Sound();
var req:URLRequest = new URLRequest(this.songName);
soundName.addEventListener(Event.COMPLETE, playSound);
soundName.load(req);
}
public function playSound()
{
theChannel = soundName.play();
}
public function stopSound():void
{
theChannel.stop();
}
}
}
It would be better if you have a central audio player with ability to load differnet audio files (tracks) and UI which will trigger actions on that class instead of building visual element that will handle also playing the audio. You have to learn OOP principles first to be able to do it right (right means: flexible, reusable and easy to maintain/expand):
Books:
to directly answer your question each DispalyObject has a name property you could use this to identify what has been clicked – not ideal.
best regards