I am writing code for a 16 step sequencer with 5 tracks
a sound of any given track can be activated/deactivated for any of the 16 steps.
So far I have 3 classes: Player, Track, Sound
At the moment I'm working on the Track class... for the time being i only have 4 sounds in my Track. I have a timer that and when i press play on a track it plays 4 times(can change it easily to 16) but it plays all the sounds...
my Sound class has a property active that changes alpha of the sBtn in a track. I can activate/deactivate the sounds in the track class and the alpha changes...
The problem is that I cannot figure out how to only play sounds in the track that active...
I'm thinking I should probably do it with an array somehow but a bit lost now...
the code for my Track:
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;
//import flash.media.SoundTransform;
import flash.events.MouseEvent;
import flash.media.SoundTransform;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class Track extends MovieClip
{
private var mySound:Sound = new Sound();
private var myChannel:SoundChannel;
//private var lastPosition:Number = 0; // position of where the song is playing
private var requestSound:URLRequest = new URLRequest("sound1.mp3");
public var soundTimer:Timer = new Timer(500, 4);
var sBtn:SoundBtn;// = new SoundBtn();
var trackSounds:Array = new Array("sBtn1","sBtn2","sBtn3","sBtn4");
var stepCounter:int = 0;
var vTransform:SoundTransform = new SoundTransform();
//vTransform.volume = .5;
//var volumeTransform:SoundTransform = new SoundTransform();
public function Track()
{
// constructor code
trace("track created");
this.playTrack.addEventListener(MouseEvent.CLICK, playSound);
this.playDrum.addEventListener(MouseEvent.CLICK, playSoundDemo);
mySound.addEventListener(Event.COMPLETE, soundLoaded);
soundTimer.addEventListener(TimerEvent.TIMER, timerSoundPlay);
soundTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timerSoundComplete);
mySound.load(requestSound);
}
function soundLoaded(e:Event)
{
//trace("loaded");
}
//this function is only to play the demo of the sound not the actual steps
function playSoundDemo(e:MouseEvent)
{
myChannel = mySound.play();
trace("sound played");
}
function playSound(e:MouseEvent)
{
soundTimer.start();
trace("sound played");
}
function timerSoundComplete(e:TimerEvent)
{
soundTimer.reset();
}
function timerSoundPlay(e:TimerEvent)
{
myChannel = mySound.play();
}
}
}
The SoundBtn class
package
{
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;
import flash.events.IOErrorEvent;
import flash.media.SoundTransform;
public class SoundBtn extends MovieClip
{
public var soundBtnActive:Boolean;
public var _s:Sound;
public var _sChannel:SoundChannel;
public var volumeTransform:SoundTransform = new SoundTransform();
public function SoundBtn()
{
// constructor code
soundBtnActive = true;
this.addEventListener(MouseEvent.CLICK, btnActive);
}
public function btnActive(e:MouseEvent)
{
if (soundBtnActive == true)
{
this.alpha = .5;
this.soundBtnActive = false;
trace("sound deactivated");
}
else
{
this.alpha = 1;
this.soundBtnActive = true;
trace("sound activated");
}
}
}
}
I can also send/post fla.
Can you help please...

New Topic/Question
Reply


MultiQuote



|