PDA

View Full Version : JavaScript function that set the background picture of a html page


adrian281990
08-13-2007, 11:28 AM
Hi, I have made swf in put him in to a html page. This swf will sall a javascript function in that html page. It will pass to this function a parameter (ex of parameter "image.jpg"). This function will take that parameter and load that picture and set it as the background picture of that html page. The name for the function will be setBackgroundImage.
Here is the ActionScript Ciode

package {

import flash.display.MovieClip;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.external.ExternalInterface;

public class Master extends MovieClip {

private var _myXML:XML;
var _myLoader:URLLoader;

public function Master() {
_myXML = new XML();

var myXMLURL:URLRequest = new URLRequest("date.xml");

_myLoader = new URLLoader(myXMLURL);
_myLoader.addEventListener("complete", xmlLoaded);

}

private function xmlLoaded(event:Event):void {
_myXML = XML(_myLoader.data);
var myURL:String = _myXML.backgroundImageURL;
setStageSize(myURL);
}


private function setStageSize(url:String):void
{
if (ExternalInterface.available)
{
ExternalInterface.call("setBackgroundImage", url);
}
}
}
}


and her is the html code


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Document</title>
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" valign="middle"><script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','name','myFlash','wi dth','550','height','400','align','middle','title' ,'Test','id','myFlash','src','master','quality','h igh','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movi e','master' ); //end AC code
</script>
<noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" name="myFlash" width="550" height="400" align="middle" id="myFlash" title="Test">
<param name="movie" value="master.swf" />
<param name="quality" value="high" />
<embed src="master.swf" width="550" height="400" align="middle" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" name="myFlash"></embed>
</object></noscript></td>
</tr>
</table>
</body>
</html>




If have some question please send me some emails. My email address is adrian281990@gmail.com.
Thank you very much,
Adrian