myLib



© 2017 myLib
Based on DemusDesign and Eric Séguin Themes

Layout management



setSize method

All components have common properties making easier advanced layout.
In addition of width/height properties to size components, we can use setSize method, useful if both width and height change :

1
2
3
4
myComponent.width  = 100;
myComponent.height = 20;
// OR
myComponent.setSize( 100 , 20 );

_
_
_

move method

In the same way of setSize method, you can position component with move method instead of using x/y properties

1
2
3
4
myComponent.x = 100;
myComponent.y = 100;
// OR
myComponent.move( 100 , 100 );

2 optional arguments are available with move method :

Let you specify which component point should be align from specified x/y coordinate. By default you always move a DisplayObject from its top left alignment point, this is great when you want to position your DisplayObject from top left container. What about if you want to move your DisplayObject from your scene bottom right, common usage is :

1
2
myDisplayObject.x = stage.stageWidth – myDisplayObject.width;
myDisplayObject.y = stage.stageHeight – myDisplayObject.height;

Let’s do it with move method and alignmentPoint argument :

1
myComponent.move( stage.stageWidth , stage.stageHeight , AlignmentPoint.BR );


Download sources

When you move a DisplayObject this is always from its parent container. For example if your DisplayObject is dropped on root scene, DisplayObject move from root container. In some case you may want to move DisplayObject from a different container. This can be achieved using targetCoordinateSpace argument.

For example if you DisplayObject is a child of a container Sprite which itself a child of root container at the 100/100 coordinate, if you move your DisplayObject at 0,0 coordinate it appears at 100,100 coordinate from root container, to move it to 0,0 coordinate from root you need to calculate coordinate (here the result would be -100/-100) but with some complex display list this is really boring, so let’s use targetCoordinateSpace :

1
myComponent.move( 0 , 0 , null , root );


Download sources

_
_
_

stageX/stageY properties

With stageX/stageY you can move your component using stage coordinate space whatever its parent container :

1
2
myComponent.stageX = 100;
myComponent.stageY = 100;

As seen before this is equivalent to :

1
myComponent.move( 100 , 100 , null , stage );

_
_
_

alignmentPoint property

To change component alignment point without  moving it you can alternatively use this property :

1
myComponent.alignmentPoint = AlignmentPoint.BR;

This is equivalent to :

1
myComponent.move( myComponent.x , myComponent.y , AlignmentPoint.BR );

_
_
_

USE_PIXEL_SNAPPING top-level property

USE_PIXEL_SNAPPING is really useful when you want all your components snapped to pixel to avoid blurred effect.

This is a Boolean top level property not active by default. To activate it :

1
2
import myLib.displayUtils.USE_PIXEL_SNAPPING;</p>
USE_PIXEL_SNAPPING = true;

Note this affect only next instantiated components, if you have already instantiate components they will not be affected, so you should set this property to true when your application start.
_
_
_

3 Responses to “Layout management”

  1. nick Says:
    August 21st, 2011 at 5:29 pm

    I’m having a focus problem with the components using text input. When I add new classes using these components to the display stack, The text inputs stop working. It happens when I load an external swf file. Please get back to me when you can.

  2. Repliki zegarków Says:
    April 1st, 2014 at 4:03 am

    Adobe components use style as additional components (generally common) properties. With myLib style consist of an object with pair key/value that could match any component properties. This is really useful to avoid repetitive coding

  3. iPad cases and covers Says:
    December 16th, 2014 at 11:00 am

    She rejected the suggestion, but was unable to cancel her order as the company claimed that under the online terms and conditions, the delivery date could not be guaranteed and her order could not be canceled.

Leave a Reply

*
To prove you're a person (not a spam script), type the answer to the math equation shown in the picture. Click on the picture to hear an audio file of the equation.
Click to hear an audio file of the anti-spam equation