application – DanDev.com http://www.dandev.com Tidbits about software development Wed, 04 Aug 2010 01:51:12 +0000 en-US hourly 1 Flex Tip: Accessing your AS functions/properties from imported classes http://www.dandev.com/2009/05/flex-tip-accessing-your-as-functionsproperties-from-imported-classes/ http://www.dandev.com/2009/05/flex-tip-accessing-your-as-functionsproperties-from-imported-classes/#comments Mon, 25 May 2009 22:54:10 +0000 http://www.dandev.com/?p=151 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 […]

The post Flex Tip: Accessing your AS functions/properties from imported classes appeared first on DanDev.com.

]]>
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()
        {
            // Flex 4
            import mx.core.FlexGlobals; // make "FlexGlobals" available in the current scope
            trace(FlexGlobals.topLevelApplication.myVar); // outputs the value of myVar in the main application

            // Flex 3
            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.

The post Flex Tip: Accessing your AS functions/properties from imported classes appeared first on DanDev.com.

]]>
http://www.dandev.com/2009/05/flex-tip-accessing-your-as-functionsproperties-from-imported-classes/feed/ 1