Jangaroo等宽高瀑布流算法

[code]
//data.json
{
"items": [{
"img_url": "imgs/anjuke.png",
"link_url": "http://www.amyflash.com",
"intro": "it is a message"
}, {
"img_url": "imgs/yile.png",
"link_url": "http://www.amyflash.com",
"intro": "it is a message"
}, {
"img_url": "imgs/ctrip.png",
"link_url": "http://www.amyflash.com",
"intro": "it is a message"
}, {
"img_url": "imgs/lifevc.png",
"link_url": "http://www.amyflash.com",
"intro": "it is a message"
}, {
"img_url": "imgs/xdf.png",
"link_url": "http://www.amyflash.com",
"intro": "it is a message"
}, {
"img_url": "imgs/taoche.png",
"link_url": "http://www.amyflash.com",
"intro": "it is a message"
}, {
"img_url": "imgs/fanke.png",
"link_url": "http://www.amyflash.com",
"intro": "it is a message"
}

]

}
[/code]

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.URLLoader;
	import flash.net.URLRequest;
	import flash.text.TextField;

	import joo.getQualifiedObject;
	import js.Document;

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

		private var dataloader:URLLoader = new URLLoader();
		private var count:Number = 0;

		private var top:int = 100;
		private var left:int = 100;

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

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

			var surl:String = "data.json";
			var surlr:URLRequest = new URLRequest(surl);
			dataloader.load(surlr);
			dataloader.addEventListener(Event.COMPLETE, getData);

		}

		private function getData(e:Event):void
		{
			 var sMyString:String = dataloader.data;
			 var t:Object = window['JSON'].parse(sMyString);
			 count = t.items.length;

			for each(var item in t.items )
			{

				var url:String = item.img_url;

				var urlr:URLRequest = new URLRequest(url);
				var loader:Loader = new Loader();
				loader.load(urlr);
				loader.contentLoaderInfo.addEventListener(Event.COMPLETE, doShow);
			}
		}

		private var right:Number;

		private var viewi:int = 0;
		private var pviewi:int = 0;
		private var dx:int = 10;
		private var dy:int = 10;
		private var pline:int = -1;
		private function doShow(e:Event):void
		{

			var t:DisplayObject = (e.target.loader as Loader).content;
			 right = sw - left - t.width;
			addChild(t);

			t.x = left + (t.width + dx) * viewi++;
			t.y = top;
			if (t.x > right)
			{
				if(pline==-1)
				{
					pline = viewi-1;
					trace(pline);//求出多少列
				}

				pviewi = viewi-1;
				if (pline != 0)
				{
					t.y = top+Math.floor(pviewi / pline) * (t.height + dy);
					t.x = left + (t.width + dx) * (pviewi % pline);
				}else
				{
					t.x = 5;
					t.y = 5 + pviewi * (t.height + dy);
				}	
			}

		}

	}
}

jangaroo中xml的处理

//sMyString为加载到的字符串

/*handle xml
			 * var DOMParser:Class = getQualifiedObject('DOMParser');
				  if (DOMParser) {
					var oDOM:Document = new DOMParser().parseFromString(sMyString, "text/xml");
				  } else {
					var ActiveXObject:Class = getQualifiedObject('ActiveXObject');
					if (!ActiveXObject) {
					  throw new Error("No XML support!");
					}
					oDOM = new ActiveXObject("Microsoft.XMLDOM");
					oDOM['async'] = "false";
					oDOM['loadXML'](sMyString);
				  }
		  // print the name of the root element or error message
		  trace(oDOM.documentElement.nodeName == "parsererror" ? "error while parsing" : oDOM.documentElement.nodeName);*/

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>

Jangaroo初探

1.配置好java和maven3环境
M2_HOME=D:\apache-maven-3.0.5
M2=%M2_HOME%\bin
path=%M2%
命令窗口中执行:mvn -v,运行正常则安装成功
2.下载fd模板,拷贝到fd安装目录/Projects文件夹内,我的是E:\Program Files\FlashDevelop\Projects
3.重起fd,可以看到jangaroo模板了
4.点击fd上的command prompt按钮,输入mvn jetty:run,启动服务环境

package com.acme.jooflash
{
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	import flash.text.TextField;
	
	/**
	 * ...
	 * @author harriet
	 */
	[SWF( backgroundColor='0xFFFFFF', frameRate='30', width='640', height='480')]
	public class Main extends Sprite 
	{
		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);*/
			
			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
		{
			 addChild(loader.content); 
		}
	}
}