I decided to make a little site for a short film I made in an Editing class called Social Dissonance. I wanted to try communicating with Flash through JavaScript and I ran into some pitfalls along the way.The big thing I ran into that I finally figured out was taking out the <noscript> </noscript> tags surrounding your flash movie if you embed it using Dreamweaver.
There is another way to go about doing this with some simple code within Flash, but I did it this way because I think you can do a few more things more easliy. Below I am going to post the code to get this to work properly.
JAVASCRIPT CODE
<script language="text/javascript">
function getFlashMovieObject(movieName)
{
if (window.document[movieName])
{
return window.document[movieName];
}
if (navigator.appName.indexOf("Microsoft Internet")==-1)
{
if (document.embeds && document.embeds[movieName])
return document.embeds[movieName];
}
else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
{
return document.getElementById(movieName);
}
}
function StopFlashMovie()
{
var flashMovie=getFlashMovieObject("myFlashMovie");
flashMovie.StopPlay();
}
function PlayFlashMovie()
{
var flashMovie=getFlashMovieObject("myFlashMovie");
flashMovie.Play();
//embed.nativeProperty.anotherNativeMethod();
}
function RewindFlashMovie()
{
var flashMovie=getFlashMovieObject("myFlashMovie");
flashMovie.Rewind();
}
function NextFrameFlashMovie()
{
var flashMovie=getFlashMovieObject("myFlashMovie");
// 4 is the index of the property for _currentFrame
var currentFrame=flashMovie.TGetProperty("/", 4);
var nextFrame=parseInt(currentFrame);
if (nextFrame>=10)
nextFrame=0;
flashMovie.GotoFrame(nextFrame);
}
function ZoominFlashMovie()
{
var flashMovie=getFlashMovieObject("myFlashMovie");
flashMovie.Zoom(90);
}
function ZoomoutFlashMovie()
{
var flashMovie=getFlashMovieObject("myFlashMovie");
flashMovie.Zoom(110);
}
function SendDataToFlashMovie()
{
var flashMovie=getFlashMovieObject("myFlashMovie");
flashMovie.SetVariable("/:message", document.controller.Data.value);
}
function ReceiveDataFromFlashMovie()
{
var flashMovie=getFlashMovieObject("myFlashMovie");
var message=flashMovie.GetVariable("/:message");
document.controller.Data.value=message;
}</script>
FLASH EMBED CODE
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="550" height="400">
<param name="movie" value="integration.swf">
<param name="quality" value="high">
<embed name="myFlashMovie" swliveconnect="true" src="integration.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="550" height="400"></embed>
</object>
The things highlighted in red are a must to have if you want to pull this off.
HTML CODE
<form name="controller" method="POST">
<p>
<center>
<b><font color="#0099CC">JavaScript Controller<br>
</font></b>
<input type="button" value="Play" name="Play" onClick="PlayFlashMovie();">
<input type="button" value="Stop" name="Stop" onClick="StopFlashMovie();">
<input type="button" value="Rewind" name="Rewind" onClick="RewindFlashMovie();">
<input type="button" value="NextFrame" name="NextFrame" onClick="NextFrameFlashMovie();">
<input type="button" value="Zoomin" name="Zoomin" onClick="ZoominFlashMovie();">
<input type="button" value="Zoomout" name="Zoomout" onClick="ZoomoutFlashMovie();">
<br>
Form Data:
<input type="text" name="Data" size="20" value="Enter message">
<input type="button" value="Send Data" name="SendData" onClick="SendDataToFlashMovie();">
<input type="button" value="Receive Data" name="ReceiveData" onClick="ReceiveDataFromFlashMovie();">
<br>
</center>
</p>
<p> </p>
</form>
This code is easy to manipulate and customize it any way you want. The thing you need to keep in there is the name of the form which communicates with the JavaScript.
That is pretty much it. Here is link to wha I have working so far:
http://www.jamieweber.com/AI/entertainment/integration/
If you have any questions feel free to post a comment or email me :)
No comments:
Post a Comment