Grid Sorting class v. 0.1

Tommyka | 10. juli 2009 11:01 | ActionScript

Når så kunne jeg ikke holde fingerne væk aligevel.

jeg har lige smækket en Grid sorting class sammen på en time her om natten i det lidt våde norge.

Klassen virker ved at man tilføjer nogle display objekter til dens interne list, og så hver gang du ændre højde, bredte, v og hspacing så resorter den alle objekterne der er tilknyttet.
Selve klassen er ikke lavet som et display objekt (selv om det nemt kunne), så de skal være added til en displayliste et andet sted.

her er selve klassen

package dk.tommyka.layout 
{
	import dk.tommyka.v3.layout.events.LayoutEvent;
	import flash.display.DisplayObject;
	import flash.display.Sprite;	
	/**
	 * ...
	 * @author Tommyka
	 */
	public class Grid 
	{
		private var _width:Number = 400;
		private var _height:Number = 400;
		private var _vspacing:int = 10;
		private var _hspacing:int = 10;
		
		private var _children:Array;
		
		public function Grid(children:Array) 
		{ 
			_children = children || [];
			
			for (var i:uint = 0; i < _children.length; i++)
			{
				_children[i].addEventListener(LayoutEvent.RESORT, onResort, false, 0, true);
			}
		}
		
		private function resort():void
		{
			var mw:Number = 0; //max width;
			var mh:Number = 0; //max height;
			
			var numChildren:int = _children.length;
			
			var child:DisplayObject;
			
			for (var i:uint = 0; i < numChildren; i ++)
			{
				child = _children[i];
				
				if (child.width > mw)
				{
					mw = child.width;
				}
				
				if (child.height > mh)
				{
					mh = child.height;
				}
			}
			
			var dx:int = int(mw) + _vspacing;
			var dy:int = int(mh) + _hspacing;
			
			var rows:int = Math.floor(_height / dy);
			var cols:int = Math.floor(_width / dx);
			
			for (i = 0; i < numChildren; i++)
			{
				child = _children[i];
				child.x = dx * (i % cols);
				child.y = dy * Math.floor(i / cols);
			}
		}
		
		public function addChild(child:DisplayObject):void
		{
			_children.push(child);
			child.addEventListener(LayoutEvent.RESORT, onResort, false, 0, true);
			
			resort();
		}
		
		private function onResort(e:LayoutEvent):void 
		{
			resort();
		}
		
		public function get width():Number { return _width; }
		
		public function set width(value:Number):void 
		{
			_width = value;
			resort();
		}
		
		public function get height():Number { return _height; }
		
		public function set height(value:Number):void 
		{
			_height = value;
			
			resort();
		}
		
		public function get vspacing():int { return _vspacing; }
		
		public function set vspacing(value:int):void 
		{
			_vspacing = value;
			
			resort();
		}
		
		public function get hspacing():int { return _hspacing; }
		
		public function set hspacing(value:int):void 
		{
			_hspacing = value;
			
			resort();
		}
	}
	
}

der er også en event klasse med som man kan bruge hvis nogle af de nestede elementer ændre størelse, så kan man bruge den til at sige, HEY resort lige det hele.

 

package dk.tommyka.layout.events 
{
	import flash.events.Event;
	
	/**
	 * ...
	 * @author Tommyka
	 */
	public class LayoutEvent extends Event 
	{
		
		static public const RESORT:String = "resort";
		
		public function LayoutEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false) 
		{ 
			super(type, bubbles, cancelable);
			
		} 
		
		public override function clone():Event 
		{ 
			return new LayoutEvent(type, bubbles, cancelable);
		} 
		
		public override function toString():String 
		{ 
			return formatToString("LayoutEvent", "type", "bubbles", "cancelable", "eventPhase"); 
		}
		
	}
	
}

Kommentarer

25-03-2010 12:15:41 #

no teletrack payday loan

Hey I love your style I will subscribe for your feed please keep posting!

no teletrack payday loan USA | Besvar

26-03-2010 23:10:03 #

online cash advance payday loans

I don't like your template but your posts are quite good so I will check back!

online cash advance payday loans USA | Besvar

29-03-2010 22:35:22 #

quick approval loans

I was looking for this the other day. i dont usually post in forums but i wanted to say thank you!

quick approval loans USA | Besvar

30-03-2010 11:04:50 #

instant bad credit loan

Of course, what a great site and advisory posts, Can I add backlink - import your rss feed? Regards, Reader.

instant bad credit loan USA | Besvar

01-04-2010 02:43:31 #

stretch marks on inner thighs

my God, i thought you were going to chip in with some decisive insght at the end there, not leave it with "we leave it to you to decide".

stretch marks on inner thighs USA | Besvar

08-05-2010 23:12:58 #

Mariana

Would it be cool to provide some more info on this in the future? Thanks

Mariana USA | Besvar

18-05-2010 11:44:24 #

cash advance

Of course, what a great site and informative posts, I will add backlink - bookmark this site? Regards, Reader.

cash advance USA | Besvar

19-05-2010 15:01:13 #

quick easy loan

This article gives the light in which we can observe the reality. this is very nice one and gives indepth information. thanks for this nice article!

quick easy loan USA | Besvar

20-05-2010 09:01:02 #

Wahdo Tech

Bookmarked, i will add your homepage to my toolbar

Wahdo Tech USA | Besvar

21-06-2010 22:46:32 #

Latest Headlines

If you have to do it, you might as well do it right.

Latest Headlines USA | Besvar

15-07-2010 13:49:44 #

wow gold

Like the ones that you can see on spa's, I think the elevating feature is really awesome

wow gold Uruguay | Besvar

17-07-2010 23:58:44 #

wow gold

Hey, I am checking this site from my phone and it looks kinda trendy. Thought you��d want to know. It��s a great post though, didn��t mess that up

wow gold Kroatien | Besvar

18-07-2010 00:25:31 #

goldsoon

Hi, thanks so much for these tips! My blogs usually do bring readers and responses. One thing I do is engage with the readers. Answer questions in responses and make clarifications where needed. I think they appreciate that I take the time to talk to them.

goldsoon Puerto Rico | Besvar

18-07-2010 00:54:35 #

wow map coordinates

Well every blog owner deserve a little admiration. Nice post, grazie.

wow map coordinates Østrig | Besvar

20-07-2010 02:30:13 #

wow gold

I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.

wow gold Thailand | Besvar

20-07-2010 03:17:50 #

game online news

I really enyojed this awesome blog. Please continue this great work. Regards from Jason...

game online news Australien | Besvar

20-07-2010 03:54:09 #

Wow Warlocks

Wow, what a blog!  I mean, you just have so much guts to go ahead and tell it like it is.  Youre what blogging needs, an open minded superhero who isnt afraid to tell it like it is.  This is definitely something people need to be up on.  Good luck in the future, man.

Wow Warlocks Færøerne | Besvar

24-07-2010 22:49:59 #

wow gold

Can I make a suggestion?  I think youve got something good here.  But what if you added a couple links to a page that backs up what youre saying?  Or maybe you could give us something to look at, something that would connect what youre saying to something tangible?  Just a suggestion.

wow gold Qatar | Besvar

24-07-2010 23:15:21 #

First Person Shooting

This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work.

First Person Shooting Brunei Darussalam | Besvar

24-07-2010 23:46:06 #

WoW Heroes

my God, i thought you were going to chip in with some decisive insght at the end there, not leave it with ??we leave it to you to decide?��.

WoW Heroes Peru | Besvar

31-07-2010 21:10:44 #

masters of social work online colleges

This really should also be essential for you so in the event you view the questionnaires as just one more tool to guide YOU get the correct employment  then you definitely can see there is certainly much less require for worrying about them

masters of social work online colleges USA | Besvar

19-08-2010 09:26:25 #

vigrx

your site layout is very good

vigrx USA | Besvar

30-08-2010 17:24:36 #

ffxiv gil

Thanks a good deal! I really enjoyed reading this. It makes me want to create my own blog. I do not know what topic though? I am a bank proof operator but can't conceive of many people wanting to read about that! Possibly I'm wrong. Any thoughts?

ffxiv gil Litauen | Besvar

30-08-2010 22:33:10 #

ffxiv gil

Aw, this was a really quality post. In theory I'd like to write like this also - taking time and real effort to make a good article... but what can I say... I procrastinate alot and never seem to get something done.

ffxiv gil Slovakiet | Besvar

30-08-2010 22:49:05 #

ffxiv gil

Hi, that was quite a post! So many people seem to be fans. I wish my blog got as many comments as yours does!

ffxiv gil Jamaica | Besvar

30-08-2010 23:14:28 #

buy wow gold

The Zune concentrates on being a Portable Media Player. Not a web browser. Not a game machine. Maybe in the future it'll do even better in those areas, but for now it's a fantastic way to organize and listen to your music and videos, and is without peer in that regard. The iPod's strengths are its web browsing and apps. If those sound more compelling, perhaps it is your best choice.

buy wow gold Colombia | Besvar

Tilføj kommentar




  Country flag

biuquote
  • Kommentar
  • Eksempel
Loading



 

Powered by BlogEngine.NET 1.5.0.7
Theme by Tommy Kjær Andersen admin Log ind