Home > Work > AS3 liquid layout class

AS3 liquid layout class

April 8th, 2009

I’m sure everyone has needed one of these at one time or another. I just decided to finally get one together for myself.

To use, you first call StageAlignTool.init() and pass in the stage, and optionally a minimum width and a minimum height (defaults to 1024×768).
Next, you call StageAlignTool.registerLocation() and pass in the displayObject you wish to register, which position you wish it to lock to (StageAlignTool .TL means Top Left, StageAlignTool.MC means Middle Center), and optionally if you want it to stay relative to where it is now (true) or snap to the edge of the stage (false).
The class automatically sets your stage scale mode to NO_SCALE and the stage align to TOP_LEFT. It also expects the display objects you pass it to have their registration points in the top left corner.

Download

Usage:


//StageAlignTool.init(Stage reference[, min width = 1024, min height = 768]);
StageAlignTool.init(stage, 1024, 768);

//StageAlignTool.registerLocation(a DisplayObject, position to lock to[, stay relative to current = false]);
//possible locations are [StageAlignTool.]TL, TC, TR, ML, MC, MR, BL, BC, BR

StageAlignTool.registerLocation(bg, StageAlignTool.MC);

Give it a try and tell me what you think.

Julian Work , , , ,

  1. Ruben Rojas
    April 8th, 2009 at 20:48 | #1

    Can you post a example of the real usage? Thanks

  2. marcus
    June 3rd, 2009 at 19:39 | #2

    cool. worked sweet but when i used an external loader i got an error#1009 message. think i may have placed the code somewhere wrong? suggestions?

    package {
    import StageAlignTool;

    public class Main extends MovieClip {

    var object:MovieClipInstance = new MovieClipInstance();

    public function Main() {
    addEventListner(Event.ADDED_TO_STAGE, initMain);
    }

    private function initMain(event:Event) {
    StageAlignTool.init(stage, 1024, 768);
    StageAlignTool.registerLocation(object, StageAlignTool.TL);
    }
    }
    }

  3. September 12th, 2009 at 15:06 | #3

    Hey nice class,

    I cleaned up the packaging of the class for you. You should follow packages standards so that other people can store this with their other class.
    http://gfxcomplex.com/wp-content/uploads/2009/09/StageAlignTool.zip

    There are a few things still wrong with it though.

    1: stayRelative set to true breaks the class.

    2: stayRelative set to true should be default since people would expect that the local x/y of the object would be where it positioned..

    3: I added a throw error on the constrictor so that you can’t create an instance and understand why.

    4: I added some basic docs: used asdoc with flash develop

    5: I added a flash develop project. Way better then flash IDE and comparable to flash builder

    6: you could probably dispatch an event when StageAlignTool is set on or off and or if you reached min x/y

    7: you could use Event.ADDED_TO_STAGE and Event.REMOVED_FROM_STAGE to listen for when the DisplayOject is added to stage to start the init() or registerLocation(), or to call kill when the item have been remove from the stage. that way you have to call one less function.

    Any how, nice work.

  4. December 11th, 2009 at 03:03 | #4

    Looks like you are a true professional. Did ya study about the subject? haha..

  1. No trackbacks yet.