Reputation: 68
I'm having great problems getting Javascript to resume a flash file.
The flash file loads up and the video is set to autoplay false
. For some reason, any Javascript is not recognising the AS3 function. It keeps saying the function is undefined. e.g.
function getFlashMovie(movieName) {
var isIE = navigator.appName.indexOf("Microsoft") != -1;
return (isIE) ? window[movieName] : document[movieName];
}
function callToActionscript(str)
{
getFlashMovie("video").sendToActionscript(str);
}
sendToActionscript
is undefined
.
Any help would be great.
Thanks Mark
Upvotes: 2
Views: 364
Reputation: 451
To use javascript to play your video, you need to do three things.
First set up an actionscript method in your flash file ,eg:
import flash.external.ExternalInterface;
// create the callback to allow the js to call the method
ExternalInterface.addCallback("playMyVideo", playMyVideo);
function playMyVideo():void
{
video.play();//where video is the name of the video component
}
Next create your javascript function to call the AS method:
function getFlashMovie(movieName) {
var isIE = navigator.appName.indexOf("Microsoft") != -1;
return (isIE) ? window[movieName] : document[movieName];
}
//js function to call the AS3 method
function callToActionscript()
{
//NB this is the name of the swf in the HTML and not the video component
getFlashMovie("mySWF").playMyVideo();
}
Finally you need to allow the swf to communicate with Javascript in the HTML page. The allowScriptAccess param must be set. By default this is set to ‘sameDomain’ which allows scripts only when the SWF resides in the same sub-domain as the host web page. Setting this to ‘always’ allows all scripts to call out from the SWF.
Upvotes: 1