I'm assuming my lack of knowledge (I just started learning Flex yesterday, hah!) is the reasoning behind my inability to figure out how to make this work correctly - it may even just be a code positioning issue.
I've got several MP3 files I'm trying to stream. Right now I'm just trying to start and stop the main MP3. I've got the MP3 successfully playing, but stopping it is the issue I'm having. Here's my current code:
<mx:Script>
<![CDATA[
import flash.events.Event;
import flash.media.*;
import flash.media.Sound;
import flash.media.SoundLoaderContext;
import flash.net.URLRequest;
import mx.controls.Button;
//set current track & load song
var currentTrack:Number = 1;
var song:Sound = new Sound();
var req:URLRequest = new URLRequest("../assets/0"+currentTrack+".mp3");
var context:SoundLoaderContext = new SoundLoaderContext(8000, true);
//CREATE BUTTONS (being loaded in mx:application on load)
private function createControls():void {
var playButton:Button = new Button();
playButton.label = "PLAY";
playButton.id = "playButton";
playButton.addEventListener(MouseEvent.CLICK, clickPlayHandler);
playerControls.addChild(playButton);
var stopButton:Button = new Button();
stopButton.label = "STOP";
stopButton.id="stopButton";
stopButton.addEventListener(MouseEvent.CLICK, clickStopHandler);
playerControls.addChild(stopButton);
}
//HANDLE CLICKS
private function clickPlayHandler(event:Event):void {
var button:Button = event.currentTarget as Button;
song.load(req, context);
song.play();
}
private function clickStopHandler(event:Event):void {
var button:Button = event.currentTarget as Button;
//This is not working...
song.close();
}
]]>
So I've got the song.play working, but the song.close doesn't stop the stream, it does nothing. Any clue how I could do this correctly/what I'm doing wrong?
Thanks! :)