views:

210

answers:

1

Ok I have a flex app and I am adding a callback method like this:

private function init():void
{   
    ExternalInterface.addCallback( "playVideo", playVideo );
}

private function playVideo(videoSource:String):Boolean
{
    videoDisplay.source = videoSource;
    return true;
}

I am calling it with javascript like this:

function showVideo(video)
{
    document.getElementById("video_overlay").style.display = "block";
    //alert('no error');
    document.getElementById("MiniMacVideoPreview").playVideo('https://www.kranichs.com/instore/minimac/videos/'+video);
}

I get this javascript error:

Object does not support this property or method.

However if I uncomment and run the alert first. I get no error and it works perfectly.

My first thought was that the alert was buying time until the script could execute, so i tried to run the script inside a setTimeout() but did not work.

Any ideas?

Thanks!

+2  A: 

I would try placing your code in something like jquery's $(window).load function. I have a feeling that you are exactly right. By the time you close the alert, the dom and contents are finished loading and you can make your ExternalInterface callback method.

$(window).load

Otherwise, if you are using swfobject, you could do something like

swfobject.addLoadEvent(function() {
   $("#swf_id").get(0).inited(callSomeOtherFunction()); 
});
sberry2A
+1 for suggesting the DOM be completely loaded before calling the SWF object, but I wouldn't use JQuery just for that. A simple window.onload = function { // }; would suffice.
Christian Nunciato