您当前的位置: 首页 > 

Jave.Lin

暂无认证

  • 4浏览

    0关注

    704博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

AS3 对复杂对象的排序规则[DEMO]

Jave.Lin 发布时间:2012-07-26 14:10:03 ,浏览量:4

源代码:

package
{
	import flash.display.Sprite;
	
	/**
	 *  测试复杂对象的排序
	 * @author Jave.Lin(afeng)
	 **/
	public class TestComplexSort extends Sprite
	{
		public function TestComplexSort()
		{
			super();
			
			var lastNameArr:Vector.=new Vector.();
			lastNameArr.push("Lin","Smith","Steven","Abros","BB","CCC","D","EE","FF","GG","Gates","HH");
			
			var firstNameArr:Vector.=new Vector.();
			firstNameArr.push("Jave","John","Harry","Waston","Bill","Tom","Jerry");
			
			var ageMax:uint=150;
			
			var personArr:Vector.=new Vector.();
			
			for (var i:int = 0; i < 10; i++) 
			{
				var p:Person=new Person();
				p.firstName=firstNameArr[Math.floor(Math.random()*firstNameArr.length)];
				p.lastName=lastNameArr[Math.floor(Math.random()*lastNameArr.length)];
				p.age=Math.floor(Math.random()*ageMax);
				personArr[i]=p;
			}
			
			trace(personArr);
			
			personArr.sort(comparePerson);
			
			trace(personArr);
		}
		
		private function comparePersonAge(a:Person,b:Person):int
		{
			if(a.age>b.age)return 1;
			else if(a.ageb.firstName)return 1;
			else if(a.firstNameb.lastName)return 1;
			else if(a.lastName            
关注
打赏
1664331872
查看更多评论
0.1614s