DanDev.com

Tag: class

Flex Tip: Accessing your AS functions/properties from imported classes

by admin on May.25, 2009, under Development, Flex

Every once in a while you might run across a case where you need to access a property or method from the parent application, and you don’t have the ability to pass the value you need to the class. Or, for example, you’re debugging and you don’t want to write a bunch of code that you’ll have to remove later just to test the value of a variable.

So, with that said the process is fairly simple. The following is a hypothetical example of a class you have imported into your application:

package com.example.scope
{
    private var myVar:String = 'This is NOT the value we're trying to get';
 
    public class scopeExample
    {
        public function scopeExample()
        {
            import mx.core.Application; // make "Application" available in the current scope
            trace(Application.application.myVar); // outputs the value of myVar in the main application
        }
    }
}

You could also use:

trace(parentDocument.myVar); // if the component is a child of the main application

I ran across a post on Holly Schinsky’s blog the other day that had good descriptions of the various scope keywords, and a few tips. All of which is good knowledge to possess, so check it out.

1 Comment :, , , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...