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>
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>
Related
I've code like below
<body>
<script type="text/javascript">
function GetRandomNumber() {
var x = Math.floor(Math.random() * 100);
return x;
}
</script>
// GetRandomNumber() is not calling
<script src="app/services/authInterceptorService.js?dev=' + GetRandomNumber(); + '" \></script>
</body>
How can i resolve it ?
You can use document.write which will be render blocking:
<script type='text/javascript'>
document.write('<script src="app/services/authInterceptorService.js?dev=' + GetRandomNumber() + '"></scr'+'ipt>');
</script>
Or create the script tag by hand (Usually recommended method):
<script type='text/javascript'>
var s = document.createElement('script');
s.type = 'text/javascript';
s.src = 'app/services/authInterceptorService.js?dev=' + GetRandomNumber();
document.body.appendChild(s);
</script>
You cannot just call JavaScript functions in that manner. You need to call them from within a script tag, or from a separate file included using a script tag.
Instead, in your existing script, use document.write() to add your new markup including the randomly generated number.
<script type="text/javascript">
function GetRandomNumber() {
var x = Math.floor(Math.random() * 100);
return x;
}
document.write('<script src="app/services/authInterceptorService.js?dev=' + GetRandomNumber() + '"></script>');
</script>
Also, you were writing your script tag as <script ... /></script> when it should be <script ...></script>
My html page has the following 2 scripts:
1.
<script language="javascript" type="text/javascript">
document.write("<iframe id=\"frame\" src=\"http://mywebsite.com/" + "\"scrolling=\"yes\" width=\"850\" height=\"575\" frameborder=0></iframe>");
</script>
2.
<script type="text/javascript">
var myframe = document.getElementById("frame");
if (myframe) {
var myframe_window = document.getElementById('frame').contentWindow;
if (myframe_window) {
myframe_window.confirm = window.confirm;
}
}
</script>
I'm trying to override a methiod in iFrame, but cannot get its id.
What am I doing wrong?
I can't get my Javascript to affect my SWF object.
The object is rendered correctly in the browser but I cannot call the "fill" method that I exposed to the ExternalInterface.
The ready function "flashReady" is not called. Directly calling it from the console says that the flash object does not have the function "fill". Waiting for a while then calling the function does not help.
The error is TypeError: Object HTMLObjectElement has no method 'fill'
Actionscript code:
public class Main extends Sprite
{
public function Main() {
graphics.beginFill(0xff0000);
graphics.drawRect(0, 0, 200, 100);
graphics.endFill();
Security.allowDomain("*");
ExternalInterface.addCallback("fill", fill);
ExternalInterface.call("flashReady");
}
public function fill():void {
graphics.beginFill(0x00ff00);
graphics.drawRect(0, 0, 200, 100);
graphics.endFill();
}
}
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>
Flash UI Demo
</title>
<script type="text/javascript" src="swfobject.js">
</script>
<script type="text/javascript">
function flashReady() {
document.getElementById('AddCallbackExample').fill();
}
var swfVersionStr = "0";
var xiSwfUrlStr = "";
var flashvars = {};
var params = {};
params.quality = "high";
params.bgcolor = "#ffffff";
params.allowscriptaccess = "always";
var attributes = {};
attributes.id = "AddCallbackExample";
attributes.name = "AddCallbackExample";
attributes.align = "middle";
swfobject.embedSWF(
"http://localhost:8001/swf", "flash",
"100%", "100%",
swfVersionStr, xiSwfUrlStr,
flashvars, params, attributes);
</script>
</head>
<body>
<div id="flash" />
</body>
</html>
Ok I figured it out, my version of the library didn't support allowDomain to take in "*" as an argument. I replaced it with "localhost" and it worked.
I have a swf file created by EasyPano tourweaver software. the outpout is a swf file with some .bin files to config the swf and other files such as .jpg, .js and so on.
The software create a html file to add the swf but i have to load the swf using flash and AS3. the HTML and JavaScript that the software create is :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mahan</title>
</head>
<body leftMargin="0" topMargin="0" rightMargin="0" bottomMargin="0">
<script type="text/javascript" src="swfobject.js"></script>
<div id="flashcontent">
To view virtual tour properly, Flash Player 9.0.28 or later version is needed.
Please download the latest version of Flash Player and install it on your computer.
</div>
<script type="text/javascript">
// <![CDATA[
var so = new SWFObject("twviewer.swf", "sotester", "100%", "100%", "9.0.0", "#000000");
so.addParam("allowNetworking", "all");
so.addParam("allowScriptAccess", "always");
so.addParam("allowFullScreen", "true");
so.addParam("scale", "noscale");
//<!-%% Share Mode %%->
so.addVariable("lwImg", "resources/talarmahan_1_firstpage.jpg");
so.addVariable("lwBgColor", "255,255,255,255");
so.addVariable("lwBarBgColor", "255,232,232,232");
so.addVariable("lwBarColor", "255,153,102,153");
so.addVariable("lwBarBounds", "-156,172,304,8");
so.addVariable("lwlocation", "4");
so.addVariable("lwShowLoadingPercent", "false");
so.addVariable("lwTextColor", "255,0,0,204");
so.addVariable("iniFile", "config_TalarMahan.bin");
so.addVariable("progressType", "0");
so.addVariable("swfFile", "");
so.addVariable("href", location.href);
so.write("flashcontent");
// ]]>
</script>
</body>
</html>
Please Help me!
Thanks
The answer is URLVariables passed to the URLRequest feed into load method of Loader:)
example:
var loader:Loader = new Loader();
var flashvars:URLVariables = new URLVariables()
flashvars["lwImg"] = "resources/talarmahan_1_firstpage.jpg";
flashvars["lwBgColor"] = "255,255,255,255";
flashvars["lwBarBgColor"] = "255,232,232,232";
flashvars["lwBarColor"] = "255,153,102,153";
flashvars["lwBarBounds"] = "-156,172,304,8";
flashvars["lwlocation"] = "4";
flashvars["lwShowLoadingPercent"] = "false";
flashvars["lwTextColor"] = "255,0,0,204";
flashvars["iniFile"] = "config_TalarMahan.bin";
flashvars["progressType"] = "0";
flashvars["swfFile"] = "";
flashvars["href"] = this.loaderInfo.url;
var request:URLRequest = new URLRequest("twviewer.swf");
request.data = flashvars;
loader.load(request);
addChild(loader);
also with following helper method you can get main SWF parameters (from it's html wrapper) and pass it to the loaded SWF:
public function getFlashVars(li:LoaderInfo):URLVariables
{
var vars:URLVariables = new URLVariables();
try
{
var params:Object = li.parameters;
var key:String;
for(key in params)
{
vars[key] = String(params[key]);
}
}
catch(e:Error)
{
}
return vars;
}
then
var loader:Loader = new Loader();
var request:URLRequest = new URLRequest("twviewer.swf");
request.data = getFlashVars(this.loaderInfo);
loader.load(request);
addChild(loader);
For SecurityError: Error#2000 and here - there are many reasons behind this error
The following is a simple piece of code to have javascript open up a soundcloud audio player in a pop-up window. It works perfectly in firefox and chrome, but doesn't work in IE7; it just shows a blank black screen. Does anyone know why?
I get the yellow drop down that says "to help protect.. IE has restricted this webpage from running scripts or ActiveX controls...." Even when I click on it and say allow, the soundcloud player still doesn't appear.
<HTML>
<HEAD>
<script type='text/javascript'>
function fetchArguments() {
var arg = window.location.href.split("?")[1].split("&"); // arguments
var len = arg.length; // length of arguments
var obj = {}; // object that maps argument id to argument value
var i; // iterator
var arr; // array
for (var i = 0; i < len; i++) {
arr = arg[i].split("="); // split the argument
obj[arr[0]] = arr[1]; // e.g. obj["song"] = "3"
}
return obj;
}
function loadTitle() {
var args = fetchArguments();
document.title = "Audio: Accidential Seabirds - " + args["name"];
}
function loadMusic() {
var args = fetchArguments();
var height = "100";
object = document.createElement("object");
object.height = height;
object.width = "100%";
nameParam = document.createElement("param");
nameParam.name="movie";
nameParam.value ="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F" + args["song"];
scriptParam = document.createElement("param");
scriptParam.name="allowscriptaccess";
scriptParam.value="always";
embedTag = document.createElement("embed");
embedTag.allowscriptaccess="always";
embedTag.height= height;
embedTag.src="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F" + args["song"];
embedTag.type="application/x-shockwave-flash";
embedTag.width="100%";
object.appendChild(nameParam);
object.appendChild(scriptParam);
object.appendChild(embedTag);
document.getElementsByTagName("body")[0].appendChild(object); // we append the iframe to the document's body
window.innerHeight=100;
window.innerWidth=600;
self.focus();
}
</script>
<script type='text/javascript'>
loadTitle();
</script>
</HEAD>
<BODY bgcolor="#000000" topmargin="0" marginheight="0" leftmargin="0" marginwidth="0">
<center>
<script type='text/javascript'>
loadMusic();
</script>
</center>
</BODY>
</HTML>
The code to call this window might be
function PopupMusic(song, name) {
var ptr = window.open("musicplayer.htm?song="+song+"&name='"+name+"'", song, "resizable='false', HEIGHT=90,WIDTH=600");
if(ptr) ptr.focus();
return false;
}
Listen
I figured it out. You need to use the setAttributeFunction:
function loadVideo() {
var args = fetchArguments();
var videoFrame = document.createElement("iframe");
videoFrame.setAttribute('id', 'videoFrame');
videoFrame.setAttribute('title', 'YouTube video player');
videoFrame.setAttribute('class', 'youtube-player');
videoFrame.setAttribute('type', 'text/html');
videoFrame.setAttribute('width', args["width"]);
videoFrame.setAttribute('height', args["height"]);
videoFrame.setAttribute('src', 'http://www.youtube.com/embed/' + args["vid"]);
videoFrame.setAttribute('frameborder', '0');
videoFrame.allowFullScreen;
document.getElementsByTagName("body")[0].appendChild(videoFrame); // we append the iframe to the document's body
self.focus();
}
Following code works fine in IE/FF/Chrome:
<script type='text/javascript'>
var musicSrc = 'http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fsoundcloud.com%2Frjchevalier%2Fjust-one-day-ft-deni-hlavinka&color=3b5998&auto_play=true&show_artwork=false';
document.write('<object type="application/x-shockwave-flash" width="100%" height="100%" data="'+musicSrc+'"><param name="movie" value="'+musicSrc+'" /></object>');
</script>