1

I am getting this error "Microsoft JScript runtime error: 'SWFObject' is undefined"

my code looks like this

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>   
    <div id="flashcontent">This text is replaced by the Flash movie. </div>   
<script type="text/javascript">
    var rndPick = 2;
    var rndPick = Math.floor(Math.random() * 16) + 1;
    var movie = "/Flash/sam" + rndPick + ".swf";
    var so = new SWFObject(movie, "mymovie", "955", "170", "8", "#336699");
    so.write("flashcontent");
    setTimeout("location.reload(true);", 14500);  
</script>  

1 Answer 1

4

You're using SWFObject 1.5 syntax, but linking to the SWFObject 2.2 JS file. SWFObject 1.5 and 2.2 are incompatible.

Rewrite your SWFObject code to use the 2.2 syntax. Here is your code converted to SWFObject 2.2 syntax. Note that swfobject.embedSWF is automatically executed when the DOM has finished loading.

<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>   

<script type="text/javascript">
var rndPick = Math.floor(Math.random() * 16) + 1;
var movie = "/Flash/sam" + rndPick + ".swf";

var flashvars = {}; //empty for this example
var params = { bgcolor: "#336699" };  //sets background color
var attributes = { id: "mymovie" }; //sets ID of <object> to "mymovie"

//Optional callback function gets executed after <object> is created
var callbackFn = function (){
    setTimeout("location.reload(true);", 14500);
};

swfobject.embedSWF(movie, "flashcontent", "955", "170", "8", false, flashvars, params, attributes, callbackFn);

</script> 
</head>

<body>
    <div id="flashcontent">This text is replaced by the Flash movie. </div>   
</body>
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you that was it, I had not seen anything talking about SWFObject 1.5 and 2.2 being incompatible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.