<?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>guy in the chair . com &#187; MXML</title>
	<atom:link href="http://guyinthechair.com/tag/mxml/feed/" rel="self" type="application/rss+xml" />
	<link>http://guyinthechair.com</link>
	<description>//the blog of Paul Taylor</description>
	<lastBuildDate>Fri, 18 Nov 2011 01:22:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Understanding the Flex SystemManager</title>
		<link>http://guyinthechair.com/2010/01/understanding-the-flex-systemmanager/</link>
		<comments>http://guyinthechair.com/2010/01/understanding-the-flex-systemmanager/#comments</comments>
		<pubDate>Sun, 17 Jan 2010 22:06:50 +0000</pubDate>
		<dc:creator>Paul Taylor</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[MXML]]></category>
		<category><![CDATA[SystemManager]]></category>

		<guid isPermaLink="false">http://guyinthechair.com/?p=113</guid>
		<description><![CDATA[Before I start, let me say that there has been a lot of discussion about the SystemManager on various blogs. Deepa posted a fantastic write-up on the SystemManager back in October 07, which really got me interested in learning about it more. Working on Flex-less MXML is what finally pushed me to understand exactly why [...]]]></description>
			<content:encoded><![CDATA[<p>Before I start, let me say that there has been a lot of discussion about the SystemManager on various blogs. <a title="Deepa's fantastic blog on Flex" href="http://iamdeepa.com/blog/" target="_blank">Deepa</a> posted a fantastic <a title="SystemManager: Every Flex application's best friend" href="http://iamdeepa.com/blog/?p=11" target="_blank">write-up</a> on the SystemManager back in October 07, which really got me interested in learning about it more. Working on Flex-less MXML is what finally pushed me to understand exactly why it&#8217;s such a critical class. There&#8217;s a lot to cover about the SystemManager, from the behavior of the Flash Player to the behavior of the Flex compiler, so buckle up, cause this is a long one.</p>
<p><strong>Note 1: A recurring theme in this post is the fundamental behavior of the Flash Player. Flex would be nowhere without Flash, so if we desire true understanding of Flex, we must also understand the Flash Player.<br />
Note 2: For some of this, it is helpful to turn on the -keep-generated-actionscript flag in the FlashBuilder compiler options. To do this, go to Project &#8211;&gt; Properties &#8211;&gt; Flex Compiler. In the &#8220;Additional compiler arguments&#8221; field, type &#8220;-keep&#8221; at the end of the arguments list. FlashBuilder generates ActionScript from all your MXML, including a dynamic subclass of SystemManager. This will instruct FlashBuilder to place that code in the bin-debug/generated folder.</strong></p>
<p><span style="font-weight: normal; font-size: 14px;">To understand the SystemManager, you must first understand that&#8230;</span></p>
<h2>Every Flex Application is a 2-Frame Flash Movie</h2>
<p><img class="alignleft size-full wp-image-114" title="2 Frame Flash Movie" src="http://guyinthechair.com/wp-content/uploads/2010/01/loader_content_flash.png" alt="2 Frame Flash Movie" width="302" height="63" /> Yes, every one of them. The Flash Player is capable of downloading just the data for the first frame and streaming the rest of the movie. Therefore a trend started in the earlier days of Flash-only developing; you typically put a very small loader object on your first frame that displays the loading progress of the rest of the SWF to the user. That way the user has a visual indication that something is happening, and the movie gets preloaded to a point where the user won&#8217;t experience any playback hiccups.</p>
<h2>That is awesome&#8230; why do I care?<br />
<span style="font-weight: normal; font-size: 14px;">Good question. First, lets examine the implications of Flash&#8217;s load-and-stream feature:</span></h2>
<p>From a movie perspective if frames aren&#8217;t loaded, the movie stops until they are loaded. If the movie is constantly experiencing this, the movie&#8217;s framerate essentially becomes a function of the speed of the user&#8217;s internet connection.<br />
From a code perspective, <strong>if frames aren&#8217;t fully loaded, classes can&#8217;t be accessed</strong>. Calling <code>new MyObject()</code> will throw a runtime error, &#8220;1065: Variable MyObject is not defined.&#8221; This is because the frame that contains the definition for that class hasn&#8217;t been fully loaded.</p>
<h2>Oh I see now, so we need a small preloader on the first frame?<br />
<span style="font-weight: normal; font-size: 14px;">Exactly. All that silly Flash that we thought we left behind when we became &#8220;Enterprise Flex Developers&#8221; has come back to bite us in the ass. But never fear, the SystemManager is here.</span></h2>
<p><strong>The SystemManager is a fancy MovieClip</strong>. The SystemManager has a few duties, including:</p>
<ul>
<li>Create and initialize the pre-loader to show to the user during app load and startup.</li>
<li>Manage loading in RSLs.</li>
<li>Manage module logic. If the SystemManager is the root of the SWF, he knows he is a Flex Application. If he is not the root of the SWF, he knows he is a module, and must communicate with whichever SystemManager is the root of the SWF (see if you can spot the logical flaw of the assumption made in that sentence, there will be a quiz later). SystemManager must communicate events both ways between modules/app, such as mouse and keyboard events.</li>
<li>Manage Event.RESIZE events dispatched from the Stage.</li>
<li>Manages the embedded fonts list</li>
<li>Initializes the various manager singletons, such as ResourceManager and StylesManager.</li>
<li>Manages top-level application windows. The SystemManager maintains a <code>cursorChildren</code> list and a <code>popUpChildren</code> list, for tooltips and pop-up windows respectively.</li>
<li>Once all the code for the movie is loaded, SystemManager creates your actual Application instance and calls <code>initialize()</code>.</li>
<li>Adds the Application to the stage once the Application dispatches its FlexEvent.CREATION_COMPLETE event. This is why the Application doesn&#8217;t have a reference to the stage when its FlexEvent.CREATION_COMPLETE is dispatched, when all the other components do.</li>
</ul>
<h2>How it works<br />
<span style="font-weight: normal; font-size: 14px;">How the SystemManager does its thing. Matching colors are event listening/dispatching pairs.</span></h2>
<table border="0">
<tbody>
<tr>
<td>
<h3>Frame 1</h3>
</td>
<td>
<h3>Frame 2</h3>
</td>
</tr>
<tr>
<td width="50%">
<ul>
<li>stop()</li>
<li>listen for player <span style="color: #ff0000;">init</span> event</li>
<li><span style="color: #ff0000;">init</span> dispatched:
<ol>
<li>get root SystemManager (if we&#8217;re not the top level)</li>
<li> listen for <span style="color: #ff6600;">enterFrame event</span></li>
<li>create preloader</li>
<li>listen for <span style="color: #66FF00;">preloaderDocFrameReady</span> from preloader</li>
<li>listen for <span style="color: #999900;">complete</span> from preloader</li>
<li>load RSLs and wait</li>
<li>RSLs loaded. <span style="color: #66FF00;">preloaderDocFrameReady</span> dispatched by preloader
<ul>
<li><span style="color: #3366ff;">Timer created</span> to go run nextFrame() after 100 milliseconds</li>
</ul>
</li>
<li>Exactly 10 milliseconds after preloaderDocFrameReady dispatched, <span style="color: #999900;">complete</span> dispatched by preloader</li>
<li><span style="color: #3366ff;">Timer event</span> dispatched, nextFrame() called/<span style="color: #ff6600;">enterFrame handler</span> triggered</li>
</ol>
</li>
</ul>
</td>
<td width="50%">
<ul>
<li>Managers initialized.</li>
<li>Stage Resize listener added.</li>
<li>Application instance created.</li>
<li>listener for Application <span style="color: #ff00ff;">creationComplete</span> added</li>
<li>nextFrame()</li>
<li>Application <span style="color: #ff00ff;"> creationComplete</span> dispatched
<ol>
<li>Preloader removed</li>
<li>Application added to the stage</li>
<li>applicationComplete event dispatched</li>
</ol>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
<h2>Hold on, I&#8217;m a Flex developer. I don&#8217;t work with frames.<br />
<span style="font-weight: normal; font-size: 14px;">I don&#8217;t have access to the timeline of my SWF. Actually, you do.</span></h2>
<p>It&#8217;s through an undocumented meta tag, [Frame], which is really just a shortcut for the -frames compiler option. You can <a title="[Frame] meta tag explanation" href="http://blogs.adobe.com/rgonzalez/2006/06/modular_applications_part_2.html" target="_blank">read all about the frame meta tag</a> at Roger Gonzalez&#8217;s blog, but here&#8217;s the gist of it: If you add the [Frame] meta tag to the top of the Application class of your project, the Flex compiler will insert a frame before the frame that your Application is on. If you specify the factoryClass property on the meta tag, the Flex compiler will generate a subclass of whichever class you specify as the factory, and put that on the frame it creates. If you open up the mx.core.Application class, you&#8217;ll see the line [Frame(factoryClass="mx.managers.SystemManager")] near the top. This tells the Flex compiler to create a frame before the mx.core.Application, and attach a generated subclass of mx.managers.SystemManager.</p>
<p>The Flex compiler will generate a subclass of your factory class that implements <code>IFlexModuleFactory</code>. As long as your SystemManager implements IFlexModuleFactory, your code will compile. The Flex compiler overrides the info() method and returns information specific to your Application, such as a list of embedded fonts and the name of your Application.</p>
<p>And with this meta tag, you can override the default SystemManager implementation. As Roger says, &#8220;if the [Frame] metadata exists on the base class of your application, a subclass of the factory will be generated. If the metadata is directly on your application class, it will be honored, but no subclass will be generated; its assumed that you&#8217;ve already written the appropriate factory.&#8221;</p>
<h2>Why this is cool</h2>
<p>Most Flex developers will never even know the SystemManager exists, and they shouldn&#8217;t have to. Adobe has done a good job of masking Flash behind a more professional, Java-like framework with Flex. If you want to write an app with zero dependence on the Flex framework, but still use the fantastic FlashBuilder IDE, debugger/profiler, MXML, and binding, this is really good to know. You can write an Application based on Sprite, write your own stripped down version of the SystemManager, and then write MXML and take advantage of Flex&#8217;s bindings and generated code. Rock on.</p>
]]></content:encoded>
			<wfw:commentRss>http://guyinthechair.com/2010/01/understanding-the-flex-systemmanager/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Physics and Flex: Box2DFlashAS3 meets Flex</title>
		<link>http://guyinthechair.com/2009/10/physics-and-flex-box2dflashas3-meets-flex/</link>
		<comments>http://guyinthechair.com/2009/10/physics-and-flex-box2dflashas3-meets-flex/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 09:17:51 +0000</pubDate>
		<dc:creator>Paul Taylor</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[MXML]]></category>

		<guid isPermaLink="false">http://guyinthechair.com/?p=26</guid>
		<description><![CDATA[Update: I have since abandoned this project in favor of the PushButton Engine, which wraps Box2D and provides a better graphics and component set than I could hope to achieve on my own. So far this has served as a useful academic exercise, and I will keep the code here for future reference. The Setup [...]]]></description>
			<content:encoded><![CDATA[<p><span style="color: #ffcc00;">Update</span><span style="color: #ffcc00;">:</span> I have since abandoned this project in favor of the <a title="PushButton Engine" href="http://pushbuttonengine.com/" target="_blank">PushButton Engine</a>, which wraps Box2D and provides a better graphics and component set than I could hope to achieve on my own. So far this has served as a useful academic exercise, and I will keep the code here for future reference.</p>
<h3>The Setup</h3>
<p>For those not in the know, <a title="Box2D" href="http://www.box2d.org/" target="_blank">Box2D</a> is an open source 2D physics engine for C++. There are many ports of it, and luckily there&#8217;s one for <a title="Box2D Flash AS3" href="http://box2dflash.sourceforge.net/" target="_blank">AS3 (Box2DFlashAS3)</a>. The current version (2.0.2) looks very similar to the C++ version, and might be a straight port (I&#8217;m not entirely sure). It follows the C++ syntax of class prefixes and allows public access to (what should be) internal member variables. 2.1 promises cleaned up syntax and fixed accessor types, but until then, the library can seem daunting to the uninitiated.</p>
<h3>The Problem</h3>
<p>The main problem is that Box2D doesn&#8217;t define a (reusable) way to graphically represent objects on the screen. It only simulates the interactions between the objects mathematically. This is very efficient, but not very convenient if you need to rapidly prototype a physics based application. There are <a title="Box2d Flash World Construction Kit" href="http://www.sideroller.com/wck/" target="_blank">tools</a> to <a title="b2ide Flash components" href="http://code.google.com/p/b2ide/" target="_blank">build</a> Box2D worlds for the Flash environment, but they emphasize working within the Flash IDE. I hate and loathe the Flash IDE (not AS3 projects themselves, mind you). I want something tailored for Flex. I want something that fits into the rapid application development cycle of most Flex apps, which means I want to use MXML. I want to stay up to date with the Box2D project, so when 2.1 does roll around, I won&#8217;t have to rewrite application code.</p>
<h3>The Solution</h3>
<p>Enter FlexWorld. FlexWorld is a framework for graphical representation of Box2D bodies. It is most similar to the <a title="Box2D Flash World Construction Kit" href="http://www.sideroller.com/wck/" target="_blank">World Construction Kit</a>, but is meant exclusively for Flex. You get all the benefits of Flex, including the <a href="http://livedocs.adobe.com/flex/3/langref/mx/managers/LayoutManager.html" target="_blank">LayoutManager</a>, styles, events, data binding, and MXML.</p>
<h3>The Demo</h3>
<p><a href="http://guyinthechair.com/wp-content/flex/flexWorld/demo/index.html" target="_blank">FlexWorld Demo (launches in a new window)</a></p>
<h3>How it Works</h3>
<p>FlexWorld starts with a PhysicalWorld, which is a subclass of <a title="The Container class" href="http://livedocs.adobe.com/flex/3/langref/mx/core/Container.html" target="_blank">Container</a>. PhysicalWorld has boundaries determined by its width and height. Children of the PhysicalWorld are typically subclasses of the abstract class PhysicalBody (which extends <a title="The UIComponent class" href="http://livedocs.adobe.com/flex/3/langref/mx/core/UIComponent.html" target="_blank">UIComponent</a>). Right now, only the PhysicalBox and PhysicalCircle classes are available. World initialization happens only when you say it does, and clean up is as efficient as can be. To get going, initialize the world: PhysicalWorld#createWorld. Then, you can register each PhysicalBody with the world by calling PhysicalWorld#registerBody. This is to ensure proper instantiation and update. When the world is ready to go, just call PhysicalWorld#activate, and it will start rendering.</p>
<h3>In-Phase updates</h3>
<p>PhysicalWorld renders by calling PhysicalBody#update on each PhysicalBody registered with it. This render cycle falls into the commitProperties phase of the component lifecycle (more on that <a title="About the component instantiation life cycle" href="https://www.adobe.com/livedocs/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&amp;file=ascomponents_advanced_148_05.html" target="_blank">here</a> and <a title="About the steps for creating a component" href="https://www.adobe.com/livedocs/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&amp;file=ascomponents_advanced_148_06.html#219779" target="_blank">here</a>). This ensures that properties are changed at the beginning of the lifecycle, just before commits will happen. If the render is meant to continue, updateDisplayList (which is at the end of the update cycle) will call UIComponent#invalidateProperties on the PhysicalWorld.</p>
<h3>Where is this going</h3>
<p>This is a very alpha release. Everything that you see works, and not much else. The shapes aren&#8217;t interactive yet, and they don&#8217;t do much drawing beyond what you see. Nothing is documented (and I&#8217;m horrible at keeping up with it), I don&#8217;t even have an SVN repository set up yet. Right now it&#8217;s primarily an interesting proof-of-concept rather than a useful tool. I&#8217;ll be developing it more for a project I&#8217;m currently on, and hopefully I&#8217;ll roll those changes in.</p>
<h3>The Source</h3>
<p>The source for the demo is <a title="FlexWorld demo source" href="http://guyinthechair.com/wp-content/flex/flexWorld/demo/srcview/index.html" target="_blank">here</a>.<br />
The source for the library (including Box2DFlashAS3 2.0.2) is <a title="FlexWorld library source" href="http://guyinthechair.com/wp-content/flex/flexWorld/source/FlexWorld.zip" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://guyinthechair.com/2009/10/physics-and-flex-box2dflashas3-meets-flex/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

