Hi all!
I’ve been banging my head against the wall for a while on this one, so I thought I’d see if there’s someone out here who can tell me what I’m doing wrong.
I’ve got a series of pages that will include audio narration and a swf that controls the audio. At the moment, I’m focusing on just the on/off states. The on/off state is controlled by the SharedObject so that the user doesn’t have to click the “on” button everytime they want to hear the audio, and they don’t have to click the “off” button everytime they don’t. Clicking the “on” button sets [COLOR=blue]lsoUserInfo.data.userid[/COLOR] to a value of 1, and clicking the “off” button sets it to 0. This works fine and once either the on or off button has been clicked, that setting is retained.
What I would like to do is set it up so that the mp3 that is played is determined by the JS and I don’t have to create separate SWF’s for each and every HTML page. Ideally, I’d like to reuse the same swf and just change the SharedObject file using JS when the page loads. I’ve tested it with the mp3 name hard coded in the AS, but I can’t seem to get any variables to load in my SWF when I try to use JS to define the variable. When I trace the SharedObject name for the audio file, it says it’s undefined.
Here’s the AS code:
import flash.external.ExternalInterface;
var lsoUserInfo:SharedObject = SharedObject.getLocal("userData","/");
var loadSong:Sound = new Sound();
lsoUserInfo.data.audioName = ExternalInterface.call("getAudioName");
loadSong.onLoad = function(success:Boolean):Void{
if(success){
if(lsoUserInfo.data.userid == 1 | lsoUserInfo.data.userid == undefined){
loadSong.start();
}
else{
loadSong.stop();
}
}
}
_root.buttonOn.onRelease = function():Void{
if(lsoUserInfo.data.userid != 1){
lsoUserInfo.data.userid = 1;
loadSong.start();
trace(lsoUserInfo.data.userid);
}
}
_root.buttonOff.onRelease = function():Void{
lsoUserInfo.data.userid = 0;
loadSong.stop();
trace(lsoUserInfo.data.userid);
}
loadSong.loadSound("../audio/" + lsoUserInfo.data.audioName + ".mp3", false);
trace(lsoUserInfo.data.audioName);
trace(lsoUserInfo.data.userid);
And here’s the JS code:
<script type="text/javascript">
function getAudioName(){
return "song2";
}
</script>
I’m pretty sure this is something fairly simple that I’m just not seeing (since I’m pretty thoroughly cross-eyed from how long I’ve looked at it so far). My JS is pretty god-awful, though, so that could certainly explain things.
Thanks for looking!