I don't like to know if there is an easier way to do this so I wrote this
function to check if a object or the requested properties exist on the
object.


// call it like this
isset_drilldown(this.language_data,'STYLES','BRACKETS',0);


// Determine whether a variable set via a drill down through the properties
// instead of this: isset(this.language_data['STYLES']['BRACKETS'][0])
// you would use this:
isset_drilldown(this.language_data,'STYLES','BRACKETS',0)
// parameters are - object [, property[, ...]]
public function isset_drilldown(variable:*, ...properties):Boolean {
    if (variable!=null && variable!=undefined) {
        var length:int = properties.length;

        if (properties.length>0) {
            var reference:* = variable;

            for (var i:int=0; i<length; i++) {
                var property:String = properties[i];
                if (Object(reference).hasOwnProperty(property)) {
                    reference = reference[property];
                }
                else {
                    return false;
                }
            }
        }
        return true;
    }
    else {
        return false;
    }
}

On Sun, Jan 18, 2009 at 5:46 AM, dorkie dork from dorktown <
dorkiedorkfromdorkt...@gmail.com> wrote:

> I have a PHP statement that I am trying to write in AS3. So far it errors
> out because the properties do not exist on it yet. How would/should I
> rewrite this for AS3? Here is the statement:
>
> // at the time this is run "this.language_data" is an object with 2
> properties
> // the "STYLES" property does not exist yet and it generates a
> // TypeError: Error #1010: A term is undefined and has no properties.
> if (isset(this.language_data['STYLES']['BRACKETS'][0])) {
>
> ddfd
>

Reply via email to