<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
   <channel>
      <title>Learning Flex 2.0</title>
      <link>http://www.evilfree.com/adam/blog/</link>
      <description>Thoughts as I&apos;m learning Flex 2.0,  things I have discovered, tips &amp; tricks.</description>
      <language>en</language>
      <copyright>Copyright 2006</copyright>
      <lastBuildDate>Wed, 14 Dec 2005 13:21:01 -0500</lastBuildDate>
      <generator>http://www.sixapart.com/movabletype/?v=3.2</generator>
      <docs>http://blogs.law.harvard.edu/tech/rss</docs> 

            <item>
         <title>Flex 2 Example (admin for news ticker) - Editing XML and saving it back to the server</title>
         <description><![CDATA[<p>In this example we pull some XML data into Flex and keep it as an XML object.   We then edit the data with a Flex GUI and save it back to the server.  To make things more interesting I created a simple “News Ticker” in Flash 8 that is built from the same XML.   You get a semi-automatic preview of the ticker directly within the GUI.</p>

<p>I can see a real use for these simple Flex apps to easily allow people to manage all sorts of configurations settings without having to actually look at the XML (or other underlining data).  </p>

<p>The ticker (4kb) is shown at the end of this post.  Everyone can modify the data using the admin control… so I don’t know how the ticker will look when you view it at this point in time.</p>

<p>There is nothing “fancy” in the Flex code just a lot of semi-manual binding of various data elements to the nodes and attributes in the XML file.  The source code is commented and it shouldn’t be hard to understand what is happening.  If you have any questions post them below and I’ll answer them.</p>

<p>Files:<br />
<a href="http://www.evilfree.com/flex/example3/">Admin For Ticker (requires Flash 8.5 player)</a><br />
<a href="http://www.evilfree.com/flex/example3/example3.zip">Project File</a><br />
<a href="http://www.evilfree.com/flex/example3/example3.mxml">MXML File</a><br />
<a href="http://www.evilfree.com/flex/example3/main.as">Linked Actionscript in MXML</a><br />
<a href="http://www.evilfree.com/flex/example3/config.xml">Current XML</a></p>

<p>Ticker:<br />
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="500" height="500" id="ticker" align="middle"><br />
<param name="allowScriptAccess" value="sameDomain" /><br />
<param name="movie" value="http://www.evilfree.com/flex/example3/ticker-hardLink.swf" /><param name="quality" value="high" /><param name="scale" value="noscale" /><param name="salign" value="lt" /><param name="bgcolor" value="#ffffff" /><embed src="http://www.evilfree.com/flex/example3/ticker-hardLink.swf" quality="high" scale="noscale" salign="lt" bgcolor="#ffffff" width="400" height="750" name="ticker" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /><br />
</object></p>]]></description>
         <link>http://www.evilfree.com/adam/blog/2005/12/flex_example_editing_xml_save.html</link>
         <guid>http://www.evilfree.com/adam/blog/2005/12/flex_example_editing_xml_save.html</guid>
         <category>Flex</category>
         <pubDate>Wed, 14 Dec 2005 13:21:01 -0500</pubDate>
      </item>
            <item>
         <title>Flex Data Binding - Nodes or Attributes?</title>
         <description><![CDATA[<p>The last <a href="http://www.evilfree.com/adam/blog/2005/11/drilling_down_into_the_data.html">example</a> showed one EASY way to drill down and access your data with Flex.  </p>

<p>If you noticed, all of the "data" in my XML file was stored in the attributes of a node, rather than in the child nodes.  All of the examples I have seen from Macromedia show the XML formatted with the data contained in child nodes.    </p>

<p>What is interesting and somewhat disconcerting is that your XML data can be formatted either way and you <strong>do not</strong> need to make any changes to your code.</p>

<p>So what happens if you have an attribute name with some data and a child node of the same name?  In this case the attribute wins and takes precedence over the child node.  </p>

<p>I took the "<a href="http://www.evilfree.com/adam/blog/2005/11/drilling_down_into_the_data.html">Drilling Down into Data</a>" example and modified it to load one of three different XML files on button click.  You can view it below and see how each XML file is used.</p>

<p><a href="http://www.evilfree.com/flex/example2/">View Example</a><br />
<a href="http://www.evilfree.com/flex/example2/example2.mxml">View Source MXML</a><br />
<a href="http://www.evilfree.com/flex/example2/content.xml">View Attribute XML</a><br />
<a href="http://www.evilfree.com/flex/example2/content2.xml">View Node XML</a><br />
<a href="http://www.evilfree.com/flex/example2/content3.xml">View Node XML with an Attribute</a></p>

<p>I find it confusing that you can use either type of XML without any changes to your code.  I think it would make more sense if you used a "@" when you wanted to access an attribute rather than a node.  This is how you access attributes with E4X in actionscript 3.</p>

<p>So:</p>

<p>mx:ComboBox x="25" y="60" width="190" id="locationSelector"  labelField="title" dataProvider="{contentData.tourContent.mLocation}"</p>

<p>could be</p>

<p>mx:ComboBox x="25" y="60" width="190" id="locationSelector"  <strong>labelField="@title"</strong> dataProvider="{contentData.tourContent.mLocation}"<br />
</p>]]></description>
         <link>http://www.evilfree.com/adam/blog/2005/11/flex_data_binding_nodes_or_att.html</link>
         <guid>http://www.evilfree.com/adam/blog/2005/11/flex_data_binding_nodes_or_att.html</guid>
         <category>Flex</category>
         <pubDate>Tue, 29 Nov 2005 16:38:21 -0500</pubDate>
      </item>
            <item>
         <title>Drilling Down into Data</title>
         <description><![CDATA[<p>This demo shows the ability of Flex to delve deeply into nested data with small amounts of intuitive code.</p>

<p><strong>Here is an example I created.</strong><br />
<a href="http://www.evilfree.com/flex/example1/">View Example</a> (Flash Player 8.5 required)<br />
<a href="http://www.evilfree.com/flex/example1/example.mxml">View Source MXML</a><br />
<a href="http://www.evilfree.com/flex/example1/content.xml">View Source XML</a></p>

<p>When you first launch the demo it loads the "content.xml" file.  This is caused by the <strong>"initialize="contentDataService.send()"</strong> tag in the mx:Application node and of course the contentDataService mx:HTTPService.</p>

<p><strong>Once the data is loaded here is what happens:</strong></p>

<blockquote>The select location comboBox is populated with the result from the service call.  The first item (index 0) is automatically selected.  

<p>The location description box pulls the "selectedItem" from the locationSelector combobox and snatches the description attribute from it.</p>

<p>The tour stop pulls its data from the selectedItem in the locationSelector combobox.</p>

<p>Tour stop description, image dataGrid and pan dataGrid pull data from the selectedItem of the tourStopSelector comboBox.</p>

<p>Image and pan descriptions are pulled from the corresponding dataGrids.</p>

<p>The URL List is populated from the selected Pan in the pan dataGrid.</p>

<p>And finally the URL path window pulls the path from the selected URL in the URLdatagrid.</blockquote></p>

<p>This way of referencing data is really slick!  Each item is using the selected bit of a "parent item" as its datasource instead of having to create an absolute reference to the data using the orginal mx:HTTPService call.  It like each component has its only little "scope" to work within.  Plus, Flex will automatically take care of all the databinding for you.  Whenever you change the selection of something all dependent items are updated automatically.  This is easy to as you play around with the demo.</p>

<p>So let’s compare the amount of code it takes to reference data with the relative method vs. an absolute path. Looking at the final URL path portion of a URL assigned to a Pan.</p>

<p><strong>Compare:</strong></p>

<p><em>text="{panURLs.selectedItem.urlPath}"</em><br />
vs.<br />
<em>text="{contentDataService.result.tourContent. mLocation[locationSelector.selectedIndex]. tourStop[tourSelector.selectedIndex].pan[tourPans.selectedIndex]. url[panURLs.selectedIndex].urlPath}"</em></p>

<p>It is interesting to note that the automatic databinding does not work correctly when using the absolute path in this way.  Strangely it does work when you are viewing the URL paths within My Home -> Living Room -> Living Room Pan 1, but not in any others.  No sure why...</p>

<p>One other thing I wanted to mention is the use of the labelField and ColumnName tags. By default many components will look for a "label" attribute or node to use as the label for each item they contain.  When you set the labelField (or ColumnName) to a different value it will look for that field to display instead.<br />
</p>]]></description>
         <link>http://www.evilfree.com/adam/blog/2005/11/drilling_down_into_the_data.html</link>
         <guid>http://www.evilfree.com/adam/blog/2005/11/drilling_down_into_the_data.html</guid>
         <category>Flex</category>
         <pubDate>Mon, 28 Nov 2005 18:40:41 -0500</pubDate>
      </item>
            <item>
         <title>Where are the trace statements?</title>
         <description><![CDATA[<p>This probably belongs under the "to embarrassed to mention" category, but I will post it anyway.</p>

<p>One of the first things I did after installing Flex was to try to get the trace method working.  I love trace and have found it invaluable when I learning a language.  I can do some quick runs to test my syntax or understanding of a piece of code.  And of course you can keep an eye on your program to make sure everything is working as you expect.</p>

<p>The <a href="http://labs.macromedia.com/wiki/index.php/ActionScript_3:resources:FAQ#Can_I_still_use_Trace_in_ActionScript_3.0.3F">FAQ</a> on the labs wiki has a nice little note informing you that you must import the trace package before the method can be used..</p>

<p>Ok, no problem.  I create a new ActionScript project that looks like this:<br />
<code><br />
package {<br />
  import flash.display.MovieClip;<br />
  import flash.util.trace;<br />
	<br />
  public class traceTest extends MovieClip {<br />
    public function traceTest() {<br />
      trace("Its nice to see you!");<br />
    }<br />
  }<br />
}<br />
</code></p>

<p><br />
I then hit the green run button at the top of Flex interface.  A few seconds later my browser pops up with an empty Flex background.  No trace on the browser so I flip back to Flex, and nothing is there either.  I see a nice little console window tab that would be an ideal place to show me my trace statements, but it says "A console is not available."</p>

<p>So I head to google and start searching for Action 3.0 trace.  I find tons of information all telling me that I need to import the trace package before I can use the command.  I know this.   Finally, I found a note on a blog that let me know you need to view your program in debug mode to see your trace statements.  You can do this by right clicking in the CODE (in case you are tracing from a Flex app) view and selecting "Debug As -> Flex Application".   </p>

<p>With that tasty bit of knowledge I was able to see my trusty trace statements!</p>

<p>I imagine this would be obvious to many people (particularly Eclipse users) but it took a good bit of my time to figure it out.  It does make sense that it works this way... now that I know about it.</p>

<p>Does anyone know of a MoveableType plugin that will let markup ActionScript and/or MXML with "code"  tag or something similar?</p>]]></description>
         <link>http://www.evilfree.com/adam/blog/2005/11/where_are_your_trace_statement_1.html</link>
         <guid>http://www.evilfree.com/adam/blog/2005/11/where_are_your_trace_statement_1.html</guid>
         <category>Actionscript 3.0</category>
         <pubDate>Tue, 22 Nov 2005 16:37:08 -0500</pubDate>
      </item>
            <item>
         <title>Learning Flex</title>
         <description><![CDATA[<p>Like many people in the community I have been following the development of Zorn and was excited about the pricing level and the release of an Alpha version to play around with.</p>

<p>I need to create a tool to edit an XML file and save it back again.  Luckily I don't have a hard deadline to complete the tool within, so it’s an ideal project to begin learning Flex with.  I find it easier to learn something new with a specific goal in mind.</p>

<p>So between my other work (mostly Flash and Director) I've decided to start tackling Flex.   It was easy enough to go through the quick start tutorials and the sample browser (great tool).   Amazing how much functionality you get with so little code.</p>

<p>However, once I exhausted these resources and tried to do something that wasn't a derivative implementation of the samples I quickly began to hit walls.  I haven't used earlier versions of Flex and it is lot to wrap your head around.  Because it’s an alpha most of the documentation and tutorials are still being developed and some of the source code in the help documents won't even compile... perfectly understandable, but still frustrating.  The <a href="http://livedocs.macromedia.com/labs/1/flex/langref/index.html">language reference</a> is extremely useful and does a good job of listings the "massive" amounts of properties and methods available, but doesn't explain when and how to use them.</p>

<p>So, I’ll post little things I discover and questions I have here.  Hopefully other people that are also trying to learn Flex will find them helpful.  </p>]]></description>
         <link>http://www.evilfree.com/adam/blog/2005/11/learning_flex.html</link>
         <guid>http://www.evilfree.com/adam/blog/2005/11/learning_flex.html</guid>
         <category>Thoughts</category>
         <pubDate>Tue, 22 Nov 2005 11:34:21 -0500</pubDate>
      </item>
      
   </channel>
</rss>
