Jangaroo自适应浏览器宽高

as代码:

package com.acme.jooflash
{
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.external.ExternalInterface;
	import flash.net.URLRequest;
	import flash.text.TextField;

	/**
	 * ...
	 * @author harriet amyflash.com

	 */
	[SWF( backgroundColor='0xFFFFFF', frameRate='30', width='640', height='480')]
	public class Main extends Sprite 
	{
		private var sw:Number = 800;
		private var sh:Number = 700;

		public function Main() 
		{
			/*var helloWorld:TextField = new TextField();
			helloWorld.text = "Hello Harriet!";
			addChild(helloWorld);*/

			/*var s:Sprite = new Sprite();
			s.graphics.beginFill(0xff00ff, 0.1);
			s.graphics.drawCircle(100, 0, 100);
			s.graphics.endFill();
			addChild(s);
			s.addEventListener(MouseEvent.MOUSE_OVER, doClick);*/

			if (ExternalInterface.available) {
				sw = ExternalInterface.call("getw");
				sh = ExternalInterface.call("geth");
			}

			this.stage.stageWidth = sw;
			this.stage.stageHeight = sh;

			var url:String = "logo.png";
			var urlr:URLRequest = new URLRequest(url);

			loader.load(urlr);
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, doShow);
			//addChild(loader);
		}

		private var loader:Loader = new Loader();
		private function doShow(e:Event):void
		{
			var t:DisplayObject = loader.content;
                       //(e.target.loader as Loader).content--加载多个图片有用
			 addChild(t); 

			 t.x = (sw - t.width) / 2;
			 t.y = (sh - t.height) / 2;
		}
	}
}

首页index.html

<!DOCTYPE html>
<html>
<head>
  <title>t2</title>
  <script>
  //获取浏览器窗口宽高
var winWidth = 0; 
var winHeight = 0; 

function findDimensions() //函数:获取尺寸 
{ 
//获取窗口宽度 
if (window.innerWidth) 
winWidth = window.innerWidth; 
else if ((document.body) && (document.body.clientWidth)) 
winWidth = document.body.clientWidth; 
//获取窗口高度 
if (window.innerHeight) 
winHeight = window.innerHeight; 
else if ((document.body) && (document.body.clientHeight)) 
winHeight = document.body.clientHeight; 
//通过深入Document内部对body进行检测,获取窗口大小 
if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth) 
{ 
winHeight = document.documentElement.clientHeight; 
winWidth = document.documentElement.clientWidth; 
} 

} 

 findDimensions();
//设置iframe宽高
function reSetWH(obj)
{  
	findDimensions();
    obj.width = winWidth;
    obj.height = winHeight;

	console.log(winWidth+","+winHeight);
}

//告诉as舞台宽高
function getw(){
return winWidth;
}

function geth(){
return winHeight;
}

function reSetIframe()
{
	location.reload(); //刷新页面
}

</script>

</head>
<body onresize="reSetIframe();">
<!--h1>t2</h1-->

<iframe id="stage" src="jooflash.html" frameborder="0" width="640" height="480" onload="reSetWH(this);" >
  no frames
</iframe>
</body>
</html>

Comments are closed.