<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Posts about Flex</title>
    <link>http://wiki.futuretoby.com/tag/flex</link>
    <language>en-us</language>
    <item>
      <title>Flex Compiler Slower on 64bit Mode Java on Snow Leopard</title>
      <description>Ever since I upgraded to Snow Leopard, the my flex apps seemed to compile slower. Today, I finally had enough and took a look into this problem. First, there was the weirdness with Java on Mac in that even though the compiler is a command line application(non-GUI), it creates a application menu. I cracked open the &lt;i&gt;mxmlc&lt;/i&gt; script, and added:&lt;pre&gt;-Djava.awt.headless=true&lt;br&gt;&lt;/pre&gt;&lt;div&gt;to &lt;i&gt;VMARGS&lt;/i&gt;. This solved that issue, but didn't make it compile much faster.&lt;/div&gt;&lt;div&gt;Then, after a bit of fiddling around, it turned out that putting java into 32bit mode:&lt;/div&gt;&lt;pre&gt;-d32&lt;/pre&gt;&lt;div&gt;fixed the problem! The difference was significant. I tested this in 2 different apps. For App 1, it took 45 seconds to compile on 64bit mode, only 9 seconds on 32bit mode. For App 2, it took 30 seconds on 64bit mode, only 7 seconds on 32bit mode. So, &lt;i&gt;mxmlc&lt;/i&gt;&amp;nbsp;performs 4-5 times slower on 64bit java than 32bit, java. Why would this be the case, I have no idea. If anyone has an idea, I'd love to be enlightened. If you come across this problem, the fix is to open up &lt;i&gt;mxmlc&lt;/i&gt;, and edit the line that says:&lt;/div&gt;&lt;pre&gt;VMARGS="-Xmx1024m -Dsun.io.useCanonCaches=false"&lt;br&gt;&lt;/pre&gt;&lt;div&gt;and change it to:&lt;/div&gt;&lt;pre&gt;VMARGS="-Xmx1024m -Dsun.io.useCanonCaches=false -Djava.awt.headless=true -d32"&lt;br&gt;&lt;/pre&gt;&lt;div&gt;I hope that helps someone.&lt;/div&gt;</description>
      <pubDate>Tue, 17 Nov 2009 15:16:37 -0600</pubDate>
      <guid>http://wiki.futuretoby.com/Flex_Compiler_Slower_on_64bit_Mode_Java_on_Snow_Leopard</guid>
      <author>toby ho</author>
      <link>http://wiki.futuretoby.com/Flex_Compiler_Slower_on_64bit_Mode_Java_on_Snow_Leopard</link>
    </item>
    <item>
      <title>Adding Real Properties to FABridge</title>
      <description>Although&amp;nbsp;&lt;a href="http://tobyho.com/Using_the_Flex-Ajax_Bridge"&gt;FABridge is a nice tool&lt;/a&gt;, it's got its shortcomings. I am going to fix one of them now, namely that it doesn't give you real properties, but uses Java's getter setter convention instead. In 3 out 4 browsers, the &lt;i&gt;__defineSetter__&lt;/i&gt; and &lt;i&gt;__defineGetter__&lt;/i&gt; methods are already usable, so why not take advantage? It's really easy as it turned out. Change the &lt;i&gt;addPropertyToType&lt;/i&gt; method to:&lt;pre&gt;    addPropertyToType: function(ty, propName)
    {
        var c = propName.charAt(0);
        var setterName;
        var getterName;
        if(c &amp;gt;= "a" &amp;amp;&amp;amp; c &amp;lt;= "z")
        {
            getterName = "get" + c.toUpperCase() + propName.substr(1);
            setterName = "set" + c.toUpperCase() + propName.substr(1);
        }
        else
        {
            getterName = "get" + propName;
            setterName = "set" + propName;
        }
        function setter(val)
        {
            this.bridge.setPropertyInAS(this.fb_instance_id, propName, val);
        }
        ty[setterName] = setter;
        function getter()
        {
            return this.bridge.deserialize(this.bridge.getPropertyFromAS(this.fb_instance_id, propName));
        }
        ty[getterName] = getter;
        if (ty.__defineGetter__)
            ty.__defineGetter__(propName, getter);
        if (ty.__defineSetter__)
            ty.__defineSetter__(propName, setter);
    },&lt;br&gt;&lt;/pre&gt;&lt;div&gt;&amp;nbsp;And..., &lt;i&gt;voila&lt;/i&gt;! You got yourself real properties. Now instead of writing:&lt;/div&gt;&lt;pre&gt;app.getTextBox()&lt;/pre&gt;&lt;div&gt;You will be much happier writting:&lt;/div&gt;&lt;pre&gt;app.textBox&lt;/pre&gt;&lt;div&gt;On non-sucky browsers that is.&lt;/div&gt;</description>
      <pubDate>Tue, 06 Oct 2009 12:35:30 -0500</pubDate>
      <guid>http://wiki.futuretoby.com/Adding_Real_Properties_to_FABridge</guid>
      <author>toby ho</author>
      <link>http://wiki.futuretoby.com/Adding_Real_Properties_to_FABridge</link>
    </item>
    <item>
      <title>Vector for ActionScript3</title>
      <description>I just&amp;nbsp;&lt;a href="http://stackoverflow.com/questions/1510231/how-to-use-vector-in-flex"&gt;learned about&lt;/a&gt;&amp;nbsp;&lt;a href="http://livedocs.adobe.com/flex/3/langref/Vector.html"&gt;Vector&lt;/a&gt;, it's a typed Array for Actionscript 3, like generics in Java or C#. However, in Actionscript 3, Vector is a one-off: it's the only class that uses the generics syntax, and developers cannot use generics in their own classes. Nevertheless, Vector gives a type-safe alternative to Array and promises big performance gains. Given that it can also&amp;nbsp;&lt;a href="http://stackoverflow.com/questions/1510231/how-to-use-vector-in-flex/1510568#1510568"&gt;give the type&lt;/a&gt;&amp;nbsp;of the containing elements at runtime, I can use it now to drive JSON deserialization into objects too.</description>
      <pubDate>Fri, 02 Oct 2009 12:28:52 -0500</pubDate>
      <guid>http://wiki.futuretoby.com/Vector_for_ActionScript3</guid>
      <author>toby ho</author>
      <link>http://wiki.futuretoby.com/Vector_for_ActionScript3</link>
    </item>
    <item>
      <title>Modifying Core Types in ActionScript 3 Using the Prototype Object</title>
      <description>ActionScript 3 has a Javascript lineage. It was essentially a fork of Ecmascript. Plus, the Adobe team has worked hard on making the language a proper superset of the Ecmascript specification. This is why although ActionScript 3 was a major architechtural change from 2, and as a result became much more like Java than Javascript, it still has support for the&amp;nbsp;&lt;a href="Dissecting the Prototype Chaining"&gt;prototype object&lt;/a&gt;.&amp;nbsp;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;When I learned about the prototype object, it was a fresh air from traditional class-based OOP. Studying cool libraries like&amp;nbsp;&lt;a href="http://prototypejs.org"&gt;prototype.js&lt;/a&gt;&amp;nbsp;made me realize that the prototype model makes javascript far more flexible than some other strictly class-based OO languages.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;One of the cool things you can do with the prototype object in javascript is modify the core classes of the language, like &lt;span class="Apple-style-span" style="font-style: italic;"&gt;Array, String, &lt;/span&gt;and &lt;span class="Apple-style-span" style="font-style: italic;"&gt;Date&lt;/span&gt;. You can do this in ActionScript 3 too, for it conforms to Ecmascript 4. For example, let's say you want to write the &lt;span class="Apple-style-span" style="font-style: italic;"&gt;collect&lt;/span&gt;&amp;nbsp;function for arrays &lt;span class="Apple-style-span" style="font-style: italic;"&gt;a la&lt;/span&gt; ruby. You would do:&lt;/div&gt;&lt;pre&gt;Array.prototype.collect = function(f){&lt;/pre&gt;&lt;pre&gt;  var ret = [];&lt;/pre&gt;&lt;pre&gt;  for each(var it in this) ret.push(f(it));&lt;/pre&gt;&lt;pre&gt;  return ret;&lt;/pre&gt;&lt;pre&gt;}&lt;/pre&gt;&lt;div&gt;There you see me using the nice &amp;nbsp;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;for each&lt;/span&gt;&amp;nbsp;syntax. But, this is going to break the behavior of the array, because now the &lt;span class="Apple-style-span" style="font-style: italic;"&gt;collect&lt;/span&gt;&amp;nbsp;function is going to show up in the enumeration in the &lt;span class="Apple-style-span" style="font-style: italic;"&gt;for each&lt;/span&gt;&amp;nbsp;loops. We don't want that, so to fix that we are going to set the &lt;span class="Apple-style-span" style="font-style: italic;"&gt;collect&lt;/span&gt;&amp;nbsp;attribute of &lt;span class="Apple-style-span" style="font-style: italic;"&gt;Array.prototype&lt;/span&gt; to not be enumerable:&lt;/div&gt;&lt;pre&gt;Array.prototype.setPropertyIsEnumerable('collect', false);&lt;/pre&gt;&lt;div&gt;This allows you to write the following code:&lt;/div&gt;&lt;pre&gt;[1,2,3].collect(function(i){ return i * 2; });&lt;/pre&gt;&lt;pre&gt;// result would be [2,4,6]&lt;/pre&gt;&lt;div&gt;It's kinda tedious to have to &lt;span class="Apple-style-span" style="font-style: italic;"&gt;setPropertyIsEnumerable&amp;nbsp;&lt;/span&gt;for every time we add a function to an existing type, so I wrote a convience function:&lt;br&gt;&lt;/div&gt;&lt;pre&gt;function addMethodsTo(cls:Class, methods){
    for (var name:String in methods){
        cls.prototype[name] = methods[name];
        cls.prototype.setPropertyIsEnumerable(name, false);
    }
}&lt;br&gt;&lt;/pre&gt;&lt;div&gt;Which you can use like so:&lt;/div&gt;&lt;pre&gt;addMethodsTo(Array, {
    collect: function(f){
        var ret = [];
        for each(var it in this) ret.push(f(it));
        return ret;
    },&lt;/pre&gt;&lt;pre&gt;    anotherMethod: function(){&lt;/pre&gt;&lt;pre&gt;        ...&lt;/pre&gt;&lt;pre&gt;    },&lt;/pre&gt;&lt;pre&gt;    ...
});&lt;br&gt;&lt;/pre&gt;&lt;div&gt;This is sort of like the style prototype.js uses for extending/creating classes.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;h2&gt;A Word of Caution&lt;br&gt;&lt;/h2&gt;&lt;div&gt;Before you consider going further with this, I must advice you to think twice before using this technique(however, I hope you &lt;span class="Apple-style-span" style="font-style: italic;"&gt;do&lt;/span&gt; decide to use it afterwards ;). There are several caveats:&lt;/div&gt;&lt;div&gt;&lt;ol&gt;&lt;li&gt;The prototype-based style is a second-class citizen in the world of ActionScript 3 and Flex. The Adobe team as well as the community seem to be much more committed to the class-based approach. I will describe some of the rough edges below.&lt;/li&gt;&lt;li&gt;You will give up compile time type checking for the portions of your code that use this style.&lt;/li&gt;&lt;li&gt;Prototype inheritence is handled by a completely different mechanism than class-based inheritence in the Flash VM and is not as performant.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;h2&gt;Where to put this Code?&lt;br&gt;&lt;/h2&gt;&lt;div&gt;You saw the code example above, but, where do you put it? Since I decided to use a helper function(&lt;span class="Apple-style-span" style="font-style: italic;"&gt;addMethodsTo)&lt;/span&gt;, the code cannot be directly pasted inside the class scope of a class unless the &lt;span class="Apple-style-span" style="font-style: italic;"&gt;addMethodsTo&lt;/span&gt;&amp;nbsp;function is declared to be static(you can only make a method call directly inside class scope if it is a class method). As, a general solution, I'd rather the code be portable. So it should be includable in both class and function scope, and also, I'd like it not to pollute any namespaces.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;My current solution is to put this bit of code inside an anonymous function which immediately gets executed:&lt;/div&gt;&lt;pre&gt;// contents of includes/Array.as&lt;/pre&gt;&lt;pre&gt;(function(){
    include 'addMethodsTo.as';
    addMethodsTo(Array, {
        collect: function(f){
            var ret = [];
            for each(var it in this) ret.push(f(it));
            return ret;
        }
    });
})();&lt;br&gt;&lt;/pre&gt;&lt;div&gt;The &lt;span class="Apple-style-span" style="font-style: italic;"&gt;addMethodTo &lt;/span&gt;function&amp;nbsp;is pulled into a separate file to be easily includable else where.&lt;/div&gt;&lt;div&gt;So, with this, I would do the following to include this Array functionality:&lt;/div&gt;&lt;pre&gt;include 'includes/Array.as';&lt;/pre&gt;&lt;div&gt;Head over to&amp;nbsp;&lt;a href="http://github.com/airportyh/misc/tree/aff1496c9f99ff890801e5ecacdefdbf78be1016/prototype_in_as"&gt;Github&lt;/a&gt;&amp;nbsp;for the complete structure of the files.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;These methods are added during runtime - at exactly the time the above line of included code is executed, and not a moment before. I like to do the include at the top level of the application, this way the entire program has immediate access to the new methods. Oh, and when I said &lt;span class="Apple-style-span" style="font-style: italic;"&gt;entire program&lt;/span&gt;, I do mean the entire program - not just the files that happen to include the file. Well, this is good &lt;span class="Apple-style-span" style="font-style: italic;"&gt;and&lt;/span&gt;&amp;nbsp;bad. This means if you create components that use the array extensions you've created without explicitly including it(you've included it at the entry point of your program), then you have created an &lt;span class="Apple-style-span" style="font-style: italic;"&gt;invisible dependency&lt;/span&gt;. If you try to take the component and use it in a different project without the array extensions, it will not work. Of course, you could also make the dependency explicit by including the file everywhere you are using them, but 1) that's kinda tedious/repetitious, and 2) there's nothing enforcing you to do this.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;h2&gt;Pitfalls and Gotchas&lt;br&gt;&lt;/h2&gt;&lt;div&gt;As I mentioned, the prototype-based programming style is a second-class citizen in the ActionScript 3 world, and so, its use is not particularly well supported. First of all, the compiler does not recognize any of the methods added via the prototype mechanism, and thus cannot perform static type checking on them. But what is funny is the way the compiler copes with this - it depends...on the type in question. For Arrays, the compiler simply allows all method calls - you can call any method on an array, even if it doesn't exist, the compiler won't complain. So, for a call like:&lt;/div&gt;&lt;pre&gt;[1, 2, 3].collect(...);&lt;/pre&gt;&lt;div&gt;The compiler won't even say a word. But for Dates, it gives a warning message. This:&lt;/div&gt;&lt;pre&gt;new Date().format()&lt;br&gt;&lt;/pre&gt;&lt;div&gt;would trigger this warning:&lt;/div&gt;&lt;pre&gt;Warning: format is not a recognized method of the dynamic class Date.&lt;br&gt;&lt;/pre&gt;&lt;div&gt;But, for strings, it's a different story still:&lt;/div&gt;&lt;pre&gt;'one, two, three'.csv2Array()&lt;br&gt;&lt;/pre&gt;&lt;div&gt;compiler says:&lt;/div&gt;&lt;pre&gt;Error: Call to a possibly undefined method csv2Array through a&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;    reference with static type String.&lt;br&gt;&lt;/pre&gt;&lt;div&gt;And the same thing with numbers:&lt;/div&gt;&lt;pre&gt;(2).minutes().ago()&lt;br&gt;&lt;/pre&gt;&lt;div&gt;compiler says:&lt;/div&gt;&lt;pre&gt;Error: Call to a possibly undefined method minutes through a&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;    reference with static type int.&lt;br&gt;&lt;/pre&gt;&lt;div&gt;The work around for strings and numbers is to upcast it to an Object:&lt;/div&gt;&lt;pre&gt;Object('one, two, three').csv2Array();&lt;br&gt;&lt;/pre&gt;&lt;pre&gt;Object(2).minutes().ago();&lt;br&gt;&lt;/pre&gt;&lt;div&gt;or if you just have an untyped variable, it'll work just fine:&lt;/div&gt;&lt;pre&gt;var x = 2;&lt;/pre&gt;&lt;pre&gt;x.minutes().ago();&lt;/pre&gt;&lt;div&gt;See the full code example&amp;nbsp;&lt;a href="http://github.com/airportyh/misc/blob/366479f05b6ef862bd48a83654b511fcd18b3b20/prototype_in_as/ex1.mxml"&gt;here&lt;/a&gt;, and the&amp;nbsp;&lt;a href="http://tobyho.com/uploads/flex_examples/prototype/ex1.swf"&gt;demo&lt;/a&gt;&amp;nbsp;here.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;What about runtime error handling? So let's see what happens if you don't include the extensions and run the code. When I took out the array extension methods, the runtime dutifully throw me the:&lt;/div&gt;&lt;pre&gt;TypeError: Error #1006: collect is not a function.&lt;br&gt;&lt;/pre&gt;&lt;div&gt;This is good, just what I would expect. For Date, it works the same way. Now let's try taking out the string extensions:&lt;/div&gt;&lt;pre&gt;TypeError: Error #1006: value is not a function.&lt;br&gt;&lt;/pre&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;Uhh, what? Not really sure what you mean.&lt;/span&gt; And as you would expect, it works like this for Number&amp;nbsp;as well.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;I have also seen cases where the runtime simply completely &lt;span class="Apple-style-span" style="font-style: italic;"&gt;muffles&lt;/span&gt; an error when there's an undefined method being tried as someone documented&amp;nbsp;&lt;a href="http://turbidwater.blogspot.com/2007/12/flex-sucks-ass.html"&gt;here&lt;/a&gt;. But I am not able to reproduce this just now. Also on another note, the error stacktrace from the flash player(debug version) is not very helpful because although it gives the call stack, there are no line numbers. I am sure that you'd get a better experience using Flex Builder, however.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;I think that about wraps it up. Although extending core types is fun, powerful, and elegent, it's also full of holes and flying scissors everywhere. Are &lt;span class="Apple-style-span" style="font-style: italic;"&gt;you&lt;/span&gt;&amp;nbsp;ready to jump into this brave new world?&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;A message to the Adobe Flex/ActionScript team: I implore you to put more effort into the prototype-based side of the language. It allows for many possibilities which its class-based counterpart cannot offer. I don't dislike the class-based approach. I think the two each have their own strengths and weakness. Which is why I love this hybrid aspect of ActionScript 3 which allows me to use either style in the same environment. I believe that if the prototype-based aspect of ActionScript were to improve and get more exposure, it would not only become a better language, but also a more wide spread language.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;&lt;br&gt;&lt;/span&gt;&lt;/div&gt;&lt;h2&gt;Other Flex-related Articles on my Site&lt;/h2&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://tobyho.com/Making_Flex_Suck_Less"&gt;Making Flex Suck Less&lt;/a&gt;&lt;br&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://tobyho.com/Property_Binding_in_Flex"&gt;Property Binding in Flex&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://tobyho.com/Adding_Real_Properties_to_FABridge"&gt;Adding Real Properties to the FABridge&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;</description>
      <pubDate>Sat, 02 May 2009 21:41:27 -0500</pubDate>
      <guid>http://wiki.futuretoby.com/Modifying_Core_Types_in_ActionScript_3_Using_the_Prototype_Object</guid>
      <author>toby ho</author>
      <link>http://wiki.futuretoby.com/Modifying_Core_Types_in_ActionScript_3_Using_the_Prototype_Object</link>
    </item>
    <item>
      <title>Using the Flex-Ajax Bridge</title>
      <description>The&amp;nbsp;&lt;a href="http://livedocs.adobe.com/flex/3/html/help.html?content=ajaxbridge_1.html"&gt;Flex-Ajax Bridge&lt;/a&gt;&amp;nbsp;is a little javascript library bundled with the Flex SDK that allows you to use javascript to drive your Flex app. It can be really handy for debugging or experimentation when you use it with Firebug's console. For complete setup up instructions,&amp;nbsp;&lt;a href="http://livedocs.adobe.com/flex/3/html/help.html?content=ajaxbridge_3.html#194300"&gt;see here&lt;/a&gt;. You &lt;span class="Apple-style-span" style="font-style: italic;"&gt;do&lt;/span&gt;&amp;nbsp;need to modify your Flex code to get the bridge to work. It's just a one-liner though.&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;To use it, first you get a reference to your flex app:&lt;/div&gt;&lt;pre&gt;app = FABridge.flash.root()&lt;/pre&gt;&lt;div&gt;To get a component by ID, you would do something like:&lt;/div&gt;&lt;pre&gt;app.get('&lt;span class="Apple-style-span" style="font-style: italic;"&gt;myDataGrid&lt;/span&gt;')&lt;/pre&gt;&lt;div&gt;To find out the type of the component:&lt;/div&gt;&lt;pre&gt;app.get('myDataGrid').typeName&lt;/pre&gt;&lt;div&gt;You can call the methods of the component as you would in normal ActionScript. To access the component's properties though, you need to use the Java getter/setter convention:&lt;/div&gt;&lt;pre&gt;app.get('myDataGrid').getSelectedItems()&lt;/pre&gt;&lt;div&gt;This isn't so nice. Ideally, a seamless experience would allow you to write:&lt;/div&gt;&lt;pre&gt;app.myDataGrid.selectedItems&lt;/pre&gt;&lt;div&gt;I guess this is where the weakness of Javascript is coming through. There's no language support for properties(like those in ActionScript, C# Python, etc.) and also no way to do method interception(&lt;span class="Apple-style-span" style="font-style: italic;"&gt;method_missing&lt;/span&gt; in ruby). But I digress.&lt;/div&gt;&lt;div&gt;To instantiate an object of a class in Flex-land, you'd do something like:&lt;/div&gt;&lt;pre&gt;&lt;span class="Apple-style-span" style="font-size: 12px; line-height: normal; white-space: pre-wrap; word-spacing: 0px; "&gt;sprite = FABridge.flash.create("flash.display.Sprite");&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;div&gt;This would call the default constructor. I am not sure how you'd call a constructor with arguments, probably just add on the arguments to &lt;span class="Apple-style-span" style="font-style: italic;"&gt;create()&lt;/span&gt;?&lt;/div&gt;&lt;div&gt;A really cool and useful thing you can do is pass functions as event handlers to into Flex-land. Try this:&lt;/div&gt;&lt;pre&gt;app.get('myButton').addEventListener('click', function(e){&lt;/pre&gt;&lt;pre&gt;    console.log('button clicked!');&lt;/pre&gt;&lt;pre&gt;});&lt;/pre&gt;&lt;div&gt;Now go click that button...cool, heh?&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;Anyway...in conclusion, the Flex-Ajax Bridge is really nice...especially when combined with Firebug.&lt;/div&gt;</description>
      <pubDate>Thu, 23 Apr 2009 22:20:33 -0500</pubDate>
      <guid>http://wiki.futuretoby.com/Using_the_Flex-Ajax_Bridge</guid>
      <author>toby ho</author>
      <link>http://wiki.futuretoby.com/Using_the_Flex-Ajax_Bridge</link>
    </item>
    <item>
      <title>Different Ways of Including Functions in ActionScript</title>
      <description>This is another example of something that would have been a blog post&#160;&lt;a href="http://stackoverflow.com/questions/775093/one-file-per-function-really/782330"&gt;creeping over to SO&lt;/a&gt;.</description>
      <pubDate>Thu, 23 Apr 2009 11:51:41 -0500</pubDate>
      <guid>http://wiki.futuretoby.com/Different_Ways_of_Including_Functions_in_ActionScript</guid>
      <author>toby ho</author>
      <link>http://wiki.futuretoby.com/Different_Ways_of_Including_Functions_in_ActionScript</link>
    </item>
    <item>
      <title>A Custom Drag-n-Drop List Control</title>
      <description>The&#160;&lt;a href="http://livedocs.adobe.com/flex/3/html/help.html?content=dpcontrols_2.html"&gt;List&lt;/a&gt;&#160;control supports drag-n-drop support out of the box - just not the way I want. What it does is allow you to drag something from another list or other type control and drop onto it there by transfering the object dragged into the list control itself. What I want is for something to be dropped onto an item in the list in question. This is how I ended up doing that.&lt;div&gt;&lt;br&gt;&lt;div&gt;By looking at the implementation of ListBase.as in the flex framework source code, I found that I needed to override some methods. So I create a MyList.as file which subclasses the List control. The methods I first needed to override were &lt;span class="Apple-style-span" style="font-style: italic;"&gt;dragEnterHandler&lt;/span&gt; and &lt;span class="Apple-style-span" style="font-style: italic;"&gt;dragOverHandler&lt;/span&gt;.&lt;span class="Apple-style-span" style="font-style: italic;"&gt;&#160;&lt;/span&gt;Both of these methods in ListBase.as look almost identical, here is the source for dragOverHandler:&lt;/div&gt;&lt;pre&gt;    protected function dragEnterHandler(event:DragEvent):void
    {
        if (event.isDefaultPrevented())
            return;

        lastDragEvent = event;

        if (enabled &amp;amp;&amp;amp; iteratorValid &amp;amp;&amp;amp; event.dragSource.hasFormat("items"))
        {
            DragManager.acceptDragDrop(this);
            DragManager.showFeedback(event.ctrlKey ? DragManager.COPY :&#160;&lt;/pre&gt;&lt;pre&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;		&lt;/span&gt;DragManager.MOVE);
            showDropFeedback(event);
            return;
        }

        hideDropFeedback(event);
        
        DragManager.showFeedback(DragManager.NONE);
    }&lt;br&gt;&lt;/pre&gt;&lt;div&gt;The &lt;span class="Apple-style-span" style="font-style: italic;"&gt;showDropFeedback&lt;/span&gt; method draws a line in the List control that indicates where the new item would be inserted into the List. This doesn't apply to us anymore, so I overrode the showDropFeedback method, to just highlight the item under the cursor instead:&lt;/div&gt;&lt;pre&gt;        override public function showDropFeedback(event:DragEvent):void{
            var item = findItemForDragEvent(event);
            var uid:String = itemToUID(item.data);
            if (item){
                drawItem(item, isItemSelected(item.data), true,&#160;&lt;/pre&gt;&lt;pre&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;			&lt;/span&gt;uid == caretUID);
            }
        }&lt;br&gt;&lt;/pre&gt;&lt;div&gt;Moreover, now we want to accept the drop only if the cursor is over a list item, whereas before it allowed for drops on empty parts of the List area. This what I did:&lt;/div&gt;&lt;pre&gt;        override protected function dragEnterHandler(event:DragEvent):void{
            _dragOverHandler(event);
        }
        
        override protected function dragOverHandler(event:DragEvent):void{
            _dragOverHandler(event);
        }
        
        public function findItemForDragEvent(event:DragEvent):Object{
            var item;
            var lastItem;
            var pt:Point = new Point(event.localX, event.localY);
            pt = DisplayObject(event.target).localToGlobal(pt);
            pt = listContent.globalToLocal(pt);
            var rc:int = listItems.length;
            for (var i:int = 0; i &amp;lt; rc; i++)
            {
                if (listItems[i][0])
                    lastItem = listItems[i][0];

                if (rowInfo[i].y &amp;lt;= pt.y &amp;amp;&amp;amp;&#160;&lt;/pre&gt;&lt;pre&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;			&lt;/span&gt;pt.y &amp;lt; rowInfo[i].y + rowInfo[i].height)
                {
                    item = listItems[i][0];
                    break;
                }
            }
            return item;
        }
        
        protected function _dragOverHandler(event:DragEvent):void{
            var item = findItemForDragEvent(event);
            if (item){
                DragManager.acceptDragDrop(this);
                DragManager.showFeedback(&lt;/pre&gt;&lt;pre&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;			&lt;/span&gt;event.ctrlKey ? DragManager.COPY :&#160;&lt;/pre&gt;&lt;pre&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;				&lt;/span&gt;DragManager.MOVE);
                showDropFeedback(event);
            }else{
                DragManager.showFeedback(DragManager.NONE);
            }
        }
&lt;/pre&gt;&lt;div&gt;I wrote a findItemForDragEvent method to find the item that the cursor is currently under or null if none exist - the code was mostly stolen from the calculateDropIndex method in ListBase.as - then I accept the drop if I get a non-null value from it.&lt;br&gt;&lt;/div&gt;&lt;div&gt;I think that's pretty much it. Here's the&#160;&lt;a href="http://tobyho.com/uploads/flex_examples/dnd.swf"&gt;demo&lt;/a&gt;&#160;and the&#160;&lt;a href="http://github.com/airportyh/misc/tree/d133657cfe979ea0e5c7a2e1da962dc0005d9854/flex_custom_dnd_list"&gt;code&lt;/a&gt;.&lt;/div&gt;&lt;/div&gt;</description>
      <pubDate>Thu, 26 Mar 2009 12:04:45 -0500</pubDate>
      <guid>http://wiki.futuretoby.com/A_Custom_Drag-n-Drop_List_Control</guid>
      <author>toby ho</author>
      <link>http://wiki.futuretoby.com/A_Custom_Drag-n-Drop_List_Control</link>
    </item>
    <item>
      <title>Property Binding in Flex</title>
      <description>I have been working more with Flex now, and I have to say: the data binding features(covered&#160;&lt;a href="http://livedocs.adobe.com/flex/3/html/help.html?content=databinding_1.html"&gt;here&lt;/a&gt;) in Flex is beautiful. It's light years ahead of anything I've ever seen before.&#160;&lt;div&gt;&lt;br&gt;&lt;div&gt;Example 1: You want a Text element to show the full name of current selected state from a drop down:&#160;&lt;pre&gt;    &amp;lt;List id="stateList" labelField="abrv"&gt;
        &amp;lt;ArrayCollection&gt;
            &amp;lt;Object abrv="NJ" full="New Jersey"/&gt;
            &amp;lt;Object abrv="MA" full="Massachusetts"/&gt;
            &amp;lt;Object abrv="NY" full="New York"/&gt;
            &amp;lt;Object abrv="NC" full="North Carolina"/&gt;
        &amp;lt;/ArrayCollection&gt;
    &amp;lt;/List&gt;
    &amp;lt;Text text="{stateList.selectedItem.full}"/&gt;&lt;br&gt;&lt;/pre&gt;&lt;div&gt;The code in the curly braces is some ActionScript code, but it doesn't just get executed once, oh no, you can look at it as an invariant, i.e. the content of the said text element will &lt;span class="Apple-style-span" style="font-style: italic;"&gt;always &lt;/span&gt;contain the value expressed by &lt;span class="Apple-style-span" style="font-style: italic;"&gt;stateList.selectedItem.full. &lt;/span&gt;Therefore, when you change the selection of &lt;span class="Apple-style-span" style="font-style: italic;"&gt;stateList&lt;/span&gt;, the text element will immediately change with it. Here's the&#160;&lt;a href="http://github.com/airportyh/misc/blob/ed1d453849a6a876aa8763357016201b06dcb98d/flex_binding/ex1.mxml"&gt;code&lt;/a&gt;&#160;and&#160;&lt;a href="http://tobyho.com/uploads/flex_examples/ex1.swf"&gt;live&#160;demo&lt;/a&gt;&#160;for example 1.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;div&gt;Example 2: Let's try binding to a custom variable rather than to another control. We first make our &lt;span class="Apple-style-span" style="font-style: italic;"&gt;counter&lt;/span&gt; variable public and bindable:&lt;/div&gt;&lt;pre&gt;    &amp;lt;Script&gt;
    [Bindable]
    public var counter:int = 0;&lt;br&gt;&lt;/pre&gt;&lt;div&gt;Then, we can bind a text control to it:&lt;/div&gt;&lt;pre&gt;    &amp;lt;Text text="{counter}"/&gt;&lt;br&gt;&lt;/pre&gt;&lt;div&gt;Next, we can periodically increment the variable like so:&lt;/div&gt;&lt;pre&gt;        setInterval(function(){
            counter++;
        }, 1000);&lt;br&gt;&lt;/pre&gt;&lt;div&gt;And you will see the number in the text display count up: the display in the text element is syncronized with the actually value of &lt;span class="Apple-style-span" style="font-style: italic;"&gt;counter&lt;/span&gt;.&#160;The&#160;&lt;a href="http://github.com/airportyh/misc/blob/ed1d453849a6a876aa8763357016201b06dcb98d/flex_binding/ex2.mxml" style="color: rgb(136, 136, 136); "&gt;code&lt;/a&gt;&#160;and&#160;&lt;a href="http://tobyho.com/uploads/flex_examples/ex2.swf" style="color: rgb(136, 136, 136); "&gt;live demo&#160;&lt;/a&gt;for example 2.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;Next, let's try creating our own properties. ActionScript has support for Java-style OOP(as supposed to Javascript style), but, &lt;span class="Apple-style-span" style="font-style: italic;"&gt;more &lt;/span&gt;interestingly, it's got direct support for properties. Add direct support of property change event bindings, and it's a beautiful thing.&#160;&lt;/div&gt;&lt;div&gt;Example 3: You have a Page object that manages the details of paginating a set of data, and you need some controls to navigate between the pages as well as display what page you are on. You create a Page object:&lt;/div&gt;&lt;pre&gt;    class Page extends EventDispatcher{
        public var number:int;
        public var size:int;
        public var total:int;&lt;br&gt;&lt;/pre&gt;&lt;pre&gt;        ...&lt;/pre&gt;&lt;pre&gt;    }&lt;/pre&gt;&lt;div&gt;A page has a page number, a page size, and the total size of the data set(used to tell whether a page exists). I instantiate a Page object:&lt;/div&gt;&lt;pre&gt;    &amp;lt;Script&gt;
    [Bindable]
    public var currentPage:Page = new Page(0, 10, 100);
    &amp;lt;/Script&gt;&lt;br&gt;&lt;/pre&gt;&lt;div&gt;I need a label that tells me the range of results currently being viewed:&lt;/div&gt;&lt;pre&gt;    &amp;lt;Label text="{currentPage.from} to {currentPage.to}"/&gt;&lt;br&gt;&lt;/pre&gt;&lt;div&gt;Here, the label binds to 2 properties: &lt;span class="Apple-style-span" style="font-style: italic;"&gt;from&lt;/span&gt;&#160;and &lt;span class="Apple-style-span" style="font-style: italic;"&gt;to&lt;/span&gt;. Let's implement these properties:&lt;/div&gt;&lt;pre&gt;    class Page extends EventDispatcher{&lt;br&gt;&lt;/pre&gt;&lt;pre&gt;        ...&lt;/pre&gt;&lt;pre&gt;        [Bindable]
        public function get from():int{
            return number * size + 1;
        }
        [Bindable]
        public function get to():int{
            return (number + 1) * size;
        }&lt;br&gt;&lt;/pre&gt;&lt;pre&gt;        ...&lt;/pre&gt;&lt;pre&gt;    }&lt;/pre&gt;&lt;div&gt;Notice the &lt;span class="Apple-style-span" style="font-style: italic;"&gt;get&lt;/span&gt;&#160;syntax: this in ActionScript turns the function into a getter for a property of the same name. Also notice that I made these properties bindable.&lt;/div&gt;&lt;div&gt;Next, I need the &lt;span class="Apple-style-span" style="font-style: italic;"&gt;previous&lt;/span&gt;&#160;and &lt;span class="Apple-style-span" style="font-style: italic;"&gt;next&lt;/span&gt;&#160;buttons. I choose to sandwich the label in between them:&lt;/div&gt;&lt;pre&gt;    &amp;lt;Button label="Previous" click="currentPage.prev()"/&gt;
    &amp;lt;Label text="{currentPage.from} to {currentPage.to}"/&gt;
    &amp;lt;Button label="Next" click="currentPage.next()"/&gt;&lt;br&gt;&lt;/pre&gt;&lt;div&gt;Clicking on P&lt;span class="Apple-style-span" style="font-style: italic;"&gt;revious&lt;/span&gt;&#160;will call the &lt;span class="Apple-style-span" style="font-style: italic;"&gt;prev &lt;/span&gt;method and clicking on &lt;span class="Apple-style-span" style="font-style: italic;"&gt;Next&lt;/span&gt;&#160;will call the &lt;span class="Apple-style-span" style="font-style: italic;"&gt;next&lt;/span&gt;&#160;method. Simple. Here is the code:&lt;/div&gt;&lt;pre&gt;        public function next(){
            number++;
        }
        
        public function prev(){
            number--;
        }&lt;br&gt;&lt;/pre&gt;&lt;div&gt;Compiled it, but it doesn't work. Clicking on &lt;span class="Apple-style-span" style="font-style: italic;"&gt;Previous&lt;/span&gt;&#160;and &lt;span class="Apple-style-span" style="font-style: italic;"&gt;Next&lt;/span&gt;&#160;does no change the display on the label at all. Oh! We need to fire the events! To fire a property change event, you'd do something like:&lt;/div&gt;&lt;pre&gt;                this.dispatchEvent(new PropertyChangeEvent(
                    "propertyChange", true, true, 
                    PropertyChangeEventKind.UPDATE,
                    propertyName, null, null, this));&lt;br&gt;&lt;/pre&gt;&lt;div&gt;In our case, we are going to fire the change events for both &lt;span class="Apple-style-span" style="font-style: italic;"&gt;from &lt;/span&gt;and &lt;span class="Apple-style-span" style="font-style: italic;"&gt;to&lt;/span&gt;, because both of those must change after you flip a page. So we fire the changes:&lt;/div&gt;&lt;pre&gt;        private function fireChanges(){
            var toFire = ['from', 'to'];
            for (var i = 0; i &amp;lt; toFire.length; i++)
                this.dispatchEvent(new PropertyChangeEvent(
                    "propertyChange", true, true, 
                    PropertyChangeEventKind.UPDATE,
                    toFire[i], null, null, this));
        }
        public function next(){
            number++;
            fireChanges();
        }
        public function prev(){
            number--;
            fireChanges();
        }&lt;br&gt;&lt;/pre&gt;&lt;div&gt;Ok, but I would like to disable the &lt;span class="Apple-style-span" style="font-style: italic;"&gt;Previous&lt;/span&gt;&#160;or &lt;span class="Apple-style-span" style="font-style: italic;"&gt;Next&lt;/span&gt;&#160;button when we are at the begining or the end of the dataset. No problem! We create a couple more bindable properties: &lt;span class="Apple-style-span" style="font-style: italic;"&gt;hasNext&lt;/span&gt;&#160;and &lt;span class="Apple-style-span" style="font-style: italic;"&gt;hasPrev&lt;/span&gt;:&lt;/div&gt;&lt;pre&gt;        [Bindable]
        public function get hasNext():Boolean{
            return to &amp;lt; total;
        }
        [Bindable]
        public function get hasPrev():Boolean{
            return number &gt; 0;
        }&lt;br&gt;&lt;/pre&gt;&lt;div&gt;Bind the buttons' &lt;span class="Apple-style-span" style="font-style: italic;"&gt;enabled&lt;/span&gt;&#160;property to them:&lt;/div&gt;&lt;pre&gt;    &amp;lt;Button label="Previous" click="currentPage.prev()"&#160;&lt;/pre&gt;&lt;pre&gt;        enabled="{currentPage.hasPrev}"/&gt;
    &amp;lt;Label text="{currentPage.from} to {currentPage.to}"/&gt;
    &amp;lt;Button label="Next" click="currentPage.next()"&lt;/pre&gt;&lt;pre&gt;        enabled="{currentPage.hasNext}"/&gt;&lt;br&gt;&lt;/pre&gt;&lt;div&gt;Make sure to fire the change events for them too when you are flipping pages(add them to &lt;span class="Apple-style-span" style="font-style: italic;"&gt;toFire &lt;/span&gt;in the implementation of &lt;span class="Apple-style-span" style="font-style: italic;"&gt;fireChanges&lt;/span&gt;)&#160;and we are done.&#160;The code:&#160;&lt;a href="http://github.com/airportyh/misc/blob/ed1d453849a6a876aa8763357016201b06dcb98d/flex_binding/ex3.mxml" style="color: rgb(136, 136, 136); "&gt;ex3.mxml&lt;/a&gt;,&#160;&lt;a href="http://github.com/airportyh/misc/blob/ed1d453849a6a876aa8763357016201b06dcb98d/flex_binding/Page.as" style="color: rgb(136, 136, 136); "&gt;Page.as&lt;/a&gt;&#160;and&#160;&lt;a href="http://tobyho.com/uploads/flex_examples/ex3.swf" style="color: rgb(136, 136, 136); "&gt;live demo&lt;/a&gt;&#160;for example 3.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;The end result of this is that you have very well separated MVC code. There isn't any code whose sole purpose is to sync the display like you get with jQuery code, for example. The code to do this is very minimal and naturally readable.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;All code examples can be found&#160;&lt;a href="http://github.com/airportyh/misc/tree/ed1d453849a6a876aa8763357016201b06dcb98d/flex_binding"&gt;here&lt;/a&gt;&#160;on Github.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;Btw, I should mention that, the code inside of the curly braces does not allow any arbitrary ActionScript. There is some amount of flexibility, but not a lot. You can read more&#160;&lt;a href="http://livedocs.adobe.com/flex/3/html/help.html?content=databinding_2.html"&gt;here&lt;/a&gt;.&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
      <pubDate>Wed, 11 Mar 2009 01:01:36 -0500</pubDate>
      <guid>http://wiki.futuretoby.com/Property_Binding_in_Flex</guid>
      <author>toby ho</author>
      <link>http://wiki.futuretoby.com/Property_Binding_in_Flex</link>
    </item>
    <item>
      <title>Making Flex Suck Less</title>
      <description>This is a follow up to &lt;a href="/FLEX:_first_impressions" mce_href="/FLEX:_first_impressions"&gt;my last Flex post&lt;/a&gt;. As I am learning more about Flex I have learned ways to address all 3 of the items in the &lt;i&gt;cons &lt;/i&gt;list.&lt;br&gt;&lt;ol&gt;&lt;li&gt;&lt;i&gt;Development feedback - not as instant.&lt;/i&gt; I mentioned that Flex has a compile step in the development process, this cannot be fixed. But the lack of an interactive console can be addressed by using the Javascript bridge, with which you can use Firebug to script your Flex app. There are inevitably some limitations, of course(like, I don't think you can pass functions to and from Flex land; and you can't modify the existing code), but by and large it is extremely useful. The scripting ability alleviates the slower feedback problem even though it does not eliminate it.&lt;/li&gt;&lt;li&gt;&lt;i&gt;Mandatory Static Typing.&lt;/i&gt; I misspoke on this one. Actually the static typing isn't mandatory at all. I mistook the warnings from the compiler to be errors. You have the option of turning off the warnings. Now I can eliminate a lot of what I dim the unnecessary type declarations from my code. However, I will not remove type declarations entirely, because I believe static type checking &lt;span class="Apple-style-span" style="font-style: italic;"&gt;is&lt;/span&gt; immensely useful for situations where 1) it takes some time for the program to start up, and 2) it takes some user navigation actions to get to the place you want to test. The type checker will catch a class of stupid errors, which if you encounter only after waiting and performing a series of mouse clicks and key presses, can make you irritated quickly. My rule of thumb for type declaration in ActionScript is: 1) declare function input and output types; 2) declare global variable types; 3) local variables may or may not be declared, depending on the situation(if the variable is used extensively in the function, then declare); 4) do not declare if the type is void(i.e. nothing). I've never &lt;i&gt;really &lt;/i&gt;worked with a language that has optional type checking, this is fresh! The browsers in the future will have this too in Ecmascript 4. Another language that has this is Groovy, and I heard &lt;a href="http://blogs.msdn.com/charlie/archive/2008/11/13/anders-hejlsberg-video-on-c-dynamic.aspx" mce_href="http://blogs.msdn.com/charlie/archive/2008/11/13/anders-hejlsberg-video-on-c-dynamic.aspx"&gt;C# is adding this too&lt;/a&gt;, how exciting! I SOOO admire Anders Hejlsberg. &lt;i&gt;(after seeing the video it seems it's more like a bridge to scripting languages/libraries)&lt;/i&gt; &lt;/li&gt;&lt;li&gt;As for the mx: prefix, I've &lt;a href="http://stackoverflow.com/questions/284530/is-it-a-bad-idea-to-get-rid-of-the-mx-in-your-flex-code" mce_href="http://stackoverflow.com/questions/284530/is-it-a-bad-idea-to-get-rid-of-the-mx-in-your-flex-code"&gt;already figured out how to do without it&lt;/a&gt;. So you can write &lt;font face="courier new,courier"&gt;&amp;lt;Panel ...&gt;&lt;/font&gt; rather than &lt;font face="courier new,courier"&gt;&amp;lt;mx:Panel...&gt;&lt;/font&gt;&lt;/li&gt;&lt;/ol&gt;In conclusion, Flex is actually an even better development environment than I gave it credit for last time. &lt;br&gt;</description>
      <pubDate>Wed, 26 Nov 2008 20:47:25 -0600</pubDate>
      <guid>http://wiki.futuretoby.com/Making_Flex_Suck_Less</guid>
      <author>toby ho</author>
      <link>http://wiki.futuretoby.com/Making_Flex_Suck_Less</link>
    </item>
    <item>
      <title>FLEX: first impressions</title>
      <description>At work I am required to write a web UI that has a rich-desktop kind of interface. Without getting into too much details, it's layout will look a bit like an older email application(e.g. outlook, the older versions). It also need to have drag-n-drop capabilities. I whipped up a prototype of the UI using prototype and scriptaculous, since that's what I've been getting fluent with. A couple of things about my prototype made me decide to give Flex a try.&lt;br&gt;&lt;ol&gt;&lt;li&gt;No draggable divider. The draggable divider - although not essential - is something that seasoned computer users have learned to expect when you give them interfaces that have multiple panels jammed onto one screen. Scriptaculous didn't have an draggable divider widget. YUI and ExtJS did, and I am not against learing a new library. But I get the vibe that their implementations might not be rock solid.&lt;br&gt;&lt;/li&gt;&lt;li&gt;Buggy drag-n-drop libary. Scriptaculous comes with a drag-n-drop library. I've used it in multiple occations. It's also been buggy for me on multiple occations. A lot of the bugs are attributed to differences in browsers.&lt;/li&gt;&lt;/ol&gt;I decided that I was tired of chasing down cross browser bugs, which will only grow exponentially the more complex my UI gets. Therefore, Flex could really be the answer to these problems.&lt;br&gt;&lt;br&gt;I am probably 60% done with my port of the UI prototype from Javascript/prototype/scriptaculous to Flex. I am happy with it for the most part. Here are my first impressions of Flex. First the pros:&lt;br&gt;&lt;ol&gt;&lt;li&gt;Programming in Flex is suprisingly similar to programming in HTML/javascript/CSS. (Well, not as suprising as it could have been since I've heard Charles Lowe say the same on DrunkAndRetired.com podcast). You write a mxml file, which is like your markup - in place of your HTML; you write ActionScript inplace of Javascript; and there's a css 3 compliant stylesheet you can use to style the UI.&lt;/li&gt;&lt;li&gt;Flex has a rich UI component model that similar to many of the desktop UI toolkits(Swing, GTK, MFC, etc), which is a departure from the HTML/Javascript model. This is a plus because you get a lot of widgets you can use out of the box with very little code. Using third party Javascript widgets is usually &lt;i&gt;more involved&lt;/i&gt;.&lt;/li&gt;&lt;li&gt;ActionScript is not much different from Javascript, so people literate in Javascript should pick it up easily. The only significant difference I've noticed so far is the type declaration syntax - ActionScript is statically typed. I believe ActionScript is compatible with a newer version of Ecmascript which has optional type declaration for variables and parameters. Type declaration in ActionScript(as far I can tell) is required on function parameters and global variables(errors out if you leave it), and optional on local variables(warns you if you leave it).&lt;br&gt;&lt;/li&gt;&lt;li&gt;Yes, you have to write XML, but it's not &lt;i&gt;that&lt;/i&gt; bad. I have expressed my hatred for making programmers read and write XML by hand in the past. It's inhumane! Flex makes you do that. Yes. But! It's used in a way that's not as bad as some other ways in which XML have been used(build scripts, web configuration, for example). In Flex, XML is used for Markup (wow! a markup language used for markup? what a concept?). The XML declaratively defines the UI(such as in HTML), which, I my opinion, is the way UI's ought to be written, and not in a procedure way(such as in Swing).&lt;br&gt;&lt;/li&gt;&lt;li&gt;Flex components look good by default. For HTML/CSS you always have to design your own theme - even if you just want it to look half way decent. No such BS in Flex. Flex components look good out of the box(no CSS tweaks or includes required), because of this I believe you can prototype Flex UIs faster.&lt;/li&gt;&lt;li&gt;A Flex app runs exactly the same on any browser it supports. This was the main sell for me. Nothing more needs to be said.&lt;/li&gt;&lt;/ol&gt;Now the cons:&lt;br&gt;&lt;ol&gt;&lt;li&gt;Development feedback - not as instant. Developer feedback loop is slower because of the compile step. ActionScript is a compiled language, and you need to compile your Flex programing to get a SWF file. Also, in Flex 3, they &lt;a href="http://www.colettas.org/?p=17" mce_href="http://www.colettas.org/?p=17"&gt;took away the eval() function&lt;/a&gt;(why oh why???). This means you cannot create an interactive shell in Flex like Firebug or the python shell.&lt;/li&gt;&lt;li&gt;Mandatory Static typing. Although I have nothing against static typing in general. I don't like mandatory static typing(such as exists in Java, C#, C++). Haskell is a staticly typed language, it verifies all your types for you, and yet it doesn't require you to specify the types of all you variables and parameters because it can infer them all for you. I like that. This is not a big issue for me, it's just not as kosher as Javascript in this respect.&lt;/li&gt;&lt;li&gt;&lt;strike&gt;It's annoying that you have to write mx: to begin all Flex component tags in the mxml spec. No such BS in HTML. I tried a &lt;a href="http://stackoverflow.com/questions/284530/is-it-a-bad-idea-to-get-rid-of-the-mx-in-your-flex-code" mce_href="http://stackoverflow.com/questions/284530/is-it-a-bad-idea-to-get-rid-of-the-mx-in-your-flex-code"&gt;hack to do without it&lt;/a&gt;, it didn't work so well.&lt;/strike&gt;&lt;br&gt;&lt;i&gt;Update: Looks like I have &lt;a href="http://stackoverflow.com/questions/284530/is-it-a-bad-idea-to-get-rid-of-the-mx-in-your-flex-code"&gt;gotten rid of the mx: problem&lt;/a&gt;. I guess I showed &lt;/i&gt;&lt;i&gt;them ;)&lt;/i&gt;&lt;br&gt;&lt;/li&gt;&lt;/ol&gt;Overall, the pros are worth more than the cons. Linguistically, I prefer Javascript to ActionScript and HTML to MXML, so it's not going to &lt;a href="http://tv.winelibrary.com/" mce_href="http://tv.winelibrary.com/"&gt;Change My Life(TM)&lt;/a&gt;. But the UI component model and cross browser compatibility greatly outweigh those nags.&lt;br&gt;&lt;br&gt;</description>
      <pubDate>Thu, 20 Nov 2008 18:51:45 -0600</pubDate>
      <guid>http://wiki.futuretoby.com/FLEX%3A_first_impressions</guid>
      <author>toby ho</author>
      <link>http://wiki.futuretoby.com/FLEX%3A_first_impressions</link>
    </item>
  </channel>
</rss>

