I need some help to implement swfobject.
I add this to my page:
<script src="https://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js" src_type="url" />
then I create a div with ID: flash-banner
<div id="flash-banner"></div>
and this is how I try to call the swfobject
<script>
var flash = document.getElementById("#flash-banner");
swfobject.embedSWF("pub/media/wysiwyg/welcome.swf", flash, 300, 120, 10);
</script>
I do something wrong? What is not good here?
Thank you
As mentioned, no one should be doing anything new with Flash these days - it's a dead end technology (I don't have it installed in any of my browsers, on any platform, for example). But the technical problem is that embedSWF wants the name of the ID as a string, but document.getElementByID returns the object, not its name. So, what you want is simply:
<script>
swfobject.embedSWF("pub/media/wysiwyg/welcome.swf", "flash-banner", "300", "120", "10");
</script>
swfobject should be avoided because it no longer works in Chrome.
More details in this answer: swfobject.embedSWF not working?
Related
hiii all,
this is my very first post on stackoverflow, I always used to be a guy sitting back and see what happens here, never contributed, but now i finally got a chance..
MY question is I have a swf file, and I am playing it on my html page using SWFObject,now I want to implement a javascript method which triggers when videos gets completely played or get stopped..
here's my code
<html><head>
<title>PENSIONS BOOST</title>
<script type="text/javascript" src="https://aimhighermarketing.s3.amazonaws.com/videocontrollers/swfobject.js"></script>
</head><body>
<div id="player" align="center">
<script type="text/javascript">
var so = new SWFObject('https://aimhighermarketing.s3.amazonaws.com/videocontrollers/player.swf','mp1','640','480','10');
so.addParam('allowscriptaccess','always');
so.addParam('allowfullscreen','true');
so.addVariable('frontcolor','FFFFFF');
so.addVariable('lightcolor','FFFFFF');
so.addVariable('screencolor','FFFFFF');
so.addParam('flashvars','&file=HTTP://soci7361#socialnetworkbizbuilder.com/videos/pbsalesvideov2.mp4&&controlbar=none&autostart=true');
so.write('player');</script>
</div>
</body>
</html>
,any kind of help is very much appreciated..
Kindly help..
Thanks
Would love to help you out, but unfortunately you are missing very important information. SWFObject is just a tool to place the object tag safely on the user's browser. Remember those days you had to click on the OBJECT tag in order to activate it? Well, SWFObject fixes that... and much more.
What we need to know is which video player are you using? Flash is actually what fires the events to a javascript, which is what you'd be listening for.
The most popular of them is usually JWPlayer or Flowplayer.
If you can let us know which one it is, or what kind of flash player you are using, I'd be happy to do some quick research for you.
Never mind, I just visited your SWF File and found it is JW Player 4.
Here is the JS Code to listen for event changes:
var player;
function playerReady(object) {
player = document.getElementById(object.id);
player.addModelListener("state","playerStateChanged");
}
function playerStateChanged(obj) {
if (obj.newstate == 'COMPLETED') {
// Your video has finished playing
} else if (obj.oldstate == 'IDLE' AND obj.newstate == 'PLAYING') {
// Your video started to play. Now, this is not fully accurate. IDLE can also mean they pressed STOP and sat there.
}
}
In all reality, you should have a "startedVideo = false;" and on the first play change it to true. Then you'll be able to tell when it was first started playing..
Even though JWPlayer is up to version 5, they do still have a full JS API Doc online:
JWPlayer 4 JavaScript API
I'm a javascript beginner, and I'm trying to figure out why this code works when written in the head, but not when it's being referenced from an external file.
in the head of my html document, I'm referencing the javascript file "quote.js" as follows.
<script type="text/javascript" language="JavaScript" src="/js/quote.js"> </script>
the contents of quote.js are as follows
var textarray = [
"Be Good.",
"Our future depends powerfully on how well we understand the cosmos.",
"Bottomless wonders spring from simple rules... repeated without end.",
"All our science, measured against reality, is primitive and childlike — and yet, it is the most precious thing we have.",
"To use violence is to already be defeated."
];
function RndText() {
var rannum= Math.floor(Math.random()*textarray.length);
document.getElementById('ShowText').innerHTML=textarray[rannum];
}
window.onload = function() { RndText(); }
finally, the div I'm replacing in the body is as follows...
<div id = "ShowText"></div>
it's probably a stupid mistake, but I've been trying to track it down for a while now, and I'm missing something. When I write the contents of quote.js in my html head, it works fine. Any ideas? Thanks in advance.
If the code works in the head, but not when included, it's likely to be a problem with the path to the script. Double check that /js/quote.js is an appropriate location. It may need to be js/quote.js, you you may have a typo. In browsers like FireFox and Chrome, if you view the source code of your page you can click on the path to files like this and it loads the included file or shows you an error if the file is not found.
If you can share a link to the page, I can tell you with more certainty exactly what the problem is.
Also, you don't have to the language attribute if you're using XHTML, but that's not causing the problem.
Perhaps the code is running before the DOM is ready
Instead of onload use the event DOMContentLoaded
document.addEventListener('DOMContentLoaded', function () {
//code here
}, false);
I am using jwplayer to play embedded video,
the javascript api tells me
jwplayer("mediaplayer").getPosition()
will get the current position, but my result is undefined
Can anyone help me get the correct resilts
Works fine for me just how the documentation specifies :
<div id="container"></div>
jwplayer("container").setup({
file: "http://content.bitsontherun.com/videos/nPripu9l-60830.mp4",
flashplayer: "http://player.longtailvideo.com/player.swf",
image: "http://content.bitsontherun.com/thumbs/nPripu9l-480.jpg",
height: 270,
width: 480
});
var state = jwplayer("container").getState();
var elapsed = jwplayer("container").getPosition();
How does your HTML and JavaScript look? Without seeing these, I can only assume the following.
According to the API documentation on the website this can be achieved without specifying a container, like so...
jwplayer().getPosition()
I would like to update the flashvars value argument to view another video:
<param name='flashvars' value='movieId=1002' />
I found out that I can make it work in Firefox by updating the parameter with the extra step of readding the whole flash contents.
$("param[name=flashvars]").attr("value", "movieId=33");
$("embed").attr("flashvars", "movieId=33");
$(".root").append($("#video"));
But this does not work in IE8 as the browser won't refresh the flash contents. Any ideas on how to reload the flash contents without external dependencies like swfobject.js?
I'm curious about this too. I'm trying to send a new string via flashvars to a SWF that I have no opportunity to change, and just changing the flashvars with jQuery, without having to use externalinterface, is the best option.
// update flashvars
var fv = 'foobar=1';
$("object param[name='flashvars']").attr("value", fv);
$("embed").attr("flashvars", fv);
// create new object to hold it
var obj = $("object");
// remove existing Flash from DOM
$("object").remove();
// add new HTML to DOM
$("#mviewer").append(obj.html());
If you want to change the flash vars and reload the Flash, you should just remove the SWF from the DOM and embed it again with your new vars (using SWFObject or whatever other method suits your fancy!).
If you want to change the flash vars without reloading the Flash, you're out of luck: there's no officially-supported way. In this case, you should use ExternalInterface to call ActionScript methods that update your values from JavaScript.
Instead of using flashvars, you could use the ExternalInterface AS3 class to send the new value to Flash.
ExternalInterface allows for a two way communication between AS3 & Javascript
Actually, why not use swfobject.js ?
I did like this :
<script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="js/swfobject.js"></script>
<div id="qsound"></div>
<script type="text/javascript">
if(q.sound) {
swfobject.embedSWF("js/dewplayer/dewplayer.swf", "qsound", "60", "20", "9.0.0", false, {'mp3': 'sounds/'+q.sound}, {'wmode': 'transparent'});
$('#qsound').show();
} else {
$('#qsound').hide();
}
</script>
I've seen many web pages with a simple sound on /sound off button which plays music or some mp3 file when you press sound on and turns it off when you press off.
How do I do that?
Hi, I wasn't planning on using Flash -- if there is a standard plugin I could use and then make modification to the script, that'd be cool.
I'm open to whatever is the "standard" way to do it.
Here's the proper way to do it in AS3.
Initialization:
var sound:Sound;
var channel:SoundChannel;
var pos:Number;
var numLoops:Number = 0; // 0 to loop forever
sound = new Sound();
sound.load( new URLRequest("song.mp3") );
channel = sound.play( 0, numLoops );
Stop playback:
pos = channel.position;
channel.stop();
Start playback:
channel = sound.play( pos, numLoops );
It's true that you could toggle the volume to zero and back, but this leaves needless overhead, and when you restart the sound it will have advanced from where you "stopped" it.
I used google and then I used pixel1 standalone
You can try embed my Javascript SoundPlayer and see if that works out for you. Its easy to use, just copy the code below into your webpage.
<script language="javascript" type="text/javascript" src="http://lablogic.net/scripts/soundplayer/audio_o.js"></script>
<a href="#" onclick='play("your-sound-file.mp3")'>PLAY</a>
<a href="#" onclick='stop("your-sound-file.mp3")'>STOP</a>
just change "your-sound-file.mp3" to the url or location of your sound file. It should work in most browser and most sound format. If it doesnt work I would really like to get feedback, so I can improve it even more. You can try out the script here to see if it works first: free javascript sound player
Are you using Flash? In that case you can do it like this:
stopAllSounds();
or
theSound.stop(["id"]);
Assuming you are using Flash as above.
AS2
stopAllSounds();
AS3
var xf:SoundTransform = SoundMixer.soundTransform;
xf.volume = 0;
SoundMixer.soundTransform = xf;