View Full Version : swfobject and dynamic load
How do I with swfobject and Javascript create so I can change the movie to a Flashvare?
I know how to use it static address but never got it work with dynamic.
I have create this code inside a HTML page
var mymovie ="test"
var flashvars = false;
var params = {
allowfullscreen: "true",
allowscriptaccess: "always",
wmode: "opaque",
flashvars: "flvpVideoSource=rtmp://adresstotheserver/," + mymovie,
bufferlength: "1",
autostart: "true"
};
var attributes = {
id: "myDynamicContent",
name: "myDynamicContent"
};
swfobject.embedSWF("intro.swf", "myContent", "1000", "563", "9.0.0","expressInstall.swf", flashvars, params, attributes);
and I have a div with name myContent
It play nice but now I dont like it to play any movie intil I press a link
<a href="javascript:myplayer('movie2');">movie 2</a>
I was thinking about add all in a function but then the player dont show and dont work at all.
Depends if you want to leave loading the SWF until the link is clicked or just the video.
To cause an already loaded SWF to load a video you'll want to use ExternalInterface (http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/external/ExternalInterface.html).
I you want to leave loading the SWF until the link is clicked you'll want to call swfobject.embedSWF (http://code.google.com/p/swfobject/wiki/api#swfobject.embedSWF%28swfUrlStr,_replaceElemIdS tr,_widthStr,_height) from the link.
Thanks for you replay
Well I dont want it to play the movie before I click on the link.
I have to use Flashvare because it is no flash that I have create that I going to use.
I just want the flash to be load and prepare for the movie when I push the button.
Sorry for the delay, just realised I hadn't updated my profile here since I changed my email.
If you haven't figured it out, you need to register the play function in ActionScript using ExternalInterface:
ExternalInterface.addCallback( "loadMyVideo", myMoviePlayer.loadVideo );
Then in JavaScript, call the function you defined on the Flash object. Best thing to do is pass a callback to SWFObject and store the reference that passes:
var swfReference;
function myCallback( event )
{
if( event.success )
swfReference = event.ref;
else
// handle error
}
swfobject.embedSWF( "intro.swf", "myContent", "1000", "563", "9.0.0",
"expressInstall.swf", flashvars, params, attributes, myCallback );
<a href="javascript:swfReference.loadMyVideo('movie2');">Movie 2</a>
That is ok :)
Well I have to use flashvars and I dont think I can change so much inside the flash (Like I say it is not my flash that I going to use)
I maybe can fix it to have a emty flv that is going to "play" when someone visit the site but I have no idea how to change the flashvars and then play the flash with swfobject.
I have to change the code that I show at the top and make it work somehow.
Oh, I missed that you can't edit the flash. I don't think it's possible to alter FlashVars at runtime. I'd suggest removing the SWF from the page completely and re-embedding it with the new FlashVars in that case. IIRC just calling swfobject.embedSWF each time should remove the previous object.
var params = {
allowfullscreen: "true",
allowscriptaccess: "always",
wmode: "opaque",
bufferlength: "1",
autostart: "true"
};
var attributes = {
id: "myDynamicContent",
name: "myDynamicContent"
};
function myplayer(movie)
{
var flashvars = {
flvpVideoSource: "rtmp://adresstotheserver/," + movie
};
swfobject.embedSWF("intro.swf", "myContent", "1000", "563", "9.0.0",
"expressInstall.swf", flashvars, params, attributes);
}
myplayer( "test" );
ohh thanks going to try that. I have think about maybe use AJAX
Technically you could use AJAX, but it's massive overkill for what you're trying to achieve - you already have all the data you require on the client.
hmm I did change to you code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>SWFObject 2.0 (dynamisk) - Steg 3</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
var params = {
allowfullscreen: "true",
allowscriptaccess: "always",
wmode: "opaque",
bufferlength: "1",
autostart: "true"
};
var attributes = {
id: "myDynamicContent",
name: "myDynamicContent"
};
function myplayer(movie)
{
var flashvars = {
flvpVideoSource: "rtmp://addresstotheserver/," + movie
};
swfobject.embedSWF("intro.swf", "myContent", "1000", "563", "9.0.0",
"expressInstall.swf", flashvars, params, attributes);
}
myplayer( "intro" );
</script>
</head>
<body>
<div id="myContent">
<p>GET FLASH</p>
</div>
<a href="javascript:myplayer('movie2');">Movie 2</a>
</body>
</html>
and it did play the intro file but nothing happend when I click on the link to movie2
Hmm... guess SWFObject doesn't like doing that then. Try this, it's a bit hacky but should work:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>SWFObject 2.0 (dynamisk) - Steg 3</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
var params = {
allowfullscreen: "true",
allowscriptaccess: "always",
wmode: "opaque",
bufferlength: "1",
autostart: "true"
};
var attributes = {
id: "myDynamicContent",
name: "myDynamicContent"
};
function myplayer(movie)
{
var flashvars = {
flvpVideoSource: "rtmp://addresstotheserver/," + movie
};
document.getElementById("movieHolder").innerHTML =
"<div id=\"myContent\"><p>GET FLASH</p></div>";
swfobject.embedSWF("intro.swf", "myContent", "1000", "563", "9.0.0",
"expressInstall.swf", flashvars, params, attributes);
}
myplayer( "intro" );
</script>
</head>
<body>
<div id="movieHolder">
<div id="myContent">
<p>GET FLASH</p>
</div>
</div>
<a href="javascript:myplayer('movie2');">Movie 2</a>
</body>
</html><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
</body>
</html>
Thanks it did work when I did change a little
I did removemyplayer( "intro" );
And add
<body onload="javascript:myplayer('intro');">
Now it works nice, thanks again :)
Oh yes, that's quite right; the DOM objects we're interested in won't have loaded when the head script fires. Glad you got it working.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.