Archive for

January, 2009

...

JavaScript force minimal flash size

A simple, small script that makes sure your fullscreen flash doesn't gets too small.

make sure to copy the onresize and onload attributes in the body tag along with the script.

<!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>My title</title>
<style type="text/css">
<!--
/* commented backslash hack \*/
html, body{height:100%;}
/* end hack */
html,body {margin:0;padding:0}

</style>

<script language="javascript" type="text/javascript">

var minHeight = 750;
var minWidth = 955;

function resizeDiv(_id){
   var elm = document.getElementById(_id);

   var pageWidth = 0, pageHeight = 0;

     if( typeof( window.innerWidth ) == 'number' ) {
       pageWidth = window.innerWidth;
       pageHeight = window.innerHeight;
     }
     else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
       //IE 6+ in 'standards compliant mode'
       pageWidth = document.documentElement.clientWidth;
       pageHeight = document.documentElement.clientHeight;
     }
     else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
       //IE 4 compatible
       pageWidth = document.body.clientWidth;
       pageHeight = document.body.clientHeight;
     }
   pageWidth < minWidth ? elm.style.width = minWidth+'px' : elm.style.width = '100%';
   pageHeight < minHeight ? elm.style.height = minHeight+'px' : elm.style.height = '100%';
}

</script>

<script type="text/javascript" src="swfobject.js" ></script>
<script type="text/javascript">
   swfobject.embedSWF("index.swf", "flashDiv", "100%", "100%", "9.0.0");

</script>
</head>

<body  bgcolor="#ffffff"  border="0" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onresize="resizeDiv('flashDiv')" onload="resizeDiv('flashDiv')">

   <div id="flashDiv"></div>

</body>
</html>

Tweener onComplete fires too early!

I've been working for some time now with papervision in combination with tweener. It's a real great combination to make some cool stuff. There is only one thing that doesn't seem to work really seamless. When working with compex models, i want to stop the papervision engine when it isn't needed. This creates some space to do other heavy stuff. But when I remove my enterframe function when tweener is onComplete, it seems to miss like half a second, and my animation is screwed-up. So it seems to be that Tweener fires the onComplete, just before it really completes. I wrote a function for it to handle the problem.

The name of the render function is onEnterFrame, and plane is the papervision model thats been tweening.

private function stopRender(e:TimerEvent = null):void {
	if(e) {
		e.target.removeEventListener(TimerEvent.TIMER, stopRender);
		e.target.stop();
	}
	if (!Tweener.isTweening(plane)){
		removeEventListener(Event.ENTER_FRAME, onEnterFrame);
		trace("engine stopt")
	}
	else {
		var timer:Timer = new Timer(100,1);
		timer.addEventListener(TimerEvent.TIMER, stopRender)
		timer.start();
	}
}