Order Now AdSolution Sign Up | Login » Bits on the Run Sign Up | Login »

Javascript error with embed

33 replies [Last post]

This code below gives me a clientside error when navigating away from the page where the media player was. "Instance" is null... so gives an error when name is begin indexed.

function __flash__removeCallback(instance, name) {
instance[name] = null;
}

maybe try something like this:

function __flash__removeCallback(instance, name) {
if (instance != null) { instance[name] = null; }
}

The problem is that i just embed the player on the page. Does the player not generate its own javascript?

<div id="dvPlayer" style="text-align:center;">
<embed id="theplayerid" name="theplayerid" src="../flash/mediaplayer.swf" width="580" height="350" allowscriptaccess="always" allowfullscreen="true" flashvars="height=350&width=580&file=playlist.aspx&displaywidth=380&thumbsinplaylist=true&enablejs=true&javascriptid=theplayerid&shuffle=false&repeat=list&showeq=false&showstop=true" />
</div>

I only get this error in IE7

same problem with <embed tag here, so that is not the cause

It is happening with the <embed tag. With <object it should be solved....

http://img364.imageshack.us/my.php?image=ie7playererrgw5.gif
http://img364.imageshack.us/my.php?image=ie7playererr2ue1.gif

still happens even embed or object... this occurs if i refresh/reload the page...
the first call is ok, if you press ctrl+r or f5 u get the error...

error with embed is due to the plugin in the browser

sheryar nizar
www.sheryar.net

Is there anyway to fix this problem?

The 4.1 player has this error caught within a try-catch block.

I had this problem too with IE7 win XP and flash 9 plugin and running from my local harddrive. On closing IE threw an error for evey ExternalInterface.addCallback defined in actionscript of the embedded swf.

With me the solution was to NOT do this:

<embed src="movie.swf"/>

but this:

<object>
<param name="allowScriptAccess" value="always" />
<emebed src="movie.swf">
</object>

This not only stopped the javascript errors but also enabled me to call flash methods from javascript, which did not work before.

Solved !!!!
Try this
<object id="HUY" name="HYETA">

Version 4.2 (10/21/2008) IE 7 XP

Problem still exist running following code

<object width="320" height="240">
<param name="allowScriptAccess" value="always" />
<param name="flashvars" value="file=UserData/M2_100_5153.swf" />
<param name="src" value="MediaPlayer/player.swf" />
<embed src="MediaPlayer/player.swf" type="application/x-shockwave-flash" width="320" height="240" flashvars="file=UserData/M2_100_5153.swf"></embed>
</object>

@Felix,

You are trying to play an SWF file in an FLV player. Expect  —BIG—   problems!   :D

@Microsoftmustdie,

works for me. thx.

@andersen: where do I edit this javascript??

@Willieram - please see - http://www.longtailvideo.com/support/tutorials/Javascript-API-Examples
and - http://home5.inet.tele.dk/nyboe/flash/mediaplayer4

note that the examples use swfobject v.2.1 - http://code.google.com/p/swfobject/

As a workaround (this error also happens in other Flash stuff) I unload the Flash movie before closing the window (using window.onbeforeunload).

Is this due to a bug in the Flash player then?

Adding window.onbeforeunload doesn't work for me because it gets triggered when I close a lightbox on the page.

I get the error when closing IE, but mine is loaded with JS, not the embed or object tags.

I really wonder if this is due to the Flash player for IE?

@andersen: can you please be a bit more specific about where to change the javascript? it's really giving me headache...

Let me share with you a "mootools" solution.

First you will have to enclose the <embed or <object tags within a containng DIV of a specific class.

If say all of your these DIVs where of class "jw_player", then the code would be like:

window.addEvent ('beforeunload', function() {
$each($$('jw-player'), function(el) { el.dispose; });
});

You can change the class name to whatever you wand and add several $each sentences as classes you have.

This code will be added to everypage that the site uses the player (or simply everypage as it fails nicely if there are no DIVs like that).

You will have to include mootools core if not already included.

Cheers, Willie.

I'm having the same problem. I've created new function tags for my forum. This is the code I am using:

function EmbedFLV(URL,autostart){
if(autostart != true && autostart != "true" && autostart != "1" && autostart != 1){
autostart = 0; //Replace with default. Default = 0 (false).
}else{
autostart = 1; //Replace with 1, being zero.
}//See if we can continue.
if(URL == null || URL == "illegal"){
//Nope, we can't.
document.writeln(" error: illegal use of flv tag! ");
}else{
//Add the code to the document
document.writeln('<embed src="player2.swf" width="450" height="300" allowscriptaccess="always" allowfullscreen="true" flashvars="file=' + URL + '&skin=./playerskins/snel.swf" ');
}
}

It displays the file just fine but I get that same error in IE8:

function __flash__removeCallback(instance, name) {
instance[name] = null;
}

How would I rewrite this?

I fixed it.

I changed this part of my code:

document.writeln('<embed src="player2.swf" width="450" height="300" allowscriptaccess="always" allowfullscreen="true" flashvars="file=' + URL + '&skin=./playerskins/snel.swf" ');

To this:

document.writeln('<span style="width:450px;height:300px;" id="flashholder1">');
document.writeln('<object type="application/x-shockwave-flash" style="width:450px;height:300px;" data="player2.swf" id="myplayer1" />');
document.writeln('<param name="movie" value="player2.swf" />');
document.writeln('<param name="flashvars" value="file=' + URL + '&skin=./playerskins/snel.swf" />');
document.writeln('</object>');
document.writeln('</span>');

Another fix, for a Joomla 1.5 install:

Add the following javascript to your site:

/*-- Utility Scripts --*/
window.addEvent('beforeunload', function() {

window.__flash__removeCallback =
(function() {
return function(instance, name) {
if (instance) instance[name] = null;
}; // IE 6 dangling semicolon needed
})(); // force another closure to prevent IE memory leaks
});

window.addEvent('beforeunload', function() {
swfobject.removeSWF("JomPlayer");
});

swfobject needs to be 2.2 (the latest)
replace "jomplayer" with the 'id' of your flash object

More info here:
http://code.google.com/p/doctype/wiki/ArticleFixingFlashExternalInterface

Microsoftmustdie

Awesome, fix works perfectly... and your name is SOOOO true!!! :D

Thanks a bunch xx

...For those who didnt see what Microsoftmustdie had done... He's added an ID and a name to the tag:

name="something" id="something"

So u end up with...

<object name="something" id="something" src=".... etc

COOKIE

My solution was close to Anderson's, except that his doesn't guarantee that the player will use your definition. In fact, some time after the object loads, it overwrites your definition. I made a script that just re-sets the function every 10 milliseconds.

<script type="text/javascript">
    (function(){
        var setRemoveCallback = function() {
            __flash__removeCallback = function(instance, name) {
                if (instance) {
                    instance[name] = null;
                }
            };
            window.setTimeout(setRemoveCallback, 10);
        };
        setRemoveCallback();
    })();
</script>

The outer function is there to hide my function definition so that I don't have to worry about name collisions. I need this because I'm generating embed code that has to run on other people's websites. On your own site, you could simplify it to

<script type="text/javascript">
    var setRemoveCallback = function() {
        __flash__removeCallback = function(instance, name) {
            if(instance) {
                instance[name] = null;
            }
        };
        window.setTimeout(setRemoveCallback, 10);
    };
    setRemoveCallback();
</script>

I actually trimmed it down to

<script type="text/javascript">(function(){var s=function(){__flash__removeCallback=function(i,n){if(i)i[n]=null;};window.setTimeout(s,10);};s();})();</script>

Thank you Dave and others
That solution relly worked for me

Thanks agin

/Luke

I was actually fighting the same problem, and Dave's solution seemed to work perfectly. Nicely done.

Any downside to fixing the problem this way?

thanks Dave Smith
i was facing same issue and it has been resolved by solution provided by you

Thanks Dave Smith. I just had the above mentioned problem with EI. Your script works well. Wish you good luck.

Post new comment

  • Allowed HTML tags: <code> <blockquote> <em> <strong> <strike> <ul> <li> <ol>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic).

More information about formatting options