<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Roger Gonzalez</title>
    <link rel="alternate" type="text/html" href="http://blogs.adobe.com/rgonzalez/" />
    <link rel="self" type="application/atom+xml" href="http://blogs.adobe.com/rgonzalez/atom.xml" />
   <id>tag:blogs.adobe.com,2007:/rgonzalez//52</id>
    <link rel="service.post" type="application/atom+xml" href="http://blogs.adobe.com/cgi-bin/mt-atom.cgi/weblog/blog_id=52" title="Roger Gonzalez" />
    <updated>2007-03-10T01:12:35Z</updated>
    <subtitle>Interesting Flex/Flash hacks that are occasionally even useful.</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type 3.2</generator>
 
<entry>
    <title>Goodbye, Adobe!</title>
    <link rel="alternate" type="text/html" href="http://blogs.adobe.com/rgonzalez/2007/03/goodbye_adobe.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.adobe.com/cgi-bin/mt-atom.cgi/weblog/blog_id=52/entry_id=2715" title="Goodbye, Adobe!" />
    <id>tag:blogs.adobe.com,2007:/rgonzalez//52.2715</id>
    
    <published>2007-03-10T01:05:40Z</published>
    <updated>2007-03-10T01:12:35Z</updated>
    
    <summary>Well, today was my last day at Adobe. I&apos;m taking a year off to race motorcycles and tinker with Ideas and think Big Thoughts. I will be setting up a new blog at http://v0.net/rg where I&apos;ll continue to post the...</summary>
    <author>
        <name>Roger Gonzalez</name>
        
    </author>
            <category term="Flex" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.adobe.com/rgonzalez/">
        <![CDATA[<p>Well, today was my last day at Adobe.  I'm taking a year off to race motorcycles and tinker with Ideas and think Big Thoughts.</p>

<p>I will be setting up a new blog at <a href="http://v0.net/rg">http://v0.net/rg</a> where I'll continue to post the occasional article on Flex and Flash (and who knows what else!)  I'll have contact info up for questions and contract gigs.  :-)</p>

<p>Cheers!<br />
</p>]]>
        
    </content>
</entry>
<entry>
    <title>Life at Adobe...</title>
    <link rel="alternate" type="text/html" href="http://blogs.adobe.com/rgonzalez/2006/11/life_at_adobe.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.adobe.com/cgi-bin/mt-atom.cgi/weblog/blog_id=52/entry_id=2139" title="Life at Adobe..." />
    <id>tag:blogs.adobe.com,2006:/rgonzalez//52.2139</id>
    
    <published>2006-11-29T21:39:17Z</published>
    <updated>2006-11-29T21:43:26Z</updated>
    
    <summary>For your amusement, a fairly typical Friday....</summary>
    <author>
        <name>Roger Gonzalez</name>
        
    </author>
            <category term="General" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.adobe.com/rgonzalez/">
        <![CDATA[<p><a href="http://argh.smugmug.com/gallery/2146506">For your amusement, a fairly typical Friday.</a></p>]]>
        
    </content>
</entry>
<entry>
    <title>My MAX preso...</title>
    <link rel="alternate" type="text/html" href="http://blogs.adobe.com/rgonzalez/2006/11/my_max_preso.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.adobe.com/cgi-bin/mt-atom.cgi/weblog/blog_id=52/entry_id=2028" title="My MAX preso..." />
    <id>tag:blogs.adobe.com,2006:/rgonzalez//52.2028</id>
    
    <published>2006-11-08T02:23:15Z</published>
    <updated>2006-11-08T02:29:21Z</updated>
    
    <summary> Here is an archive file containing my slides and demos from MAX. Hopefully they will be of some use to you! Turn on the &quot;notes&quot; view in Powerpoint to see some accompanying description for the slides. I&apos;ve removed most...</summary>
    <author>
        <name>Roger Gonzalez</name>
        
    </author>
            <category term="Flex" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.adobe.com/rgonzalez/">
        <![CDATA[<p></p>

<p><a href="http://blogs.adobe.com/rgonzalez/max_preso.zip">Here is an archive file containing my slides and demos from MAX</a>.  Hopefully they will be of some use to you!</p>

<p>Turn on the "notes" view in Powerpoint to see some accompanying description for the slides.</p>

<p>I've removed most of the assets and SWFs for a variety of size and copyright reasons, so you'll need to tweak the projects a bit to get them to work.</p>

<p><br />
</p>]]>
        
    </content>
</entry>
<entry>
    <title>My 10:30 Wednesday MAX preso...</title>
    <link rel="alternate" type="text/html" href="http://blogs.adobe.com/rgonzalez/2006/10/my_1030_wednesday_max_preso.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.adobe.com/cgi-bin/mt-atom.cgi/weblog/blog_id=52/entry_id=1943" title="My 10:30 Wednesday MAX preso..." />
    <id>tag:blogs.adobe.com,2006:/rgonzalez//52.1943</id>
    
    <published>2006-10-26T01:15:31Z</published>
    <updated>2006-10-26T01:59:56Z</updated>
    
    <summary>So, my first attempt at live coding failed. It turned out it wasn&apos;t the code - it was a silly thing I forgot to do in FlexBuilder in the heat of the moment! I wanted to show how trivial it...</summary>
    <author>
        <name>Roger Gonzalez</name>
        
    </author>
            <category term="Flex" />
            <category term="adobemax2006" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.adobe.com/rgonzalez/">
        <![CDATA[<p>So, my first attempt at live coding failed.  It turned out it wasn't the code - it was a silly thing I forgot to do in FlexBuilder in the heat of the moment!  I wanted to show how trivial it was to write a dynamically loadable module that used bidirectional communication between the loader and loadee, so I prepared a WidgetShell (like a dumb portal) that would read an XML file containing a list of Widget SWFs to load.</p>

<p>Basically, FB doesn't present a way for you to create a new ActionScript project where the main class extends a particular base class or implements an interface.  You have to hand-add that.  However, if you add a class, you get prompted and it will codegen the interface methods for you.  Very handy when you're on stage and can't remember all the methods you need to implement for that module project.</p>

<p>So the trick I discovered was that you can delete the autogenerated class, and add it back at your leisure.  For my preso, I left the (empty) project stub in place (which mostly just contained overrides of the src and bin directories) and planned to add the live-coded widget implementation.</p>

<p>I totally forgot that you then need to mark that new class as the executable application for the project!  D'oh!  It never even compiled my widget!</p>

<p>Oh well.  Perhaps my 4:30 Thursday preso will be a bit more coherent and less coffee-addled.  :-)</p>

<p>Stay tuned, I'll be posting my demo code as a zip in the next day or so.  The copy of the preso in the library doesn't have the best notes in it, so I'll post that as well.  </p>]]>
        
    </content>
</entry>
<entry>
    <title>MAX, modules, and other stuff...</title>
    <link rel="alternate" type="text/html" href="http://blogs.adobe.com/rgonzalez/2006/10/max_modules_and_other_stuff.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.adobe.com/cgi-bin/mt-atom.cgi/weblog/blog_id=52/entry_id=1915" title="MAX, modules, and other stuff..." />
    <id>tag:blogs.adobe.com,2006:/rgonzalez//52.1915</id>
    
    <published>2006-10-20T19:09:27Z</published>
    <updated>2006-10-20T21:25:17Z</updated>
    
    <summary>I&apos;ve been incommunicado in the blogosphere because I&apos;ve been tweaking the compiler to fix some issues discovered in 2.0 that would get in the way of modularizing your app. If you&apos;re one of the lucky few who have had a...</summary>
    <author>
        <name>Roger Gonzalez</name>
        
    </author>
            <category term="Flex" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.adobe.com/rgonzalez/">
        <![CDATA[<p>I've been incommunicado in the blogosphere because I've been tweaking the compiler to fix some issues discovered in 2.0 that would get in the way of modularizing your app.</p>

<p>If you're one of the lucky few who have had a chance to play with 2.0.1, you'll also notice that mx.modules is official!</p>

<p><strong>IM IN UR BETA OPTIMIZING UR SWFS</strong></p>

<p>I've put in numerous refinements since the prototype I posted to my blog a while back, including:<br />
- Both low-level AS API and high-level MXML-oriented declarative API supported<br />
- MXML modules fully work and do the CSS thang<br />
- Runtime stylesheets are now possible and are built using modules!<br />
- You can stream extra classes after the application by using the -frame configuration option.<br />
- There's a dictionary weak-key approach for releasing but reacquiring modules such that they may reload quickly if they didn't get dumped via GC.  This should be handy for apps where you're only ever visiting one giant module at a time.</p>

<p>I'm pretty happy with it all, and hey, guess what?  I'll be talking a lot about modularizing your app (the general issue, but I'll touch on mx.modules) at MAX in two workshop sessions titled "Techniques for Delivering Modular Flex Applications",  on Wednesday at 10:30 am and on Thursday at 4:15 pm.  </p>

<p>In other news, I've decided to move over to the Player team.  The compiler has started to stabilize, which is good for you but not as much fun for me.  I'll be dusting off my C++ and getting my hands dirty at a lower level.  I've gotta say, I'm looking forward to it!</p>

<p>See you at MAX!</p>]]>
        
    </content>
</entry>
<entry>
    <title>No promises yet, but...</title>
    <link rel="alternate" type="text/html" href="http://blogs.adobe.com/rgonzalez/2006/08/no_promises_yet_but.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.adobe.com/cgi-bin/mt-atom.cgi/weblog/blog_id=52/entry_id=1499" title="No promises yet, but..." />
    <id>tag:blogs.adobe.com,2006:/rgonzalez//52.1499</id>
    
    <published>2006-08-17T18:22:51Z</published>
    <updated>2006-08-17T18:28:13Z</updated>
    
    <summary>I finally got the green light! Woohoo! STATUS: Locking 9 files ... STATUS: edit //depot/flex/sdk/frameworks/flex-classes.properties#5 STATUS: edit //depot/flex/sdk/frameworks/framework-classes.properties#26 STATUS: add //depot/flex/sdk/frameworks/mx/modules/IModuleInfo.as#1 STATUS: add //depot/flex/sdk/frameworks/mx/modules/Module.as#1 STATUS: add //depot/flex/sdk/frameworks/mx/modules/ModuleBase.as#1 STATUS: add //depot/flex/sdk/frameworks/mx/modules/ModuleEvent.as#1 STATUS: add //depot/flex/sdk/frameworks/mx/modules/ModuleLoader.as#1 STATUS: add //depot/flex/sdk/frameworks/mx/modules/ModuleManager.as#1 STATUS: edit //depot/flex/sdk/frameworks/mxml-manifest.xml#93 ===&gt;...</summary>
    <author>
        <name>Roger Gonzalez</name>
        
    </author>
            <category term="Flex" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.adobe.com/rgonzalez/">
        <![CDATA[<p>I finally got the green light!  Woohoo!<br />
<pre><br />
STATUS:  Locking 9 files ...<br />
STATUS:  edit //depot/flex/sdk/frameworks/flex-classes.properties#5<br />
STATUS:  edit //depot/flex/sdk/frameworks/framework-classes.properties#26<br />
STATUS:  add //depot/flex/sdk/frameworks/mx/modules/IModuleInfo.as#1<br />
STATUS:  add //depot/flex/sdk/frameworks/mx/modules/Module.as#1<br />
STATUS:  add //depot/flex/sdk/frameworks/mx/modules/ModuleBase.as#1<br />
STATUS:  add //depot/flex/sdk/frameworks/mx/modules/ModuleEvent.as#1<br />
STATUS:  add //depot/flex/sdk/frameworks/mx/modules/ModuleLoader.as#1<br />
STATUS:  add //depot/flex/sdk/frameworks/mx/modules/ModuleManager.as#1<br />
STATUS:  edit //depot/flex/sdk/frameworks/mxml-manifest.xml#93<br />
  ===>   Change 146524 submitted<br />
</pre><br />
</p>]]>
        
    </content>
</entry>
<entry>
    <title>Motorcycle Safety Foundation</title>
    <link rel="alternate" type="text/html" href="http://blogs.adobe.com/rgonzalez/2006/06/motorcycle_safety_foundation.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.adobe.com/cgi-bin/mt-atom.cgi/weblog/blog_id=52/entry_id=1180" title="Motorcycle Safety Foundation" />
    <id>tag:blogs.adobe.com,2006:/rgonzalez//52.1180</id>
    
    <published>2006-06-27T00:55:45Z</published>
    <updated>2006-06-27T01:00:56Z</updated>
    
    <summary>As some people know, I have a weekend gig working as an instructor for the MSF Beginner RiderCourse in Alameda, CA. Its a lot of fun, and if you have any interest, I encourage you to give it a try....</summary>
    <author>
        <name>Roger Gonzalez</name>
        
    </author>
            <category term="Motorcycles" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.adobe.com/rgonzalez/">
        <![CDATA[<p>As some people know, I have a weekend gig working as an instructor for the <a href="http://www.care2ride.net/">MSF Beginner RiderCourse in Alameda, CA</a>.  Its a lot of fun, and if you have any interest, I encourage you to give it a try.  If you do sign up for the course, tell Angela that I sent you!<br />
</p>]]>
        
    </content>
</entry>
<entry>
    <title>Modular Applications (part 2)</title>
    <link rel="alternate" type="text/html" href="http://blogs.adobe.com/rgonzalez/2006/06/modular_applications_part_2.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.adobe.com/cgi-bin/mt-atom.cgi/weblog/blog_id=52/entry_id=1131" title="Modular Applications (part 2)" />
    <id>tag:blogs.adobe.com,2006:/rgonzalez//52.1131</id>
    
    <published>2006-06-17T23:05:24Z</published>
    <updated>2006-06-24T00:20:15Z</updated>
    
    <summary>So, back to where we were going before the digression on ApplicationDomain. One effective way of partitioning an application is to create an application shell that dynamically loads modules. What exactly should a module look like?...</summary>
    <author>
        <name>Roger Gonzalez</name>
        
    </author>
            <category term="Flex" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.adobe.com/rgonzalez/">
        <![CDATA[<p>So, back to where we were going before the digression on ApplicationDomain.  One effective way of partitioning an application is to create an application shell that dynamically loads modules.</p>

<p>What exactly should a module look like?</p>]]>
        <![CDATA[<p>There are a couple choices here.  One possibility would be to just build a SWC, and extract out the SWF, and use it as a "bag of classes" via getDefinition.  Not particularly elegant.</p>

<p>Another possibility would be to build the module as an application.  This is probably somewhat wasteful, because most applications carry some runtime infrastructure with them.</p>

<p>Or, perhaps just build something extending a Flash class like Sprite or MovieClip.  Not a bad possibility, but you'll probably need to just use it as a bag of classes again, unless you intend to use your modules as pure visual elements.</p>

<p>My preference is to build a new base class (lets call it "ModuleBase"!) that takes advantage of the semi-secret and bizarre [Frame] metadata that the Flex compiler uses to build multiframe Flash movies.</p>

<p>What?  You've never heard of [Frame]?  Take a peek in mx.core.Application's source, and you'll see:</p>

<pre>
[Frame(factoryClass="mx.managers.SystemManager")]
</pre>

<p>or take a look in mx.core.SimpleApplication, and you'll see:</p>

<pre>
[Frame(factoryClass="mx.core.FlexApplicationBootstrap")]
</pre>

<p>This metadata is a hint to the compiler that the class containing the metadata would like to be bootstrapped by the cited factory.</p>

<p>In other words, when you build an application based on mx.core.Application, that isn't actually the "root" class of the SWF.  The root class is actually a compiler-generated subclass of mx.managers.SystemManager that overrides the info() method.  Turn on "keep-generated-actionscript" during your compile, and you can see what the compiler generates.</p>

<p>The rules are a bit weird, but basically: 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've already written the appropriate factory.</p>

<p>When a frame factory class has been specified, the compiler will basically create a multi-frame movie, where the factory class is on the previous frame.  It can arbitrarily daisy-chain these frames; you could (although why?) build a 10-frame bootstrapped movie this way.  Note that the metadata is actually just an inline alias for the "frames" compiler configuration option, which lets you explicitly specify the frame classes.</p>

<p>I personally like the notion of module SWFs being multiframe, because (a) it allows the module to use RSLs (which must be loaded before the main class), (b) it allows some interaction with the loaded content as soon as the INIT event fires, and (c) the generated factory subclass is how the compiler generates some information like the list of embedded fonts.</p>

<p>Its really just personal preference.  The one thing I do believe is useful, though, is to have the root class of the SWF be a factory class.  So, if you do extend Sprite or MovieClip, consider implementing some sort of interface that can be used to create the classes within your module.</p>

<p>To explore this concept, I've written the beginnings of a module system, with a demo that exercises it.</p>

<p>Here is <a href="http://blogs.adobe.com/rgonzalez/modules.zip">a ZIP file containing the demo</a>.</p>

<p>The demo uses a small utility library built around a ModuleManager singleton that handles the complexities of loading modules.  Any given module URL is either in an unloaded or loaded state.  After requesting that a module be loaded, an IModuleInfo interface is available.  Once the module is loaded, a factory can be obtained that can be used to create an instance of whatever the module implements.  The modules rely on a factory class to issue a "ready" event when it is safe to invoke the create() function.</p>

<p>The demo exploits this system by having a shell application that loads an XML file containing elements that correspond to SWF file names; for example, if a "square" element is encountered, it tries to find "square.swf", load it as a module, and then invoke the IRenderer interface on the module.  Each module is simply expected to implement this small interface to draw itself.</p>

<p>The code for this demo is pretty simple, and will evolve over time, hopefully into an actual supported library.  For now, its just a small skunkworks project, so enjoy your advanced peek!</p>]]>
    </content>
</entry>
<entry>
    <title>ApplicationDomain</title>
    <link rel="alternate" type="text/html" href="http://blogs.adobe.com/rgonzalez/2006/06/applicationdomain.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.adobe.com/cgi-bin/mt-atom.cgi/weblog/blog_id=52/entry_id=1130" title="ApplicationDomain" />
    <id>tag:blogs.adobe.com,2006:/rgonzalez//52.1130</id>
    
    <published>2006-06-17T21:48:16Z</published>
    <updated>2006-06-22T23:35:36Z</updated>
    
    <summary>ApplicationDomains are pretty much a neverending source of confusion and suffering, but they provide an interesting palette of class definition partitioning. Anyone building an application that dynamically loads SWF files needs to learn and love the AppDom rules......</summary>
    <author>
        <name>Roger Gonzalez</name>
        
    </author>
            <category term="Flex" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.adobe.com/rgonzalez/">
        <![CDATA[<p>ApplicationDomains are pretty much a neverending source of confusion and suffering, but they provide an interesting palette of class definition partitioning.</p>

<p>Anyone building an application that dynamically loads SWF files needs to learn and love the AppDom rules...</p>]]>
        <![CDATA[<p><u>The Rules</u></p>

<p><strong>AppDoms are containers for AS3 definitions</strong></p>

<p>Generally classes, but also functions and namespaces.  You will use the "getDefinition" call to get a reference to one of these definitions, which you might then cast to a Class or a Function.</p>

<p><strong>AppDoms are hooked together into a tree, linked by "parentDomain" pointers. </strong></p>

<p>The topmost AppDom is the system domain, and it contains the built-in Flash types like Sprite, TextField, etc.</p>

<p><strong><br />
If a definition already exists in a parent AppDom, the definition in the child is ignored.</strong></p>

<p>This always surprises people.  As developers, we're used to thinking of definitions as following the most local scope.  Some reasons why we didn't do it that way include:<br />
<ul><br />
<li>The app doing the loading should be the master of the things it loads</li><br />
<li>Flex applications loading Flex applications would would double the memory use if the child used its own class definitions.</li><br />
<li>It reduces some security worries about classes being replaced.</li><br />
<li>It simplifies the implementation of manager singletons (the static parent version is used by the children)</li><br />
<li>Its closer to the old AS2 behavior, where classes were defined via some code that looked something like "if (!_global.Classname) {_global.Classname = ...}", which is a model that the Flex frameworks expects.</li><br />
<li>You can mimic the benefits of the "child wins" behavior by simply rooting a new AppDom on the System domain.</li><br />
</ul></p>

<p>You may or may not find the above arguments compelling.  Its still a source of controversy, even internally.</p>

<p><strong>AppDoms live within a single SecurityDomain</strong></p>

<p>Crossing a security boundary isn't allowed.without explicit trust.</p>

<p><u>Usage</u></p>

<p>Ok, good.  So there's the rules.  How do you use them?  Lets say that you're dynamically loading a SWF:</p>

<pre><xmp>var myLoader:Loader = new Loader();</xmp></pre>

<p>You have some options.  Perhaps..</p>

<pre>myLoader.applicationDomain = new ApplicationDomain()</pre>

<p>This creates a new domain, rooted on the System domain.  What this means is that the classes in this domain are guaranteed to not collide  It also means that you can't talk to them in a strongly typed manner, all you can do is use "getDefinition", and talk to them as Object (or other base Flash types).</p>

<pre>myLoader.applicationDomain 
         = new ApplicationDomain(ApplicationDomain.currentDomain)</pre>

<p>This creates an ApplicationDomain as a child of the current application.  This is the default for the Flex framework, as it allows strongly typed references to the child classes.  For example, a dynamically loaded Flex application will be of type IFlexDisplayObject.</p>

<pre>myLoader.applicationDomain = ApplicationDomain.currentDomain</pre>

<p>This means that new classes will actually be added to the current application context.  This is normally used for Runtime Shared Libraries (RSLs), and isn't especially useful otherwise.  The basic issue is that dangling ("externs") references to classes must be fulfilled before the Actionscript Bytecode (ABC) block containing the references is ever initialized.  This is usually carefully choreographed by ensuring that RSLs are dynamically loaded on the first frame of the application, before any of the classes that depend on the RSL are ever seen.  Its hard to imagine any non-RSL case where adding classes to the current AppDom would be better than loading into a child AppDom.</p>

<p><u>Here's where stuff gets weird...</u></p>

<p>ApplicationDomain.currentDomain is nutty.  It isn't what you think it should be.  Heck, it isn't what I thought it would be, and I helped design ApplicationDomain!</p>

<p>The definition of ApplicationDomain.currentDomain is <em>the ApplicationDomain that contains the code that is calling ApplicationDomain.currentDomain.</em></p>

<p>This is all well and good, until you make a utility function to do something like:<br />
<pre><br />
function create(className:String):Object<br />
{<br />
  var clazz:Class <br />
   = Class(ApplicationDomain.currentDomain.getDefinition(className);</p>

<p>  return new clazz();<br />
}<br />
</pre></p>

<p>and then you use that utility function both in a parent application and in a dynamically loaded child application.  The child's version is ignored (since its in the parent), and the meaning of "current" shifts to mean the parent!  So, its basically impossible for the child to call a shared utility function to get a definition from its own domain unless you pass a handle to currentDomain in, which is often rather inconvenient.</p>

<p>This weirdness has never failed to surprise us.  In fact, we're shipping with a deferred bug in the FlexModuleLoader class (used bySimpleApplication) that exhibits exactly this problem - it tries to find the application class, but fails if both the parent and child are derived from SimpleApplication.  Oops.  We'll send the fix for this out in the first updater.</p>

<p>The solution to this nightmare is to ensure that the code calling ApplicationDomain.currentDomain is unique to that particular SWF.  The only class that you can generally assume to be unique is the root class of the SWF (for MXML-based Applications, its a compiler-generated subclass of SystemManager.  For Actionscript-based code extending SimpleApplication, its a compiler-generated subclass of FlexApplicationBootstrap.)  If you extend Sprite or MovieClip, its up to you, as the compiler doesn't generate a unique subclass, you're just getting a one-frame movie based on your class.</p>

<p>In my next post, I'll get back to discussing modular applications that take advantage of ApplicationDomain to partition classes cleanly for dynamic loading.</p>]]>
    </content>
</entry>
<entry>
    <title>Modular Applications (part 1)</title>
    <link rel="alternate" type="text/html" href="http://blogs.adobe.com/rgonzalez/2006/06/modular_applications_part_1.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.adobe.com/cgi-bin/mt-atom.cgi/weblog/blog_id=52/entry_id=1128" title="Modular Applications (part 1)" />
    <id>tag:blogs.adobe.com,2006:/rgonzalez//52.1128</id>
    
    <published>2006-06-17T21:03:53Z</published>
    <updated>2006-06-17T21:47:46Z</updated>
    
    <summary>There are lots of crazy ways that one can imagine partitioning an application into multiple independently downloadable chunks. At one end of the spectrum, perhaps every single class is in a separate file, downloaded on demand by a classloader. This...</summary>
    <author>
        <name>Roger Gonzalez</name>
        
    </author>
            <category term="Flex" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.adobe.com/rgonzalez/">
        <![CDATA[<p>There are lots of crazy ways that one can imagine partitioning an application into multiple independently downloadable chunks.  At one end of the spectrum, perhaps every single class is in a separate file, downloaded on demand by a classloader.  This would be pretty inefficient, obviously - class references have significant "locality of reference"; if you need one class, odds are pretty good that there are a bunch of other classes that you will also need immediately, and it would be much more efficient to package them all together.</p>

<p>Determining a good packaging scheme is a pretty hard decision for the compiler to make automatically.  Perhaps you would run some sort of profiler on your application during development, and monitor the class references over time.  By seeing when things are referenced, in what order, and more interestingly seeing when things aren't referenced, you could build up statistics to use for computing the optimal partitioning scheme for how many SWFs your application should be built from, and what classes should be in which.  I don't know about you, but while that sounds like a fun research problem, it doesn't seem like its very practical, and I'd hate to have to tell my deadline-obsessed boss how long it would take to "get it working".  (Not to mention the fact that the Flash AVM+ gets really grouchy if it touches an Actionscript Bytecode (ABC) block that contains unknown type references.)</p>

<p>Lets look at a much more practical way of partitioning things.</p>]]>
        <![CDATA[<p>Many applications can be factored as containing two categories of functionality: "stuff needed immediately at startup", and "stuff needed later".</p>

<p>There are lots and lots of applications that fit this model.  Games, for example; you have the core game engine, and a bunch of individual levels.  Or Portals and Portlets; some basic shared functionality, and a data-driven set of little mini-apps that follow a common API.  Or maybe some giant insurance application with 1500 pages of data entry forms, of which a particular run will only touch a few of them.  Or maybe a content-heavy application where it is desireable to be able to independently update parts of the content without having to force users to re-download everything on every visit.</p>

<p>I call these independent pieces of late-loaded functionality "modules", and I call the application that loads these modules the "shell".</p>

<p>Ignoring the "how" for now, lets look at some general issues here.</p>

<p>The thing is, the shell needs to be able to talk to the modules, and the modules need to be able to talk to the shell. If the shell has a hard type reference to a module class, then it will link it in.  Similarly, if the module class has a hard type reference to a shell class, it will link it in.  And the way that ApplicationDomains work (I'll get to this in a subsequent post), there are only two options here: either a class reference is "the same", and shared (and thus was inefficient to download twice) or else it is different (and despite the classes having the same name, they're treated as unrelated, and can't communicate with each other).</p>

<p>The best way to handle this is simply to make the shell and modules communicate through interfaces.  This way, the shell doesn't have a hard type reference to the module, just to some common interface that the module will implement.  Similarly, the module won't bake in the implementation of the shell class(es), just an interface defining the allowed API that modules are allowed to call.</p>

<p>This also reduces the need to recompile modules when the shell changes (or vice versa).  Implementation changes are generally more common than interface changes, so as long as the interface is stable, you don't need to constantly rebuild everything.</p>

<p>Sidebar: yes, you could also use "externs" (or "external-library-path") to build modules that automatically exclude the shell classes - since the module is loaded into a child ApplicationDomain of the shell, it should be safe to extern the shell classes, and thus the module could actually refer directly to implementation classes in the shell code.  However, since the opposite doesn't make sense (the shell can't extern module classes) I think its more symmetric (and aesthetically pleasing) to just use interfaces in both cases.</p>

<p>At this point, we need to digress, and get in-depth with ApplicationDomain for a bit.  We'll get back to Shell/Module applications afterwards.</p>]]>
    </content>
</entry>
<entry>
    <title>Multi-SWF Applications</title>
    <link rel="alternate" type="text/html" href="http://blogs.adobe.com/rgonzalez/2006/06/multiswf_applications.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.adobe.com/cgi-bin/mt-atom.cgi/weblog/blog_id=52/entry_id=1127" title="Multi-SWF Applications" />
    <id>tag:blogs.adobe.com,2006:/rgonzalez//52.1127</id>
    
    <published>2006-06-17T20:01:01Z</published>
    <updated>2006-06-17T21:02:58Z</updated>
    
    <summary>In most cases, the Flex compiler constructs applications by building a two-frame Flash movie, where the first frame contains a preloader (with download progress bar graphic) and the second frame contains the bulk of the application. This allows the application...</summary>
    <author>
        <name>Roger Gonzalez</name>
        
    </author>
            <category term="Flex" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.adobe.com/rgonzalez/">
        <![CDATA[<p>In most cases, the Flex compiler constructs applications by building a two-frame Flash movie, where the first frame contains a preloader (with download progress bar graphic) and the second frame contains the bulk of the application.  This allows the application to start up fairly quickly so that the user isn't staring at a dead window during SWF download.</p>

<p>However, the application is still fundamentally a single monolithic SWF file.  This has a few benefits, but several down sides.</p>]]>
        <![CDATA[<p>The main benefits are simplicity of deployment (one file) and more reliable downloading (single HTTP transaction).</p>

<p>Some disadvantages include the need to wait for entire download before starting, the fact that any trivial change will require the entire application be recompiled, inefficiencies due to the fact that not necessarily all the data downloaded was really required to support a given run of the application, and that for advanced users, it becomes difficult to create certain desireable ApplicationDomain configurations.</p>

<p>I believe that in the future, most Flex applications will be built in a manner where functionality is split into multiple SWF files, loaded on-demand or incrementally.  This will inevitably result in added complexity (partitioning decisions, multi-file deployment) and more failure modes (load errors) that increases with the number of SWF files, but I think it will be possible to use techniques to help make the advantages greatly outweigh the disadvantages.</p>

<p>We're not there yet.  The Flex frameworks is by design a fairly monolithic blob of code.  Once you touch mx.core.Application, you're already going to pull in much of the functionality.  This is why typical MXML applications start off with a fairly high initial download size, but don't greatly increase.  You're payng a one-time cost for the framework code.</p>

<p>Also, the compiler gives you absolutely no help.  The dependency tree from a given class will be relentlessly followed and linked in.  You can play some games by building Runtime Shared Libraries (RSLs) that will help with code sharing between applications, but fundamentally, you're still needing to download all those classes (and assets) in the dependency tree of your application.</p>

<p>So, what to do?  Well, we can start experimenting with alternate architectures for applications.  The good news is that the Flex compiler does in fact provide a bunch of kind of weird low-level features that can let you build some very different types of applications.</p>

<p>In my next post, I'll talk about one particular type of application architecture, built from a "shell" and a set of "modules".</p>]]>
    </content>
</entry>
<entry>
    <title>Howdy</title>
    <link rel="alternate" type="text/html" href="http://blogs.adobe.com/rgonzalez/2006/06/howdy.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.adobe.com/cgi-bin/mt-atom.cgi/weblog/blog_id=52/entry_id=1123" title="Howdy" />
    <id>tag:blogs.adobe.com,2006:/rgonzalez//52.1123</id>
    
    <published>2006-06-16T18:53:49Z</published>
    <updated>2006-06-16T22:52:28Z</updated>
    
    <summary>As I watch Flex roll through the GMC builds, heading inexorably towards release, I realize that there&apos;s a lot of insider knowledge that might be of interest to hardcore Flex/Flash folks - undocumented APIs, clarifications of why we made certain...</summary>
    <author>
        <name>Roger Gonzalez</name>
        
    </author>
            <category term="Flex" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.adobe.com/rgonzalez/">
        <![CDATA[<p>As I watch Flex roll through the GMC builds, heading inexorably towards release, I realize that there's a lot of insider knowledge that might be of interest to hardcore Flex/Flash folks - undocumented APIs, clarifications of why we made certain design decisions, details on subtle bugs that we deferred fixing and why they're hard or risky, insight on weird player behavior, and so forth.  A bunch of this knowledge only exists in my head, and since I risk lanesplitting a motorcycle across the Bay Bridge twice a day, it would probably be a good idea for me to share some of this information with the community ASAP, just in case!</p>]]>
        <![CDATA[<p>A little about me, so that you can decide whether you want to read this blog.  I work on the Flex compiler team.  Everybody on my team tends to touch on code all over the product, but my main area of expertise is the low level construction of SWF files; how bytecode blocks are linked together with assets and put together to form something that the Flash player can consume.  As such, a lot of the code that I provide here will be low-level Actionscript, without fancy MXML effects or deep use of the Flex Frameworks components.  Before Macromedia (Adobe), I was doing a lot of network software development for the web, but my background is really rooted in game development, writing AI software for distributed defense simulators, and robotics.  The applications I write don't look like traditional Flex applications.  You might have seen one of them (a fishtank running the Boids algorithm) used as a benchmark for the Flash player, up on the big screens at the conferences to demonstrate how fast the new VM is.  In short, if you're looking for how to write sophisticated and pretty business applications, this isn't for you.  If you want to learn how to exploit crazy un- and semi-documented tricks in Flash and Flex, keep reading.</p>

<p>Next up, I'll share some of my thoughts on how Flex applications will be built in the future.</p>]]>
    </content>
</entry>

</feed> 

