// Created by Grant Hinkson
// -- Catalist Creative
// -- http://www.catalistcreative.com
//
// The fundamentals of much of this code is derived from information
// presented in the book "Flash and XML" written by
// Dov and Jesse Jacobson (http://www.flashandxml.com)
// Now, on to the code...
// Functions called by buttons
/*
radioPlay();
radioStop();
radioNext();
radioPrevious();
stationNext();
stationPrevious();
*/
// Define XML file to be loaded (actually loaded in
// the movieclip "cxml". Once loaded, cxml advances this
// timeline to the next frame
cxml.url = "radio.xml";
// Define Objects to hold radio
function Song
(title
, composer
, file) { this.title = title;
this.composer = composer;
}
function Station (name, arrSongs) {
this.name = name;
this.arrSongs = arrSongs;
}
function Radio (arrStations) {
this.arrStations = arrStations;
}
function traceRadio (objRadio) {
for (j=0; j<objRadio.arrStations.length; j++) {
traceStation(objRadio.arrStations[j]);
}
}
function traceStation (objStation) {
// first, display station name
trace ("-----------------");
trace ("Station Name: "+objStation.name);
// now display all songs
for (i=0; i<objStation.arrSongs.length; i++) {
traceSong(objStation.arrSongs[i]);
}
}
function traceSong (objSong) {
trace ("title: "+objSong.title);
trace ("composer: "+objSong.composer);
trace
("file: "+objSong
.file); trace ("**");
}
// Not in Use... loaded drop-down list
function loadStations() {
mcStations.removeAll();
for (var i = 0; i < objRadio.arrStations.length; i++) {
mcStations.addItem(objRadio.arrStations[i].name,i);
}
}
function radioPlay () {
trace (">>start");
traceSong(objRadio.arrStations[intStation].arrSongs[intSong]);
txtTitle = objRadio.arrStations[intStation].arrSongs[intSong].title;
txtStation = objRadio.arrStations[intStation].name;
txtComposer = objRadio.arrStations[intStation].arrSongs[intSong].composer;
if (!s) {
s = new Sound();
s.onSoundComplete = function () {
_root.radioNext();
}
}
var filename
= objRadio
.arrStations
[intStation
].arrSongs
[intSong
].file s.loadSound(filename, true);
s.start();
instStatus.posReset();
instStatus.gotoAndPlay(1);
mLoaded.paramTarget = "s";
mLoaded._visible = true;
mLoaded.gotoAndPlay(1);
}
function radioStop () {
trace (">>stop");
s.stop();
}
function radioNext () {
intSong++;
if (intSong>=objRadio.arrStations[intStation].arrSongs.length) {
intSong = 0;
}
radioPlay();
}
function radioPrevious () {
intSong--;
if (intSong<0) {
intSong = objRadio.arrStations[intStation].arrSongs.length-1;
}
radioPlay();
}
function stationNext () {
intStation++;
if (intStation>=objRadio.arrStations.length) {
intStation = 0;
}
intSong = 0;
radioPlay();
}
function stationPrevious () {
intStation--;
if (intStation<0) {
intStation = objRadio.arrStations.length-1;
}
intSong = 0;
radioPlay();
}
// Initialize Variables
intStation = 0;
intSong = 0;
_root
.newSongArray
= new Array();_root
.newStationArray
= new Array();_root.objRadio = new Radio();
stop();