I have the following code, its on the first frame on my flash and I have two buttons at the moment, but when I press one the sound start off ok but then when I press the other button it plays over the ither so it sounds terrible, so I placed a stop in the next sound function but this i snow giving issues:
import flash.display.*;
import flash.media.*;
import flash.net.*;
import flash.text.*;
import flash.events.*;
var _sound:Sound;
var _channel:SoundChannel;
// song button functions (buttons found on the main fla file.
songOne.addEventListener(MouseEvent.CLICK, one);
function one(event:MouseEvent):void {
var nextSong:String = "http://...to mp3";
songChange(nextSong);
}
songTwo.addEventListener(MouseEvent.CLICK, two);
function two(event:MouseEvent):void {
var nextSong:String = "http://...to mp3";
songChange(nextSong);
}
/// the next song function
function songChange(nextSong:String):void {
_channel.stop();
_sound = new Sound(new URLRequest(nextSong));
_sound.play();
}
the error I get is when i put this in _channel.stop();…
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at jukeboxAS3_ALLONE_2_fla::MainTimeline/songChange()
at jukeboxAS3_ALLONE_2_fla::MainTimeline/one()
with out the stop they will simply keep playing over each other.
Any ideas I read that I simply need to add a stop to my channel variable but this does not work but throws up the error.
thank you