Home Tutorials Forums Articles Blogs Movies Library Employment Press

<< Prev 5 |

Object reverse

function reverseObject(o:Object):Void
{
        //var a = [], s, p;
        var a:Array = new Array();
        var s:Object = new Object();
        var p:Object = new Object();
        
        for(var n:String in o){ a.push(n); }
        
        a.reverse();
        
        var i:Number = a.length;
        
        while(i--)
        {
                p = a[i];
                s = o[p];
                delete o[p];
                o[p] = s;
        }
}

var obj:Object = new Object();
obj.one = {test:"TEST"};
obj.two = "TWO";
obj.three = "THREE";
obj.four = "FOUR";

for(var i:String in obj){trace(i add " = " add obj[i]);}
trace("===")
reverseObject(obj);
for(var i:String in obj){trace(i add " = " add obj[i]);}

Posted by: Red Penguin | website http://www.komielan.com/
TraceObject (Static Debugger class)
/**
* @author: Eric Feminella
* @version 1.1
* @copyright: http://www.ericfeminella.com
*/

package {
        
        public final class TraceObject
        {
                
                public static function filterObject(obj:Object, recursivelyTraceAll:Boolean):void
                {
                        if (obj is Array) {
                                
                                if (obj[0] != null) {
                                        
                                        e.trace("\nObject is of Type: Array[Indexed]\nIndexed as follows:");
                                        
                                        for (var i:Number = 0; i < obj.length; i++) {
                                                
                                                if (obj[i] is Object || obj[i] is Array)
                                                {
                                                        if (recursivelyTraceAll)
                                                        {
                                                                TraceObject.filterObject(obj[i], true);
                                                        }
                                                        else
                                                        {
                                                                e.trace("\t[" + i + "] = " + obj[i] + "");
                                                        }
                                                }
                                                else
                                                {
                                                        e.trace("\t[" + i + "] = " + obj[i] + "");
                                                }
                                        }
                                }
                                else
                                {
                                        e.trace("\nObject is of Type: Array[Associative]\nKeyed as follows:");
                                        
                                        for (var element:* in obj) {
                                                
                                                if (element is Object || element is Array)
                                                {
                                                        if (recursivelyTraceAll)
                                                        {
                                                                TraceObject.filterObject(element, true);
                                                        }
                                                        else
                                                        {
                                                                e.trace("\t['" + element + "'] = " + obj[element]);
                                                        }
                                                }
                                                else
                                                {
                                                        e.trace("\t['" + element + "'] = " + obj[element]);
                                                }
                                        }
                                }
                        }
                        else if (obj is Object)
                        {
                                e.trace("\nObject is of Type: " + typeof(obj));
                                
                                for (var prop:* in obj){
                                        
                                        if (prop is Object || prop is Array)
                                        {
                                                if (recursivelyTraceAll)
                                                {
                                                        TraceObject.filterObject(prop, true);
                                                }
                                                else
                                                {
                                                        e.trace("\t\t." + prop + " = " + obj[prop]);
                                                }
                                        }
                                        else
                                        {
                                                e.trace("\t\t." + prop + " = " + obj[prop]);
                                        }
                                }
                        }
                        else if (obj == null)
                        {
                                e.trace("A type of undefined has been set for: " + obj);
                        }
                }
        }
}

Posted by: Eric Feminella | website http://www.ericfeminella.com
Validator
/**
* @author: Eric Feminella
* @class: Validator
* @usage: type validation utility class
*/



class Validator
{
        
        
        public static function isBoolean(textAreaString:String):Boolean
        {
                var bool:String = textAreaString;
                
                if (bool == "true" || bool == "false")
                {
                        return true;
                }
                else
                {
                        return false;
                }
        }
        
        
        public static function isString(textAreaString:String):Boolean
        {
                if (isNaN(textAreaString))
                {
                        return true;
                }
                else
                {
                        return false;
                }
        }
        
        
        public static function isNumber(textAreaString:String):Boolean
        {
                var isnan:Boolean = isNaN(Number(textAreaString));
                
                if (isnan)
                {
                        return false
                }
                else
                {
                        var hasDecimal:Number =  textAreaString.indexOf(".");
                        
                        if (hasDecimal > -1)
                        {
                                return false;
                        }
                        else
                        {
                                return true;
                        }
                }
        }
        
        
        public static function isDecimal(textAreaString:String):Boolean
        {
                var isnan:Boolean = isNaN(Number(textAreaString));
                
                if (isnan)
                {
                        return false
                }
                else
                {
                        var hasDecimal:Number =  textAreaString.indexOf(".");
                        
                        if (hasDecimal > -1)
                        {
                                return true;
                        }
                        else
                        {
                                return false;
                        }
                }
        }
}

Posted by: Eric Feminella | website http://www.ericfeminella.com
Version
/**
*@ author: Eric Feminella
*@ published: 03.13.06
*@ dynamic class:Version
*@ usage: Software Application versioning Singleton
*/




dynamic class com.dataProviders.meta.Version
{
        
        
        private static var APPLICATION_NAME:String;
        private static var MAJOR_VERSION:Number;
        private static var MINOR_VERSION:Number;
        private static var BUILD_DATE:String;
        private static var AUTHOR:String;
        
        
        
        public static function Meta(applicationName:String, major_version:Number, minor_version:Number, build_date:String, author:String):Void
        {
                Version.APPLICATION_NAME = applicationName;
                Version.MAJOR_VERSION = major_version;
                Version.MINOR_VERSION = minor_version;
                Version.BUILD_DATE = build_date;
                Version.AUTHOR = author;
        }
        
        
        
        public static function getVersion():String
        {
                var ver:String = "Software Version Information: " + newline +
                "Name: " + Version.APPLICATION_NAME + newline +
                "Major Version: " + Version.MAJOR_VERSION + newline +
                "Minor Version: " + Version.MAJOR_VERSION + newline +
                "Build Date: " + Version.BUILD_DATE + newline +
                "Author(s): " + Version.AUTHOR;
                return ver;
        }
        
}

Posted by: Eric Feminella | website http://www.ericfeminella.com

<< Prev 5 |

Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.