<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
> <channel><title>DanDev.com &#187; class</title> <atom:link href="http://www.dandev.com/tag/class/feed/" rel="self" type="application/rss+xml" /><link>http://www.dandev.com</link> <description>Daniel&#039;s Dev Blog..ish</description> <lastBuildDate>Sat, 28 Jan 2012 18:06:25 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" /> <item><title>Flex Tip: Accessing your AS functions/properties from imported classes</title><link>http://www.dandev.com/flex/flex-tip-accessing-your-as-functionsproperties-from-imported-classes/</link> <comments>http://www.dandev.com/flex/flex-tip-accessing-your-as-functionsproperties-from-imported-classes/#comments</comments> <pubDate>Mon, 25 May 2009 22:54:10 +0000</pubDate> <dc:creator>Daniel</dc:creator> <category><![CDATA[Development]]></category> <category><![CDATA[Flex]]></category> <category><![CDATA[actionscript]]></category> <category><![CDATA[application]]></category> <category><![CDATA[as3]]></category> <category><![CDATA[class]]></category> <guid
isPermaLink="false">http://www.dandev.com/?p=151</guid> <description><![CDATA[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&#8217;t have the ability to pass the value you need to the class. Or, for example, you&#8217;re debugging and you don&#8217;t want to write a bunch of code that [...]]]></description> <content:encoded><![CDATA[<p>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&#8217;t have the ability to pass the value you need to the class. Or, for example, you&#8217;re debugging and you don&#8217;t want to write a bunch of code that you&#8217;ll have to remove later just to test the value of a variable.</p><p>So, with that said the process is fairly simple. The following is a hypothetical example of a class you have imported into your application:</p><div
class="wp_syntax"><div
class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>example<span style="color: #000066; font-weight: bold;">.</span>scope
<span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> myVar<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;This is NOT the value we're trying to get&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> scopeExample
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> scopeExample<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #009900; font-style: italic;">// Flex 4</span>
            <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>FlexGlobals<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// make &quot;FlexGlobals&quot; available in the current scope</span>
            <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>FlexGlobals<span style="color: #000066; font-weight: bold;">.</span>topLevelApplication<span style="color: #000066; font-weight: bold;">.</span>myVar<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// outputs the value of myVar in the main application</span>
&nbsp;
            <span style="color: #009900; font-style: italic;">// Flex 3</span>
            <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>Application<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// make &quot;Application&quot; available in the current scope</span>
            <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>Application<span style="color: #000066; font-weight: bold;">.</span>application<span style="color: #000066; font-weight: bold;">.</span>myVar<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// outputs the value of myVar in the main application</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div><p>You could also use:</p><div
class="wp_syntax"><div
class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>parentDocument<span style="color: #000066; font-weight: bold;">.</span>myVar<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// if the component is a child of the main application</span></pre></div></div><p>I ran across a post on Holly Schinsky&#8217;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 <a
title="Flex/AIR Application Scope Tips" href="http://devgirl.wordpress.com/2009/01/27/flexair-application-scope-tips/" target="_blank">check it out</a>.</p> ]]></content:encoded> <wfw:commentRss>http://www.dandev.com/flex/flex-tip-accessing-your-as-functionsproperties-from-imported-classes/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> </channel> </rss>
