FormerSwinger
05-06-2008, 02:57 PM
Since the wmode transparent can cause a lot of issues on different browsers I'm starting a challence to create a generic way to "inherit" the background style definitions from the html.
The only way I can think of requires javascript similar to the next function from
http://www.quirksmode.org/dom/getstyles.html
<script language="javascript" type="text/javascript">
function getStyle(el,styleProp)
{
var x = document.getElementById(el);
if (x.currentStyle)
var y = x.currentStyle[styleProp];
else if (window.getComputedStyle)
var y = document.defaultView.getComputedStyle(x,null).getP ropertyValue(styleProp);
return y;
}
</script>
THE RULES:
The solution needs to be generic (i.e. work on all browsers, and all flashfiles)
Generic javascript functions can be required. So the use of the function above is optional :) You can write your own.
THE GOALS
A snippet of code that can be pasted to any flash file
The background of the swf will inherit color from the html
The background of the swf will inherit bg image from the html
The background of the swf will inherit image position and tiling settings from the html
Here is my example that sort of works for bg color on Firefox (remember to include the js function into the header)
if(flash.external.ExternalInterface.available==tru e){
var c=flash.external.ExternalInterface.call("getStyle","flash","background-color");
if(c){
var cs=c.substring(4,c.length-1).split(",");
var cn="0x"+Number(cs[0]).toString(16)+Number(cs[1]).toString(16)+Number(cs[2]).toString(16);
_root.moveTo(0,0);
_root.beginFill(cn);
_root.lineTo(0,Stage.width);
_root.lineTo(Stage.height,Stage.width);
_root.lineTo(Stage.height,0);
_root.endFill();
}
}
ps. To those who are wondering why the hell would someone go through the trouble when you can just use the bgcolor attribute: The bg color only works for solid colors :p , If the bg color changes all flash emebds need to be edited.
The only way I can think of requires javascript similar to the next function from
http://www.quirksmode.org/dom/getstyles.html
<script language="javascript" type="text/javascript">
function getStyle(el,styleProp)
{
var x = document.getElementById(el);
if (x.currentStyle)
var y = x.currentStyle[styleProp];
else if (window.getComputedStyle)
var y = document.defaultView.getComputedStyle(x,null).getP ropertyValue(styleProp);
return y;
}
</script>
THE RULES:
The solution needs to be generic (i.e. work on all browsers, and all flashfiles)
Generic javascript functions can be required. So the use of the function above is optional :) You can write your own.
THE GOALS
A snippet of code that can be pasted to any flash file
The background of the swf will inherit color from the html
The background of the swf will inherit bg image from the html
The background of the swf will inherit image position and tiling settings from the html
Here is my example that sort of works for bg color on Firefox (remember to include the js function into the header)
if(flash.external.ExternalInterface.available==tru e){
var c=flash.external.ExternalInterface.call("getStyle","flash","background-color");
if(c){
var cs=c.substring(4,c.length-1).split(",");
var cn="0x"+Number(cs[0]).toString(16)+Number(cs[1]).toString(16)+Number(cs[2]).toString(16);
_root.moveTo(0,0);
_root.beginFill(cn);
_root.lineTo(0,Stage.width);
_root.lineTo(Stage.height,Stage.width);
_root.lineTo(Stage.height,0);
_root.endFill();
}
}
ps. To those who are wondering why the hell would someone go through the trouble when you can just use the bgcolor attribute: The bg color only works for solid colors :p , If the bg color changes all flash emebds need to be edited.