flashgameblog.at

11.08.2010
10:24

Layout management for display objects

 

I am working hard at the next update for www.kineticarm.com. So I didn't have much time for the blog in the last month, sorry for that.

 

At my latest custom project I had a complex GUI system and the whole Movie had to be resizeable. So a layout manager seemed to be a proper solution. I just wanted to have a system where I define positions and sizes of the GUI objects once and without having to care about it afterwards.

I builded a static Layoutmanager class where I register all objects and a helper class that allows me to define position and size of each object.

Values can be defined absolute and relative as in CSS and referenced to top left and bottom right border.

  • all values ending with "px" are absolute
  • all values ending width "%" are relative
  • all values starting width "-" are referenced to bottom/right border.
  • all values starting with "+" or without any sign are referenced to top/left border.

 

On top of that all properties can be referenced to the stage or other objects as well. So if layout gets really complex it's possible to build unvisible dummy objects to align other objects to it.Here are some Examples:

 

  1.  
  2. // Created an instance from an object from the lib.
  3. // and adds it to the stage
  4. var obj1:MovieClip = new Item();
  5. addChild(obj1);   
  6.  
  7.  
  8. // creates a layout object for the added Displayobject
  9. // The constructor takes the display object
  10. lit = new LayoutItem(obj1);
  11. lit.scale = false              // the size isn't touched
  12. lit.x = "90%";                 // X pos. is 90% of stage width   
  13. lit.y = "50%";                 // Y pos. is 50% of stage height
  14. Layouter.registerObject(lit)// registers the object to the layoutManager
  15.  
  16.  
  17. // Created an instance from an object from the lib.
  18. // and adds it to the stage
  19. var obj2:MovieClip = new Item();
  20. addChild(obj2);   
  21.  
  22.  
  23. // creates a layout object for the added Displayobject
  24. // The constructor takes the display object
  25. lit = new LayoutItem(obj2);
  26. lit.reference = obj1;          // values references to obj1
  27. lit.scale = false              // the size isn't touched
  28. lit.x = "-100px";              // X pos. is 100 pixels left to obj1
  29. lit.y = "0px";                 // Y pos. is obj1.y
  30. Layouter.registerObject(lit);
  31.  

 

The only thing you need to do is to call the static method "arrange" of the LayoutManager everytime you want to rearrange all registered objects. This is mostly done in a function called at the stage's resize event.


Here you can download the source code with some examples.

  •  
  • 0 Comments
  •  

Your comment

Notify me when someone adds another comment to this post

back

< < August 2010 > >
S M T W T F S
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        

Blog rolls

Latest Comments

Blur Filter
17.01.2011 11:01
ISO FTW!
18.09.2010 20:17
ISO Blender Camera Setup
24.04.2010 06:58
update
21.03.2010 01:15

Archive

  • [-]2010(9)
    • [-]November(1)
    • [-]August(1)
    • [-]July(1)
    • [-]June(2)
    • [-]April(1)
    • [-]March(2)
    • [-]February(1)
  • [-]2009(13)
    • [-]December(4)
    • [-]November(8)
    • [-]October(1)

Copy and paste this link into your RSS news reader

RSS 0.91Posts
RSS 2.0Posts

Social Bookmarking

Bookmark bei: Mr. Wong Bookmark bei: Webnews Bookmark bei: Icio Bookmark bei: Oneview Bookmark bei: Linkarena Bookmark bei: Favoriten Bookmark bei: Seekxl Bookmark bei: Favit Bookmark bei: Social Bookmarking Tool Bookmark bei: Power Oldie Bookmark bei: Bookmarks.cc Bookmark bei: Newskick Bookmark bei: Newsider Bookmark bei: Linksilo Bookmark bei: Readster Bookmark bei: Folkd Bookmark bei: Yigg Bookmark bei: Digg Bookmark bei: Del.icio.us Bookmark bei: Reddit Bookmark bei: Simpy Bookmark bei: StumbleUpon Bookmark bei: Slashdot Bookmark bei: Netscape Bookmark bei: Furl Bookmark bei: Yahoo Bookmark bei: Spurl Bookmark bei: Google Bookmark bei: Blinklist Bookmark bei: Blogmarks Bookmark bei: Diigo Bookmark bei: Technorati Bookmark bei: Newsvine Bookmark bei: Blinkbits Bookmark bei: Ma.Gnolia Bookmark bei: Smarking Bookmark bei: Netvouz Information