<?xml version="1.0" encoding="UTF-8"?>
<!--Generated by Squarespace V5 Site Server v5.13.166 (http://www.squarespace.com) on Thu, 20 Jun 2013 11:20:00 GMT--><feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/"><title>Ramblings</title><subtitle>Ramblings</subtitle><id>http://ramblingdeveloper.com/ramblings/</id><link rel="alternate" type="application/xhtml+xml" href="http://ramblingdeveloper.com/ramblings/"/><link rel="self" type="application/atom+xml" href="http://ramblingdeveloper.com/ramblings/atom.xml"/><updated>2012-09-04T18:28:32Z</updated><generator uri="http://five.squarespace.com/" version="Squarespace V5 Site Server v5.13.166 (http://www.squarespace.com)">Squarespace</generator><entry><title>Double Click Enabled Flex Spark DataGrid Example</title><category term="CookBooks"/><category term="DataGrid"/><category term="Examples"/><category term="Flex"/><category term="Spark"/><category term="example"/><id>http://ramblingdeveloper.com/ramblings/2012/9/2/double-click-enabled-flex-spark-datagrid-example.html</id><link rel="alternate" type="text/html" href="http://ramblingdeveloper.com/ramblings/2012/9/2/double-click-enabled-flex-spark-datagrid-example.html"/><author><name>Mike Roberts</name></author><published>2012-09-03T01:26:02Z</published><updated>2012-09-03T01:26:02Z</updated><content type="html" xml:lang="en-US"><![CDATA[<p>Enabling the double click property on a Spark DataGrid is very simple except for one simple gotcha.</p>
<p>First, the obvious: In order to make a spark datagrid double clickable, you need to set the property doubleClickEnabled to "true".</p>
<p>Next, the part that always trips me up, is that you need to set the editable attribute on the datagrid to "true". &nbsp;This will allow you to double click one of the default text item renderers and edit the text within the data grid cell. &nbsp;View a the sample data grid code below:</p>
<pre class="brush: xml">
<s:DataGrid id="personDataGrid" editable="true" doubleClickEnabled="true" dataProvider="{new XMLListCollection(namesXML.children())}">
  <s:columns>
    <s:ArrayList>
      <s:GridColumn headerText="Name" dataField="@name"/>
      <s:GridColumn headerText="Role" dataField="@role"/>
      <s:GridColumn headerText="Movie" dataField="@movie"/>
    </s:ArrayList>
  </s:columns>
</s:DataGrid>
</pre>
<p>With these two attributes you can allow double click editing of any cell in a Flex Spark DataGrid.</p>
<p>An example of this is shown below. &nbsp;You can right click the example to view the source.</p>
<iframe src="http://ramblingdeveloper.com/storage/flex-examples/doubleclicksparkdatagridexample/DoubleClickToEditDataGridExample.html" width="300" height="250">
 <p>Your browser does not support iframes.</p>
 </iframe>]]></content></entry><entry><title>Getting Selected Values of a Flex List of Checkboxes</title><category term="CheckBox"/><category term="CookBooks"/><category term="Examples"/><category term="Flex"/><category term="List"/><category term="Spark"/><category term="XML"/><category term="tutorial"/><id>http://ramblingdeveloper.com/ramblings/2012/8/29/getting-selected-values-of-a-flex-list-of-checkboxes.html</id><link rel="alternate" type="text/html" href="http://ramblingdeveloper.com/ramblings/2012/8/29/getting-selected-values-of-a-flex-list-of-checkboxes.html"/><author><name>Mike Roberts</name></author><published>2012-08-30T01:41:44Z</published><updated>2012-08-30T01:41:44Z</updated><content type="html" xml:lang="en-US"><![CDATA[<p>This example will be a continuation of the post <a href="http://ramblingdeveloper.com/ramblings/2011/9/24/creating-a-flex-spark-list-of-checkbox-bound-to-xml-dataprov.html">"Creating A Flex Spark List of Checkbox Bound To XML DataProvider</a>". &nbsp;If you have not read that tutorial and are not sure how to create a List of Checkboxes form XML, please see that tutorial first.</p>
<p>Now, we will need to do severals things to know the selected value of our list items:</p>
<ul>
<li>Add a "selected" attribute for each person in our XML dataprovider</li>
<li>Update the checkbox in the itemrenderer so that it is selected only when the dataprovider's "selected" attribute is "true"</li>
<li>Add a method to update the dataprovider for the itemrenderer</li>
<li>Add a method to setup an EventListener to be notified of changes to the dataprovider</li>
<li>Add a method to extract the current selected values from the dataprovider</li>
</ul>
<p>So, first, we need to add the "selected" attribute to our dataprovider elements. &nbsp;That is done quite simply as you can see below:</p>
<p><pre class="brush: xml">
<fx:XML id="namesXML" format="e4x">
  <people>
    <person name="Leon" selected="false"/>
    <person name="Mathilda" selected="false"/>
    <person name="Stansfield" selected="false"/>
    <person name="Benny" selected="false"/>
  </people>
</fx:XML>
</pre></p>
<p>Next, we need to update the definition of the checkbox so that it shows a checkmark only when the dataprovider's "selected" attribute is true. &nbsp;We'll also need to update the checkbox definition to call a method called onCheckboxChange when the checkbox sends a "change" event.&nbsp; We can see that definition here:</p>
<p><pre class="brush: xml">
<s:CheckBox id="checkBox"
label="{data.@name}"
change="onCheckboxChange(event)"
selected="{data.@selected=='true'}"/>
</pre></p>
<p>In order for that selected attibute to update in the dataprovider when the user clicks it we need to add the&nbsp;onCheckboxChange method seen in the definition above. &nbsp;This method will set the "selected" attribute to true when the checkbox is checked and false when the checkbox is not checked. &nbsp;Simple, right? &nbsp;You can see the method here:</p>
<p><pre class="brush: as3">
protected function onCheckboxChange(changeEvent:Event):void{
  //When the checkbox changes update the data provider's "selected" attribute
  data.@selected = checkBox.selected ? "true" : "false";
}
</pre></p>
<p>Ok. &nbsp;Now we are almost there. &nbsp;Next, in our applicaton file, we need to create two methods. The first will be onCreationComplete, which will fire when the application has been created (note: this method is triggered by the application definition with the code creationComplete="onCreationComplete()"). &nbsp;This method will populate a variable called "personDataProvider" which is the dataProvider to our list. &nbsp;Then we will add an EventListener to the personDataProvider that listens to CollectionChange events so we know when a user is selected or unselected. &nbsp;The method is below:</p>
<p><pre class="brush: as3">
protected function onCreationComplete():void{
  //Initialize the dataprovider
  personDataProvider = new XMLListCollection(namesXML.children());
  //Add a listener so we know when the dataprovider is updated
  personDataProvider.addEventListener(CollectionEvent.COLLECTION_CHANGE, onListChange);
}
</pre></p>
<p>Finally, we simply need to create the final method which is called every time the personDataProvider is updated. &nbsp;This method simply loops over all of the person elements in our list, finds which people are selected, and then adds their names to a text element. &nbsp;See the code here:</p>
<p><pre class="brush: as3">
protected function onListChange(changeEvent:Event):void{
  //Clear the selected person text since we'll be building it here
  selectedPersonText.text = "Selected People:";
  for each (var personXML:XML in personDataProvider) {
    //Add all selected person names to our text component
    if(personXML.@selected=="true"){
      //Add the person's name to the text component
      selectedPersonText.text += " " + personXML.@name
    }
  }
}
</pre></p>
<p>That's it! &nbsp;We now have a way of finding out which people are selected in our checkbox list. &nbsp;See the example below (you can see the source code by right clicking on the example application):</p>
<iframe src="http://ramblingdeveloper.com/storage/flex-examples/selectedcheckboxesexample/SelectedCheckboxes.swf" width="300" height="250">
 <p>Your browser does not support iframes.</p>
 </iframe>]]></content></entry><entry><title>Flex Tree with variable height item renderers</title><category term="CookBooks"/><category term="Examples"/><category term="Flex"/><category term="Tree"/><category term="example"/><category term="item renderer"/><id>http://ramblingdeveloper.com/ramblings/2012/8/17/flex-tree-with-variable-height-item-renderers.html</id><link rel="alternate" type="text/html" href="http://ramblingdeveloper.com/ramblings/2012/8/17/flex-tree-with-variable-height-item-renderers.html"/><author><name>Mike Roberts</name></author><published>2012-08-18T02:44:05Z</published><updated>2012-08-18T02:44:05Z</updated><content type="html" xml:lang="en-US"><![CDATA[<p>Creating a Flex Tree with variable height rows can be mysteriously difficult if you are new to Flex item renderers.&nbsp; This cookbook will give you the step by step instructions to creating a Tree control with variable height renderers.</p>
<p>First you will need to define your tree component:
</p>
<p><pre class="brush: xml">&lt;mx:Tree itemRenderer="{new ClassFactory(CustomTreeItemRenderer)}"
&nbsp;&nbsp;&nbsp; labelField="@name"
&nbsp;&nbsp;&nbsp; showRoot="false"
&nbsp;&nbsp;&nbsp; variableRowHeight="true"
&nbsp;&nbsp;&nbsp; width="200"
&nbsp;&nbsp;&nbsp; height="350"&gt;
&nbsp;&nbsp;&lt;mx:XMLListCollection id="Characters"&gt;
&nbsp;&nbsp;&nbsp;&lt;mx:XMLList&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;movie&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;main name="Leon" height="25"&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;sub name="Mathilda" height="50"/&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;sub name="Tony" height="75"/&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/main&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;main name="Stansfield" height="50"&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;sub name="Benny" height="100"/&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/main&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/movie&gt;
&nbsp;&nbsp;&nbsp;&lt;/mx:XMLList&gt;
&nbsp;&nbsp;&lt;/mx:XMLListCollection&gt;
&nbsp;&lt;/mx:Tree&gt;</pre></p>
<p>Notice that the tree control has the attribute "variableRowHeight" set to true.&nbsp; This is very important since it will allow all of the rows to be a different height.&nbsp; We also set our data provider to have names which will be used as our renderer's label and heights which will be used to resize each renderer.</p>
<p>The next most important attribute here is the "itemRenderer" which is defined as&nbsp;new ClassFactory(CustomTreeItemRenderer).&nbsp; This means that we will be using a component called the CustomTreeItemRenderer as our itemRenderer.</p>
<p>Now, we must create the CustomTreeItemRenderer.&nbsp; This will extend the TreeItemRenderer and will override two methods:</p>
<p>
<ul>
<li>measure</li>
<li>updateDisplayList</li>
</ul>
</p>
<p>The measure method simply measures all of the components within the renderer and sets their heights and widths.&nbsp; Below we can see what our code must do:</p>
<p><pre class="brush: as3">override protected function measure():void{
    super.measure();
    //Check to make sure the data is initialized
    if(data && data.@height > 0){
        this.measuredHeight = data.@height;
    }
}</pre></p>
<p>Above, you can see that the code is simply setting the measuredHeight of our renderer to the height that&nbsp;was defined in our tree's data provider above.&nbsp; The @ sign in from of the height attribute is used since we are extracting data from our XML based dataprovider rather than an Object based dataprovider.</p>
<p>Now, that the height is set, we need to override the updateDisplayList method so that we can correctly layout out newly resized component.</p>
<p><pre class="brush: as3">override protected function updateDisplayList(unscaledWidth:Number,
													  unscaledHeight:Number):void{
    super.updateDisplayList(unscaledWidth, unscaledHeight);
    //Check to make sure the data is initialized
    if(data && data.@height > 0){
        //put the label at the correct y coordinate based on the height
        label.y = (data.@height / 2) - (label.measuredHeight /2);
    }
}</pre></p>
<p>We can see in the code above, that we are setting the label's y coordinate based on the new height of the renderer.&nbsp; This is necessary in order to vertically align our label within the new larger renderer.
<p>That's it.&nbsp; We now have Flex Tree with variable height rows!
<p>See the sample below which will allow you to download the source by right clicking:
<p><iframe src="http://mikejuly24.squarespace.com/storage/flex-examples/variableheighttreeitemsexample/VariableHeightTreeItems.html" width="300" height="400">
 <p>Your browser does not support iframes.</p>
 </iframe>
FYHD72V6F4PN]]></content></entry><entry><title>Apache Flex getting the Falcon compiler</title><category term="Apache"/><category term="Apache Community"/><category term="Compiler"/><category term="Falcon"/><category term="Flex"/><id>http://ramblingdeveloper.com/ramblings/2012/8/17/apache-flex-getting-the-falcon-compiler.html</id><link rel="alternate" type="text/html" href="http://ramblingdeveloper.com/ramblings/2012/8/17/apache-flex-getting-the-falcon-compiler.html"/><author><name>Mike Roberts</name></author><published>2012-08-17T18:41:07Z</published><updated>2012-08-17T18:41:07Z</updated><summary type="html" xml:lang="en-US"><![CDATA[Adobe will be donating the Falcon Compiler to the Apache Flex project which promises speed improvements and improved code syntax checking for IDEs.]]></summary></entry><entry><title>Apache Flex to use Git</title><category term="Apache"/><category term="Apache Community"/><category term="Flex"/><category term="Git"/><category term="SVN"/><id>http://ramblingdeveloper.com/ramblings/2012/8/16/apache-flex-to-use-git.html</id><link rel="alternate" type="text/html" href="http://ramblingdeveloper.com/ramblings/2012/8/16/apache-flex-to-use-git.html"/><author><name>Mike Roberts</name></author><published>2012-08-16T18:24:39Z</published><updated>2012-08-16T18:24:39Z</updated><summary type="html" xml:lang="en-US"><![CDATA[In a very interesting vote, the Apache Flex decision makers show support for the community by changing their minds and switching to Git as their SCM.]]></summary></entry><entry><title>Removing Grid Lines from Spark DataGrid Skin</title><category term="CookBooks"/><category term="DataGrid"/><category term="Examples"/><category term="Flex"/><category term="GridLine"/><category term="Skin"/><category term="Spark"/><id>http://ramblingdeveloper.com/ramblings/2011/10/15/removing-grid-lines-from-spark-datagrid-skin.html</id><link rel="alternate" type="text/html" href="http://ramblingdeveloper.com/ramblings/2011/10/15/removing-grid-lines-from-spark-datagrid-skin.html"/><author><name>Mike Roberts</name></author><published>2011-10-15T04:21:01Z</published><updated>2011-10-15T04:21:01Z</updated><content type="html" xml:lang="en-US"><![CDATA[<p>Creating a datagrid with no column or row seperator lines is just a matter of creating a new DataGrid skin and applying it to the DataGrid.</p>
<p>The first thing to do is to create a new MXML class (BlankDataGridSkin.mxml) which extends the spark "DataGridSkin" class. &nbsp;Essentially, we'll be extending the basic DataGridSkin and overriding two components:</p>
<p>1. columnSeparator</p>
<p>2. &nbsp;rowSeparator</p>
<p>The code to override those two components follows:</p>
<p><pre class="brush: xml">&lt;spark:DataGridSkin xmlns:fx="http://ns.adobe.com/mxml/2009"
           xmlns:s="library://ns.adobe.com/flex/spark"
           xmlns:spark="spark.skins.spark.*"&gt;
  &lt;fx:Declarations&gt;
    &lt;fx:Component id="columnSeparator"&gt;
      &lt;s:Line/&gt;
    &lt;/fx:Component&gt;
    &lt;fx:Component id="rowSeparator"&gt;
      &lt;s:Line/&gt;
    &lt;/fx:Component&gt;
  &lt;/fx:Declarations&gt;
&lt;/spark:DataGridSkin&gt;</pre></p>
<p>Pretty simple, right? &nbsp;If we wanted to change the appearance of the seperators all we would need to do is change around what is drawn by the components. &nbsp;For instance, if we wanted red seperator lines we could write components like this:</p>
<p><pre class="brush: xml">&lt;fx:Component id="columnSeparator"&gt;
  &lt;s:Line&gt;
    &lt;s:stroke&gt;
      &lt;s:SolidColorStroke color="0xFF0000" weight="1" caps="square" alpha="1"/&gt;
    &lt;/s:stroke&gt;
  &lt;/s:Line&gt;
&lt;/fx:Component&gt;
&lt;fx:Component id="rowSeparator"&gt;
  &lt;s:Line&gt;
    &lt;s:stroke&gt;
      &lt;s:SolidColorStroke color="0xFF0000" weight="1" caps="square" alpha="1"/&gt;
    &lt;/s:stroke&gt;
  &lt;/s:Line&gt;
&lt;/fx:Component&gt;</pre></p>
<p>Now, how do we apply our new skin? &nbsp;Thankfully, that's pretty simple too. &nbsp;All we need to do is define our new class as the&nbsp;skinClass of a DataGrid. &nbsp;That code looks like this:</p>
<p><pre class="brush: xml">&lt;s:DataGrid skinClass="BlankDataGridSkin"&gt;
  &lt;s:columns&gt;
    &lt;s:ArrayCollection&gt;
      &lt;s:GridColumn headerText="Header 1" width="200"/&gt;
      &lt;s:GridColumn headerText="Header 2" width="200"/&gt;
      &lt;s:GridColumn headerText="Header 3" width="200"/&gt;
    &lt;/s:ArrayCollection&gt;
  &lt;/s:columns&gt;
&lt;/s:DataGrid&gt;</pre></p>
<p>That's pretty much everything. &nbsp;Now you should have a datagrid where you can completely define what the seperators look like.</p>
<p>Below, you can see an example of the DataGrid with no seperator lines with view source right click enabled.</p>
<iframe src="http://ramblingdeveloper.com/storage/flex-examples/datagridseperatorexample/DataGridSkinningExample.html" width="550" height="300">
 <p>Your browser does not support iframes.</p>
 </iframe>]]></content></entry><entry><title>Styling an Alert in Flex 4</title><category term="Alert"/><category term="CookBooks"/><category term="Examples"/><category term="Flex"/><category term="Skin"/><category term="Spark"/><category term="Style"/><id>http://ramblingdeveloper.com/ramblings/2011/10/10/styling-an-alert-in-flex-4.html</id><link rel="alternate" type="text/html" href="http://ramblingdeveloper.com/ramblings/2011/10/10/styling-an-alert-in-flex-4.html"/><author><name>Mike Roberts</name></author><published>2011-10-10T23:41:33Z</published><updated>2011-10-10T23:41:33Z</updated><content type="html" xml:lang="en-US"><![CDATA[<p>There is a cookbook request on <a href="http://cookbooks.adobe.com/post_How_i_implement_skin_or_apply_the_CSS_on_Alert_in-18577.html">Adobe Cookbooks</a> requesting information on how to style an Alert in Flex 4. &nbsp;So naturally, we'll be discussing that here topic.</p>
<p>The truth is, styling an Alert in Flex 4 is almost exactly the same as styling an Alert in Flex 3 since Alert is still just a Halo component. &nbsp;Rather simply, we'll just need to define a style tag (could also be defined in a CSS file) within our application to change the style of an Alert. &nbsp;Here's a brief example of a Style tag which will give an Alert a yellow/red theme:</p>
<p><pre class="brush: xml">&lt;fx:Style&gt;
  @namespace mx "library://ns.adobe.com/flex/mx";
  mx|Alert{
    borderColor: red;
    backgroundColor: yellow;
    dropShadowVisible: true;
    chromeColor: red;
    titleStyleName: alertTitle;
    messageStyleName: alertMessage;
    buttonStyleName: alertButton;
  }
  .alertTitle{
    fontSize: 20;
    fontWeight: bold;
    color: yellow;
  }
  .alertMessage {
    fontWeight: bold;
    color: red;
  }
  .alertButton {
    color: yellow;
  }
&lt;/fx:Style&gt;</pre></p>
<p>Notice we're defining an "mx|Alert" section which is selecting the mx:Alert class to apply styles. &nbsp;Within that section we are referencing other named styles such as alertTitle, alertMessage and alertButton which are logically named.</p>
<p>That's pretty much all we need to do. &nbsp;Now when we create an Alert, it will have an unsightly red/yellow theme applied to it's text, borders and chrome!</p>
<p>See below for a demo with view source enabled in the right click menu:</p>
<iframe src="http://ramblingdeveloper.com/storage/flex-examples/alertstyleexample/StyleAlertExample.html" width="400" height="300">
 <p>Your browser does not support iframes.</p>
 </iframe>]]></content></entry><entry><title>Flex Spark Radar Chart Cookbook</title><category term="CookBooks"/><category term="Examples"/><category term="Flex"/><category term="Radar Chart"/><category term="Spark"/><category term="example"/><category term="tutorial"/><id>http://ramblingdeveloper.com/ramblings/2011/10/8/flex-spark-radar-chart-cookbook.html</id><link rel="alternate" type="text/html" href="http://ramblingdeveloper.com/ramblings/2011/10/8/flex-spark-radar-chart-cookbook.html"/><author><name>Mike Roberts</name></author><published>2011-10-08T22:11:04Z</published><updated>2011-10-08T22:11:04Z</updated><content type="html" xml:lang="en-US"><![CDATA[<p>Here, I will be going over how we can make a custom Radar/Spider/Kiviat Chart for use within Flex applications since it is not included in the Flex charting components out of the box. &nbsp;We'll be seeing a couple of rather out of the ordinary things here: drawing graphics and using trigonometric functions to determine layout.</p>
<p>So, first things first, we'll need to define a few data classes we'll be using to store the information about our Radar chart. &nbsp;What are the things you think for charts? &nbsp;Simple: Axes, Series and Values within the series. &nbsp;So those are the first classes we'll define: Axis, Series and SeriesAxisValue.</p>
<p>First up, is the Axis:</p>
<p><pre class="brush: as3">public class Axis
{
  public var name:String;
  public var numberOfTicks:Number;
  public var tickMultiplier:Number;
}</pre></p>
<p>Pretty simple class, right? &nbsp;All we are doing is creating a place where we can store the name of our Axis, the numberOfTicks to display on the Axis and the&nbsp;tickMultiplier to determine the value for each consecutive tick mark. &nbsp;For instance, if&nbsp;tickMultiplier was set to 5, the first tick mark would have a value of 5, the second tick mark a value of 10 and so on.</p>
<p>Next we need to define the data we need for a Series:</p>
<p><pre class="brush: as3">public class Series
{
  public var name:String;
  public var color:uint;
  public var values:Vector.&lt;SeriesAxisValue&gt; = new Vector.&lt;SeriesAxisValue&gt;();
 
  public function getAxisValue(axisName:String):Number{
    for each(var seriesAxisValue:SeriesAxisValue in values){
      if(seriesAxisValue.axis.name == axisName)
        return seriesAxisValue.value;
    }
    return 0;
  }
 
  public function getAxis(axisName:String):Axis{
    for each(var seriesAxisValue:SeriesAxisValue in values){
      if(seriesAxisValue.axis.name == axisName)
        return seriesAxisValue.axis;
    }
    return null;
  }
 
  public function addAxisValue(axis:Axis, value:Number):void{
    var seriesAxisValue:SeriesAxisValue = new SeriesAxisValue();
    seriesAxisValue.axis = axis;
    seriesAxisValue.value = value;
    values.push(seriesAxisValue);
  }
}</pre></p>
<p>In this class, we are storing the name of the series, the color of the series, and the value of the Series for each Axis. &nbsp;In addition we have a few convenience methods.</p>
<ul>
<li>getAxisValue - Gets the value of this series by Axis name, &nbsp;so we know where the series is going to intersect the axis.</li>
<li>getAxis - Simply returns an Axis object based on the name passed in</li>
<li>addAxisValue - Sets the value of this series by Axis,&nbsp;so we know where the series is going to intersect the axis.</li>
</ul>
<p>We see in the Series Class above that we are making reference to a SeriesAxisValue object. &nbsp;That object looks like so:</p>
<p><pre class="brush: as3">public class SeriesAxisValue
 {
 public var axis:Axis;
 public var value:Number;
 }</pre></p>
<p>This is the simplest class so far. &nbsp;All we are doing is storing an Axis and a value so that we can quickly determine what value we need to draw from what axis.</p>
<p>Now, on to the meat of this cookbook: the actual chart. &nbsp;Since the charting class is a few hundred lines long I will hit upon the important points of this class and leave the full source enabled on the example. &nbsp;This class, called RadarChart, which extends UIComponent accomplishes a few tasks:</p>
<ul>
<li>Drawing out the Axes along the correct angles</li>
<li>Drawing out the tick marks and values upon the axis</li>
<li>Drawing out the series to interset each axis at the desired value</li>
</ul>
<p>All of these actions will be performed as a result of the updateDisplayList method being called. &nbsp;Here is that method:</p>
<p><pre class="brush: as3">protected override function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
  if(redraw){
    redraw = false;
    //Set needed properties for the drawing process
    _middle = new Point(unscaledWidth/2, unscaledHeight/2);
    _radius = (Math.min(unscaledWidth, unscaledHeight)/2);
    _axisLabelSpacerSize = isNaN(getStyle("axisLabelSpacerSize")) ? 0 : getStyle("axisLabelSpacerSize");
 
    //Draw the background and border of this chart
    var g:Graphics = graphics;
    g.clear();
    g.beginFill(getStyle("backgroundColor"), getStyle("backgroundAlpha"));
    g.lineStyle(getStyle('borderThickness'), getStyle('borderColor'), getStyle('borderAlpha'));
    g.drawRect(0, 0, unscaledWidth - getStyle('borderThickness'), unscaledHeight - getStyle('borderThickness'));
    g.endFill();
 
    //Draw center dot of the chart
    g.beginFill(getStyle("centerColor"), getStyle("centerAlpha"));
    g.lineStyle(0);
    g.drawCircle(_middle.x, _middle.y, getStyle("centerRadius"));
    g.endFill();
 
    //Draw the axes and series to complete the chart
    drawAxes();
    drawSeries();
  }
  super.updateDisplayList(unscaledWidth, unscaledHeight);
}</pre></p>
<p>The first thing this method is doing is setting some class variables so that they can be used throughout our drawing methods. &nbsp;We are setting:</p>
<ul>
<li>_middle - &nbsp;A point representing the exact middle of our chart which has an x value of half of the width and a y value of half of the height. &nbsp;This assumes our chart will be a square.</li>
<li>_radius - A number representing radius of our chart, or simply half of the height or width of the chart.</li>
<li>_axisLabelSpacerSize - A number representing how much space we will need to leave between the end of our axes and the edge of the component to fit our axis names. &nbsp;This is determined by a style set on the component.</li>
</ul>
<p>Next, since we're using a UIComponent and aren't satisfied with plain white backgrounds, we need to draw a background to our component. &nbsp;To do that we follow the operations:</p>
<ul>
<li>Get the graphics object</li>
<li>Setup a fill using the&nbsp;backgroundColor and&nbsp;backgroundAlpha styles</li>
<li>Setup a lineStyle to be used as a border using the&nbsp;borderThickness, borderColor, and borderAlpha styles</li>
<li>Draw a rectangle around the component which will have our background and border.</li>
</ul>
<p>Next, we need to draw the center dot on our radar chart. &nbsp;We follow similar steps abouve of defining our fill, setting the linestyle and then drawing a circle in the middle of the component.</p>
<p>Lastly, we invoke drawAxes() which, clearly, will draw the axes nad drawSeries() which will draw the Series. &nbsp;First, let's look at draw axes:</p>
<p><pre class="brush: as3">private function drawAxes():void {
  var axisAngle:Number = (2*Math.PI) / _axes.length;
  var angle:Number = 0;
 
  for each(var axis:Axis in _axes) {
    var start:Point = new Point(
      _middle.x + Math.cos(angle) * 3,
      _middle.y + Math.sin(angle) * getStyle("centerRadius")
    );
 
    var stop:Point = new Point(
      _middle.x + Math.cos(angle) * (_radius - _axisLabelSpacerSize),
      _middle.y + Math.sin(angle) * (_radius - _axisLabelSpacerSize)
    );
 
    drawAxis(start, stop);
    addAxisLabel(axis, angle);
 
    drawTickMarks(angle, axis.numberOfTicks, axis.tickMultiplier);
    angle += axisAngle;
  }
}</pre></p>
<p>Let's walk through this method. &nbsp; We determine an axisAngle which is the angle between each axis and then we set our starting angle to 0. &nbsp;We then loop over each axis and determine it's start point form the center and it's stop point which is the end of the axis(this uses a bit of trigonometry like radius, angle, sine and cosine. &nbsp;I won't give a Math lesson here.). &nbsp;These are the points we'll use to draw our complete axes. &nbsp;The draw axes method simply uses the graphics object to draw a line between the points similar to how we were drawing rectangles and circles above.</p>
<p>The addAxisLabel method is rather lengthy for the simple task it accomplishes, so I'll only explain it's purpose here and let you view the full source for more details. &nbsp;The&nbsp;addAxisLabel method use some more trigonometry to find a point which is at the end of the axis, but adjusted so that the label is centered and right-side-up. &nbsp;Is uses the "name" attribute on the axis to populate the label.</p>
<p>The drawTickMarks method is also rather lengthy so I will only explain it's purpose here and let you view the full source for more details. &nbsp;drawTickMarks uses trig yet again to find points on the axis for each tick mark to be drawn. &nbsp;The tick mark length style is then used to determine how long a line and at what angle it will need to be drawn on the axis.</p>
<p>Now we have our Axes drawn! &nbsp;Now we need to move on to the drawSeries method to complete our chart. &nbsp;It's a bit simpler than drawing the axes:</p>
<p><pre class="brush: as3">private function drawSeries():void{
  for each(var series:Series in _series){
    drawSeriesPoints(series);
    drawSeriesFill(series);
  }
}</pre></p>
<p>Here, we're looping over all of our series and drawing points correxponding to each SeriesAxisValue and then drawing a fill polygon to connect the points with lines and fill in the area in between with a slightly shaded region. &nbsp;We'll only look at the drawSeriesPoints method since these methods are interacting with data similarly:</p>
<p><pre class="brush: as3">private function drawSeriesPoints(series:Series):void{
  var axisAngle:Number = (2*Math.PI) / _axes.length;
  var angle:Number = 0;
  var g:Graphics = graphics;
  g.lineStyle(2, series.color, 1);
  g.beginFill(series.color, .4);
  for each(var axis:Axis in _axes) {
    var seriesAxisValue:Number = series.getAxisValue(axis.name);
    var point:Point = new Point(
      _middle.x + Math.cos(angle) * (_radius - _axisLabelSpacerSize) * seriesAxisValue/axis.numberOfTicks/axis.tickMultiplier,
      _middle.y + Math.sin(angle) * (_radius - _axisLabelSpacerSize) * seriesAxisValue/axis.numberOfTicks/axis.tickMultiplier
    );
    g.drawCircle(point.x, point.y, 3);
    angle += axisAngle;
  }
}</pre></p>
<p>Above, we are first getting the angle between all of our axes and then setting out starting angle to zero. &nbsp;We then initialize a line and fill so that we may use it to draw circles at each point we determine. &nbsp;To determine those points, we loop over each axis, get the series value for that axis and determine the point using trig and our value. &nbsp;Once we have that point we draw a circle there, end the fill to fill in the circle and move on to the next axis.</p>
<p>After all of the points are drawn, the&nbsp;drawSeriesFill method would be called to draw lines between the points and fill in the enclosed area.</p>
<p>With all of the methods I've shown and described in this class and a little boilerplate skeleton code to hold it all together (viewable in 'view source' on the demo below) you should have a fully functional rader chart component. &nbsp;Now we just need to see how we can use it in flex mxml:</p>
<p><pre class="brush: xml">&lt;local:RadarChart width="400" height="400" backgroundColor="0xEEEEEE" borderColor="0x000000" borderThickness="2"
 backgroundAlpha="1" centerColor="0x000000" centerRadius="3" centerAlpha="1" axisLabelSpacerSize="50"
 tickMarkLength="10" tickMarkColor="0x000000" tickMarkAlpha="1"&gt;
  &lt;local:axes&gt;
    &lt;fx:Vector type="Axis"&gt;
      &lt;local:Axis id="axis1" name="Axis 1" numberOfTicks="10" tickMultiplier="1"/&gt;
      &lt;local:Axis id="axis2" name="Axis 2" numberOfTicks="10" tickMultiplier="1"/&gt;
      &lt;local:Axis id="axis3" name="Axis 3" numberOfTicks="10" tickMultiplier="1"/&gt;
    &lt;/fx:Vector&gt;
  &lt;/local:axes&gt;
  &lt;local:series&gt;
    &lt;fx:Vector type="Series"&gt;
      &lt;local:Series color="0xFF0000"&gt;
        &lt;local:values&gt;
          &lt;local:SeriesAxisValue value="1" axis="{axis1}"/&gt;
          &lt;local:SeriesAxisValue value="9" axis="{axis2}"/&gt;
          &lt;local:SeriesAxisValue value="7" axis="{axis3}"/&gt;
        &lt;/local:values&gt;
      &lt;/local:Series&gt;
      &lt;local:Series color="0x00FF00"&gt;
        &lt;local:values&gt;
          &lt;local:SeriesAxisValue value="7" axis="{axis1}"/&gt;
          &lt;local:SeriesAxisValue value="3" axis="{axis2}"/&gt;
          &lt;local:SeriesAxisValue value="5" axis="{axis3}"/&gt;
        &lt;/local:values&gt;
      &lt;/local:Series&gt;
      &lt;local:Series color="0x0000FF"&gt;
        &lt;local:values&gt;
          &lt;local:SeriesAxisValue value="4" axis="{axis1}"/&gt;
          &lt;local:SeriesAxisValue value="7" axis="{axis2}"/&gt;
          &lt;local:SeriesAxisValue value="4" axis="{axis3}"/&gt;
        &lt;/local:values&gt;
      &lt;/local:Series&gt;
    &lt;/fx:Vector&gt;
  &lt;/local:series&gt;
&nbsp;&lt;/local:RadarChart&gt;</pre></p>
<p>Above we see a few things:</p>
<ul>
<li>We define a RaderChart component which defines most of the styles that we saw utlized in our drawing code.</li>
<li>We define a list of Axes where each defines its name, numberOfTicks and TickMultiplier.</li>
<li>We define a list of series where each have a color and a list of SeriesAxisValues containing references to the Axes and values.</li>
</ul>
<p>That's it! &nbsp;With that we have defined a RadarChart component and invoked it!</p>
<p>Below, you can see a demo utlizing this code and the full source by right clicking the demo and selecting "View Source".</p>
<p>&nbsp;</p>
<ul>
</ul>
<iframe src="http://ramblingdeveloper.com/storage/flex-examples/radarchartexample/bin-release/RadarChartExample.html" width="400" height="800">
 <p>Your browser does not support iframes.</p>
 </iframe>]]></content></entry><entry><title>Flex Spark Radar Chart Cookbook</title><category term="Flex"/><category term="Radar Chart"/><category term="Spark"/><id>http://ramblingdeveloper.com/ramblings/2011/9/29/flex-spark-radar-chart-cookbook.html</id><link rel="alternate" type="text/html" href="http://ramblingdeveloper.com/ramblings/2011/9/29/flex-spark-radar-chart-cookbook.html"/><author><name>Mike Roberts</name></author><published>2011-09-30T03:12:25Z</published><updated>2011-09-30T03:12:25Z</updated><content type="html" xml:lang="en-US"><![CDATA[<p>I think I'll take a stab at creating a radar chart to fulfil the <a href="http://cookbooks.adobe.com/post_I_want_to_create_a_simple_radar_chart_in_Flash_Bui-17921.html">request at Adobe Cookbooks</a> asking for a simple radar chart example.</p>
<p>I imagine that this will have very little to do with Flex libraries and Spark components and more to do with just drawing graphics.</p>
<p>Look for a follow up post in the coming days.</p>]]></content></entry><entry><title>Flex Halo Accordion resizeToContent Attribute</title><category term="Accordion"/><category term="Examples"/><category term="Flex"/><category term="Halo"/><category term="resizeToContent"/><id>http://ramblingdeveloper.com/ramblings/2011/9/29/flex-halo-accordion-resizetocontent-attribute.html</id><link rel="alternate" type="text/html" href="http://ramblingdeveloper.com/ramblings/2011/9/29/flex-halo-accordion-resizetocontent-attribute.html"/><author><name>Mike Roberts</name></author><published>2011-09-30T02:04:29Z</published><updated>2011-09-30T02:04:29Z</updated><content type="html" xml:lang="en-US"><![CDATA[<p>I spent a bunch of time today trying to get a mx:Accordion to respect my width="100%" and height="100%" parameters. &nbsp;Little did I know that I needed to set the resizeToContent attribute to 'true' in order for the Accordion to update its sizing when content is added to it.</p>
<p>Here's what the definition would look like this:</p>
<p>&lt;mx:Accordion width="100%" height="100%" resizeToContent="true"&gt;</p>
<p>I hope this saves someone just a little bit of time when trying to get their Accordion to resize properly.</p>]]></content></entry></feed>