I have a Flash movie on a web page and I want to send parameters to it with JavaScript to have it go to a selected frame. The AS3 code receives its information via an ExternalInterface API. The following code parses the URL argument (?page=x) and I want to send the value (x) to Flash. Unfortunately, when creating the objMovie variable, it is always undefined, therefore getFlashMovie is undefined and Flash never receives the callback.
Thinking that it was because the flash movie is not loaded yet, I created a button to call callToActionscript, and when I click the button, I get the same error. (getFlashMovie("myFlashMovie") is undefined)
I am not seeing what I'm doing wrong (mainly because I'm a newbie...). Please enlighten me.
Also,
if (params)
always returns true, whether there are parameters or not. I don't understand that, either.
The code follows:
<script >
$(document).ready(function() {
var params=getQueryParameters();
if(params) {
callToActionscript(params[0]);
}
});
function getFlashMovie(movieName) {
var isIE = navigator.appName.indexOf("Microsoft") != -1;
var objMovie = (isIE) ? window[movieName] : document[movieName];
alert(objMovie); //Always return undefined
return objMovie;
}
function callToActionscript(page)
{
var myMovie=getFlashMovie("myFlashMovie").sentToActionscript(page);
}
function getQueryParameters() {
var query = window.location.href.split('?')[1];
//query won't be set if ? isn't in the URL
if(!query) {
return { };
}
else
{
var param = query.split('=');
}
return param[1];
}
</script>