Jump to content

Div removal set up on a timer...


Derleek

Recommended Posts

So javascript is some-what uncharted ground for me, but i think i have some use for it here.

 

I have a flash video embeded over the content of a website, i need it to disappear once it is done running.  Is there a way to do that using JavaScript? - its the only possible solution that is coming to mind.

 

I am thinking that i have a script that writes the div/embed for 5 seconds (duration of the .swf) and stops after that...

 

Is this possible?

 

are there any other (possible/better) solutions to this?

Link to comment
https://forums.phpfreaks.com/topic/117225-div-removal-set-up-on-a-timer/
Share on other sites

I don't know jack about Flash. But, you can certainly do what you describe. I'm just not certain that a flash object will initiate correctly. I'll let you figure that out.

 

Here is some rough code:

<html>
<head>

<script type="text/javascript">

function showFlash(objID, source, width, height, seconds) {

    milliseconds = seconds * 1000;  //Convert to milliseconds

    var embedCode  = '<embed type="application/x-shockwave-flash"';
        embedCode += ' pluginspage="http://www.adobe.com/go/getflashplayer"';
        embedCode += ' width="'+width+'" height="'+height+'" src="'+source+'" />';
        embedCode += '<noembed><p>Alternative content</p></noembed>';

    document.getElementById(objID).style.display = 'inline';
    document.getElementById(objID).innerHTML = embedCode;

    window.setTimeout("hideFlash('"+objID+"')", milliseconds);
}

function hideFlash(objID) {
    document.getElementById(objID).style.display = 'none';
}

window.onload = function xxx()
    {
        showFlash('flashDiv', 'path/flash_movie.swf', 300, 150, 5);
    }

</script>

</head>

<body>

<div id="flashDiv" style="display:none;"></div>

</body>
</html>

you can pass js variables from flash, for instance

 

on the first frame when the movie starts loading you can

 

in frame 1 in the flash file,

 

getURL('showFlash()'); 

 

and the last frame

 

getURL('hideFlash()');

 

 

and remove

 

the timer and

 

window.onload = function xxx()

    {

        showFlash('flashDiv', 'path/flash_movie.swf', 300, 150, 5);

    }

 

and rework the embed code a lil

 

from mjdamato's code

awesome!

 

I don't have time to try this now, so i'm not going to click topic-solved JUUUUST yet because i want to make sure i can get it working first.  but that looks awesome!

 

now, what is all this +variable+ business? what exactly does that syntax do?

Ok, so i'm not really sure what is going on here...

 

I put this code into the header of my php file...

 

function showFlash(objID, source, width, height) 
			{
		    var embedCode  = '<param name="'loop'"value="'false'"/><param name="'wmode'" value="'transparent'" />';
				embedCode += '<embed type="application/x-shockwave-flash"';
		        embedCode += ' pluginspage="http://www.adobe.com/go/getflashplayer"';
		        embedCode += ' width="'+width+'" height="'+height+'" src="'+source+'" />';

		    document.getElementById(objID).style.display = 'inline';
		    document.getElementById(objID).innerHTML = embedCode;
			}

		function hideFlash(objID) 
			{document.getElementById(objID).style.display = 'none';}

		window.onload = function xxx()
		    {
		    showFlash('flashDiv', 'fringe animation.swf', 1024, 450);
		    }

 

and I tried just putting

getURL('hideFlash()');

in to the last frame in actionscript (although i'm not confident i did that correctly.

 

so i did some research on Flash/JS communication (http://blog.circlecube.com/2008/02/01/actionscript-javascript-communication/) and came up with the code:

import flash.external.*;
function blah() {
ExternalInterface.call("hideFlash","flashDiv");
}

and injected it into the last frame of ActionScript.

 

not quite sure why its not working. i'm guessing it MIGHT be how i put it into actionscript...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.