Mi primera clase en AS 2, -casi 3 años sin comprender a mi
compilador...
Es una pequeña utilidad para alinear cosas... y registrar las
alineaciones a Stage.onResize
Seguro que hay cosas mejores por ahí, pero esta es sencilla...
Saludos!!!
http://usuarios.arsystel.com/sergiodf/as/sdf/AlignManager.as
/**
 * The class gives an easy interface to align movieclips on
Stage or to other movieclips,
 * and register -or not- these alignments to the
Stage.onResize event.
 * @usage  import sdf.AlignManager
 * var aligner=AlignManager.getInstance();
 * aligner._align(mc,Stage,'R',2,0,true);
 * @author  Sergio Daroca Fernández (funlab)
 * @version 1.0
 * @since   20-01-2007
 */
class sdf.AlignManager
{
        public var _alignments : Array = new Array ();
        private static var _instance : AlignManager = null;
        public function AlignManager ()
        {
                Stage.scaleMode = "noscale";
                Stage.align = "TL";
                Stage.addListener (this);
        }
        /**
         * Used to instantiate the class, returns a 'singleton' class
instance.
         *  
         * @usage var aligner=sdf.AlignManager.getInstance(); 
         * @return  AlignManager instance
         */
        public static function getInstance () : AlignManager
        {
                if (_instance == null)
                {
                        AlignManager._instance = new AlignManager ();
                }
                return AlignManager._instance;
        }
        /**
         * Aligns a movieclip to Stage or other scope (MovieClip),
and registers (or not) the alignment to Stage onResize event.
         * Uses  'T' 'M' 'B' and 'L' 'C' 'R' strings to set the
alignment (case unsensitive).
         * ('Top, Middle, Bottom' for vertical alignment)
         * ('Left, Center, Right' for horizontal alignment)
         * @usage  
sdf.AlignManager.getInstance()._align(mc,Stage,'MR',6,0,true);
         * This will instantiate the class, align mc to the Stage
vertical center 
         * and to the right of the stage with a 6 pixels margin, and
trigger the align action 
         * anytime the Stage is resized
         * @param   mc       MovieClip to be aligned
         * @param   scope    Alignment's scope (Stage or MovieClip)
         * @param   alignTo  One of: 'T' 'M' 'B', and/or one of: 'L'
'C' 'R'
         * @param   xmargin  Horizontal offset/margin for alignment
         * @param   ymargin  Vertical offset/margin for alignment
         * @param   register Wether to register the alignment for
Stage.onResize method
         * @return  Void
         */
        public function _align (mc : MovieClip, scope : MovieClip,
alignTo : String, xmargin : Number, ymargin : Number, register
: Boolean) : Void
        {
                var xmargin = isNaN (xmargin) ? 0 : xmargin;
                var ymargin = isNaN (ymargin) ? 0 : ymargin;
                switch (scope)
                {
                        case Stage :
                        var _topHeight = Stage.height;
                        var _topWidth = Stage.width;
                        break;
                        default :
                        var _topHeight = scope._height;
                        var _topWidth = scope._width;
                        break;
                }
                var l = alignTo.length;
                while ( -- l > - 1)
                {
                        var _alignTo = alignTo.charAt (l);
                        switch (_alignTo)
                        {
                                case 'T' :
                                case 't' :
                                mc._y = Math.floor(0 + ymargin);
                                break;
                                case 'M' :
                                case 'm' :
                                mc._y = Math.floor(_topHeight / 2 - mc._height 
/ 2 + ymargin);
                                break;
                                case 'B' :
                                case 'b' :
                                mc._y = Math.floor((_topHeight - mc._height) - 
ymargin);
                                break;
                                case 'L' :
                                case 'l' :
                                mc._x = Math.floor(0 + xmargin);
                                break;
                                case 'C' :
                                case 'c' :
                                mc._x = Math.floor(_topWidth / 2 - mc._width / 
2 + xmargin);
                                break;
                                case 'R' :
                                case 'r' :
                                mc._x = Math.floor((_topWidth - mc._width) - 
xmargin);
                                break;
                        }
                }
                if (register)
                {
                        var alignment : Object = {mc:mc, scope:scope,
alignTo:alignTo, xmargin:xmargin, ymargin:ymargin};
                        _alignments.push(alignment);
                }
        }
        /**
         * Event Listener Method for Stage.onResize:
         * Alingments that have been registered will trigger on
Stage.onResize event through this function
         * 
         */
        private function onResize ()
        {
                var l = _alignments.length;
                while ( -- l > - 1)
                {
                        var _args=_alignments[l];
                        var _args_array=new Array();
                        for(var a in _args) _args_array.push(_args[a]);
                        _align
(_args_array[0],_args_array[1],_args_array[2],_args_array[3],_args_array[4],false);
                }
        }
}

Envoyez vos cartes de voeux depuis www.laposte.net 
Elles seront ensuite distribuées par le facteur : pratique et malin !


-----------------------------------------------------
ASNativos
www.5dms.com
subscripciones/desubscripciones
http://asnativos.5dms.com
-----------------------------------------------------

Responder a