<?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>Flex Examples &#187; parentApplication</title>
	<atom:link href="http://blog.flexexamples.com/tag/parentapplication/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flexexamples.com</link>
	<description>Just a bunch of Adobe Flex Examples</description>
	<lastBuildDate>Wed, 26 Jan 2011 18:09:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Building a simple Flex module</title>
		<link>http://blog.flexexamples.com/2007/08/06/building-a-simple-flex-module/</link>
		<comments>http://blog.flexexamples.com/2007/08/06/building-a-simple-flex-module/#comments</comments>
		<pubDate>Tue, 07 Aug 2007 06:12:52 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[Module]]></category>
		<category><![CDATA[ModuleLoader]]></category>
		<category><![CDATA[Modules]]></category>
		<category><![CDATA[child]]></category>
		<category><![CDATA[parentApplication]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/06/building-a-simple-flex-module/</guid>
		<description><![CDATA[<p>I&#8217;ve been playing around with Flex Modules lately and thought I&#8217;d post this. It&#8217;s pretty basic, but it is kind of a &#8220;my first module&#8221; type experiment. I tried to show a few different things including: calling a module&#8217;s methods from the parent application as well as setting properties in the parent application from the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing around with Flex Modules lately and thought I&#8217;d post this. It&#8217;s pretty basic, but it is kind of a &#8220;my first module&#8221; type experiment. I tried to show a few different things including: calling a module&#8217;s methods from the parent application as well as setting properties in the parent application from the loaded module.</p>
<p>If you haven&#8217;t looked at modules in Flex yet, I highly encourage you to check out the Flex Doc Team blog at <a href="http://blogs.adobe.com/flexdoc/">http://blogs.adobe.com/flexdoc/</a>, where you can find their latest version of the &#8220;Creating Modular Applications&#8221; chapter (<a href="http://blogs.adobe.com/flexdoc/2007/01/modules_documentation_update.html">blog entry</a>, <a href="http://blogs.adobe.com/flexdoc/pdfs/modular.pdf">PDF</a>).</p>
<p>Full code after the jump.</p>
<p><span id="more-61"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/ModuleLoader_ready_test/bin/srcview/source/main.mxml.html">View MXML (main.mxml)</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2007/08/06/building-a-simple-flex-module/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.events.VideoEvent;

            [Bindable]
            private var moduleTitle:String;

            private var vm:VideoModule;

            private function init():void {
                vm = VideoModule(m1.child);
                moduleTitle = vm.getModuleTitle();
            }

            private function stopVideo():void {
                vm.stopVideo();
            }

            private function playPauseVideo():void {
                vm.playPauseVideo();
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:Panel id="panel"
            title="Module: {moduleTitle}"&gt;
        &lt;mx:ModuleLoader id="m1"
                url="VideoModule.swf"
                ready="init();"/&gt;
        &lt;mx:ControlBar&gt;
            &lt;mx:Button label="Play/Pause" click="playPauseVideo()" /&gt;
            &lt;mx:Button label="Stop" click="stopVideo()" /&gt;
            &lt;mx:Spacer width="100%" /&gt;
            &lt;mx:Label id="playheadTime" fontWeight="bold" /&gt;
        &lt;/mx:ControlBar&gt;
    &lt;/mx:Panel&gt;

&lt;/mx:Application&gt;
</pre>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/ModuleLoader_ready_test/bin/srcview/source/VideoModule.mxml.html">View MXML (VideoModule.mxml)</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2007/08/06/building-a-simple-flex-module/ --&gt;
&lt;mx:Module xmlns:mx="http://www.adobe.com/2006/mxml"
        width="100%"
        height="100%"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            public function getModuleTitle():String {
                return "Video Module";
            }

            /* Stop the video playback. */
            public function stopVideo():void {
                videoDisplay.stop();
            }

            /* If the video is currently playing, pause playback. Otherwise, resume playback. */
            public function playPauseVideo():void {
                if (videoDisplay.playing) {
                    videoDisplay.pause();
                } else {
                    videoDisplay.play();
                }
            }

            private function updateVideoTime():void {
                /* If the playheadTime is 0, the DateFormatter returns an empty string.
                   To work around this we can default the time to 10ms if the playheadTime
                   is zero. */
                var pTime:Date = new Date(videoDisplay.playheadTime * 1000 || 10);
                var tTime:Date = new Date(videoDisplay.totalTime * 1000);
                parentApplication.playheadTime.text = dateFormatter.format(pTime) + " / " + dateFormatter.format(tTime);
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:DateFormatter id="dateFormatter"
            formatString="NN:SS" /&gt;

    &lt;mx:VideoDisplay id="videoDisplay"
            source="http://www.helpexamples.com/flash/video/cuepoints.flv"
            playheadUpdate="updateVideoTime();" /&gt;
&lt;/mx:Module&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/ModuleLoader_ready_test/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/ModuleLoader_ready_test/bin/main.html" width="100%" height="350"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Building a simple Flex module on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/08/06/building-a-simple-flex-module/',contentID: 'post-61',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'child,parentApplication',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2007/08/06/building-a-simple-flex-module/feed/</wfw:commentRss>
		<slash:comments>35</slash:comments>
		</item>
	</channel>
</rss>

