ActionScript 3 Flexible Layout Class

ActionScript 3 NpFlexLayout Class

The NpFlexLayout Class is designed to simplify aligning DisplayObjects to stage dimensions and responding to changes in stage dimensions at run time by a user or between different users.

This supersedes a simpler implementation of this approach, called “ActionScript 3 Liquid Layout Manager”, which I’ll leave on the site.

As opposed to the LayoutManager class, the NpFlexLayout class is an actual layout manager, taking care of instantiating, destroying and passing on requests to instances of an internal class called NpFLexLayoutItem which wraps each displayObject passed to the NpFlexLayout Class.

Class Features

  • Position objects (x,y) on the stage as a proportion of the stages dimensions
  • offSet each displayObject (x,y) from where it would be by an absolute pixel value
  • set objects to stretch to fit either stage width / height or a proportion of stage dimensions
  • per object minX & minY settings where reflowing, resizing will cease
  • use either the clips registration point, or its visual center (width/height)
  • pause, resume displayObjects responding to resize events
  • update individual class properties at runtime
  • tween objects properties at runtime (uses internal simple tween method)
  • set tween easing
  • add, remove displayObjects from class

View Example
Here is an example; http://www.noponies.com/dev/as3_flexlayout/

Source Files
Here is the relevant source file; Flex Layout Files (1224) - 127.6 KB
By downloading, you agree to the terms of use, outlined here: http://www.blog.noponies.com/terms-and-conditions

Dependencies
None.

Version 2 Beta
Ok, here is a beta of version 2 of this class. Have a play and let me know of any issues.

I’ve updated the beta with an constrain resize property. Let me know how it works out in testing etc

http://www.blog.noponies.com/wp-content/uploads/NpFlexLayout-v2-Beta.zip

38 Neighs about “ActionScript 3 Flexible Layout Class”



Stan Neighed:

This looks really interesting. Just thought I’d let you know the source files seem to be missing.

am Neighed:

Great work!

Really complete and organized, my mum would like to have you home :P
Docs and examples are so sweet to make your work useable for others non code expertise.

Thanks for the effort!

francisco Neighed:

i cant download the files… an 404 error appears and the class you post here depends on import noponies.ui.NpFlexLayoutItem; that is not available… :(

JM Neighed:

This is really awesome

43 Hot Flex and ActionScript 3.0 APIs, tips and tools for Autumn 2008 Neighed:

[...] ActionScript 3 Flexible Layout Class The NpFlexLayout Class is designed to simplify aligning DisplayObjects to stage dimensions and responding to changes in stage dimensions at run time by a user or between different users. http://www.blog.noponies.com/archives/109 [...]

Ricardo Neighed:

Great Class, very simple but I detect some bugs when using width and resize it in full screen … I think it could accept more parameters like maxwidth, maxheight and so on … but it?Ǭ¥s a great job so far :)

Dale Neighed:

Ricardo,

What bugs in particular are you seeing?

43 Hot Flex and ActionScript 3.0 APIs, tips and tools for Autumn 2008 « Alaguvel’s Weblog Neighed:

[...] ActionScript 3 Flexible Layout Class The NpFlexLayout Class is designed to simplify aligning DisplayObjects to stage dimensions and responding to changes in stage dimensions at run time by a user or between different users. http://www.blog.noponies.com/archives/109 [...]

Ricardo Neighed:

Dale , try using width property then change the player to fullscreen. It will produce some unexpected results :)

Dale Neighed:

Ricardo,

OK, I’ll look into whats going on.

Iwan Negro Neighed:

thanks for your great class. i think everybody can use this. unfortunately i’ve found a little bug:

- create a scene with 800×600 dimensions.

- add an object “square” to align at the bottom right corner, with x and y set to 1. with an offsetX and offsetY of lets say -30. add a minX property of 770.

resizer.addTarget(square, {x:1, y:1, offSetX:-30, offSetY:-30, minX:770});

- i you resize the stage width below 800 it x-clips correctly but if you resize at the same time the height of the stage it won’t continue to y-align at the bottom.

i hope you can understand the bug. it’s difficult to explain.

thanks for your time.

Dale Neighed:

Iwan,

I’ll look into it, when I get a chance. :)

Recent Links Tagged With "actionscript3" - JabberTags Neighed:

[...] public links >> actionscript3 ActionScript 3 Flexible Layout Class Saved by analogchainsaw on Thu 23-10-2008 generalrelativity ?جø¬? Quick Maths 1: Projectiles and [...]

Januz Neighed:

Thank you so much!! You saved my life :p

Adam Duro Neighed:

I don’t know if this is a bug or not, but I’ve noticed that you cannot set an offSetX property that pushes the object off the edge of the stage. I have an object that was added to the stage with ActionScript, I then threw it into the FlexLayout manager, aligned it to the center of the stage, and tried to set it so that the regPoint would have been a negative X value.

I can send ya an example if you’d like.

Dale Neighed:

Adam,

Sure, send something through, and I’ll have a look when I next get the chance.

Adam Duro Neighed:

You can download a zip of the test I ran here.

http://storage.duromedia.com/layout_test.zip

Basically I have a container movie, lets call it a preloader, that loads in another swf that is the same size as the preloader swf. When I try and align it to the center, and then do an offSetX which would push part of the loaded swf off the edge of the stage, it wont go any further than the 0,0 value of the stage.

abdessamad Neighed:

good class mate.
but how to ease the elements automatically ?

Selling the 204. (our house) | Andy Harper - Interactive Designer Neighed:

[...] Layout – get the class HERE I got this class from http://www.blog.noponies.com also. Like I said…I gotta drop some cash on that [...]

Allan Neighed:

I’ll be trying this out. I was planning on writing this very tool myself but thought I’d Google it first. Glad I did!

Jumptronic Neighed:

I’ve been encountering an error (likely my own causing):

1180: Call to a possibly undefined method NpFlexLayoutItem.

This happens even when I merely import the class. Has anyone else encountered this?

Again, I assume it’s something I’m doing wrong, but I figured I’d mention it here in case someone else has run into this.

Any suggestions would be greatly appreciated:)

Dale Neighed:

Is the NpFlexLayoutItem in the noponies.ui package?

Are you using the beta, or the stable release?

jumptronic Neighed:

Dale: Yes, the class was correctly placed.
I figured out my issue…. I had placed the .as files in a nested directory. Once I moved them up to the root of my Class dir. everything worked great. So, I guess it was a pathing issue w/in the packages (maybe)…..

Allan Neighed:

I’ve found a bug where the updateObjectProps method does not work when certain combinations/values of parameters are set.

this doesn’t work (offSetY doesn’t update):
stageTest.addTarget(elpomefial, {x:0, y:0,useClipRegPoint:true,offSetX:-133,offSetY:getOffset(”y”)});
stageTest.updateObjectProps(elpomefial, {x:0, y:0,offSetX:-133,offSetY:getOffset(”y”)});

if I change x to 1, then it works:
stageTest.addTarget(elpomefial, {x:1, y:0,useClipRegPoint:true,offSetX:-133,offSetY:getOffset(”y”)});
stageTest.updateObjectProps(elpomefial, {x:1, y:0,offSetX:-133,offSetY:getOffset(”y”)});

this works too:
stageTest.addTarget(elpomefial, {y:0,offSetY:getOffset(”y”)});
stageTest.updateObjectProps(elpomefial, {y:0,offSetY:getOffset(”y”)});

Thoughts?

Allan Neighed:

Forgot to mention that this affects both the stable and beta versions.

Allan Neighed:

Looks like my problem might be related to Adam’s problem. If I don’t use a negative offsetX value I can get it to work.

Allan Neighed:

Now for my final post (I think). Without extensive testing (sorry), it looks like you MUST specify a non-zero minX value (even a negative number) for things to calculate properly. Same likely applies for the Y dimension.
Hope that helps someone.

Dale Neighed:

Yeah, thats an issue still to be fixed in the 2.0 release.

Benny Hill Neighed:

Many sites have a bitmap image that fills the background and resizes with browser, but also maintains it’s aspect ratio. Could you add this functionality?

Dale Neighed:

That feature will be in an updated version of the class.

Chris Neighed:

Hi, very useful (and simple to use) class, thanks for sharing! I’m also needing to have a full-background image that resizes within ratio… is there a way for me to force this functionality while waiting for the updated version?

Andy Neighed:

Great class, thanks. But I can’t get it to work with absolute pixel values. For example: I want to pin an object first to where it was with it’s absolute pixel value and later tween it to its relative stage position.

// CODE EXAMPLE
liquidStage.addTarget(myMC,{x:myMC.x, y:myMC.y});
liquidStage.tweenObject(myMC, 2, {x:1, y:.1, offSetX:-myMC.width, easing:Elastic.easeOut}

In the first line the mc is just positioned way off screen. It seems the absolute pixel values are treated as percentage. Or am I missing some special parameters to tell the class to treat it as absolute pixel values?

Degroeve Neighed:

Dear,

Thnx for the great package. Very handy. However, I have the following problem. I want to use your package to position movieclips instantiated in actionscript 3:

var test = new MovieClip;
myStage.addTarget(test, {x:.5, y:.5});

but I get following error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at NpFlexLayoutItem()
at noponies.ui::NpFlexLayout/addTarget()
at main_fla::MainTimeline/frame1()

I checked to code and found that _resizeTarget.stage is null (NpFlexLayoutItem). Can this be solved?

geetings from Belgium

Jason Neighed:

Hi,

I was wondering if there ware any tutorials available on using your class ? I’ve scanned trough the site and could not find any.

I would be very great full if you could write one !

Thanks a ton in advance !

Flex?ß‚Ä?¬??•‚ͬ??ß?°‚Äû?§¬?‚Ǩ?§¬?‚Ä??•¬º‚Ǩ?•¬è‚Äò?§¬æ‚Ä??•¬?¬ê?§¬????¶‚Ä¢‚Ñ¢?߬®‚Ä??®¬µ‚Äû?¶¬?¬ê?©‚Ä?‚Ć?•¬êÀÜ | ?§¬?¬??¶‚Äì‚İFlex?§¬æ‚Ä??•¬?¬ê Neighed:

[...] The NpFlexLayout ?߬±¬ª?¶Àú¬Ø?®¬Æ¬æ?®¬Æ¬°?ß‚Äù¬®?¶¬ù¬•?߬ƂǨ?•?í‚ÄìDisplayObjects?ß?°‚Äû?•¬??í?•¬±‚Ǩ?£‚Ǩ‚Äöhttp://www.blog.noponies.com/archives/109 [...]

Leave a neigh?