<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Fraser Crosbie - Calgary Flash, Flex &#38; Web Developer &#187; Learning</title>
	<atom:link href="http://www.flashdev.ca/article/tag/learning/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.flashdev.ca</link>
	<description>Web developer specializing in rich internet applications. Located in Calgary, Alberta, Canada</description>
	<lastBuildDate>Thu, 09 Jun 2011 17:47:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Flex 3 Cookbook Review</title>
		<link>http://www.flashdev.ca/article/flex-3-cookbook-review/</link>
		<comments>http://www.flashdev.ca/article/flex-3-cookbook-review/#comments</comments>
		<pubDate>Fri, 05 Sep 2008 05:36:54 +0000</pubDate>
		<dc:creator>Fraser Crosbie</dc:creator>
				<category><![CDATA[Book Review]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Review]]></category>

		<guid isPermaLink="false">http://www.flashdev.ca/?p=62</guid>
		<description><![CDATA[I just finished skimming through this book and have decided that every Flex developer should own a copy. I have been developing Flex applications for over a year now and I still managed to learn a ton of new things from this book. The authors have done an excellent job of formatting the book into [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://oreilly.com/catalog/9780596529857/?CMP=ILC-search_spot1&#038;ATT=FLEX_Flex3Cookbook"><img src="http://www.flashdev.ca/wp-content/uploads/2008/09/9780596529857_cat1.gif" alt="" title="9780596529857_cat1" width="180" height="236" class="alignnone size-medium wp-image-63" /></a></p>
<p>I just finished skimming through this book and have decided that every Flex developer should own a copy. I have been developing Flex applications for over a year now and I still managed to learn a ton of new things from this book. The authors have done an excellent job of formatting the book into problem and solution scenarios. Quick and easy answers. The book starts off with issues a Flex noob might encounter and then proceeds all the way up to issues a Flex pro might encounter. Each solution includes code and a discussion/explination. This book is not really a cover to cover read,  but more of a quick reference that you want to have within an arms reach while coding. I still recommend skimming through it when you first get it, because I&#8217;m sure you&#8217;ll learn a bunch of new tidbits right off the bat.</p>
<p>You can get more info and purchase this book <a href="http://oreilly.com/catalog/9780596529857/?CMP=ILC-search_spot1&#038;ATT=FLEX_Flex3Cookbook">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashdev.ca/article/flex-3-cookbook-review/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A must-read for learning ActionScript 3.0</title>
		<link>http://www.flashdev.ca/article/a-must-read-for-learning-actionscript-30/</link>
		<comments>http://www.flashdev.ca/article/a-must-read-for-learning-actionscript-30/#comments</comments>
		<pubDate>Mon, 01 Oct 2007 17:34:33 +0000</pubDate>
		<dc:creator>Fraser Crosbie</dc:creator>
				<category><![CDATA[ActionScript 3.0 Tutorial]]></category>
		<category><![CDATA[Flash Development]]></category>
		<category><![CDATA[Components]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Open-Source]]></category>

		<guid isPermaLink="false">http://www.flashdev.ca/article/a-must-read-for-learning-actionscript-30/</guid>
		<description><![CDATA[I just stumbled across a great article by Josh Tynjala on the Yahoo! Flash Developer Center. Josh writes about the new features of ActionScript 3.0, focusing on working with the Display List, changes to root and parent, and encapsulation. I&#8217;m sure this article has been around for some time, but if you are just getting [...]]]></description>
			<content:encoded><![CDATA[<p>I just stumbled across a great article by Josh Tynjala on the Yahoo! Flash Developer Center. Josh writes about the new features of ActionScript 3.0, focusing on working with the Display List, changes to root and parent, and encapsulation. I&#8217;m sure this article has been around for some time, but if you are just getting into AS3 and have not yet seen this article, then I highly recommend you read it.</p>
<p><a href="http://developer.yahoo.com/flash/articles/display-list.html">http://developer.yahoo.com/flash/articles/display-list.html</a></p>
<p>The Yahoo! Flash Developer Center also has some great open-source components available for download. I am playing around with the Charts and I am very impressed. These seem like a great and free alternative to <a href="http://www.fusioncharts.com/">FusionCharts</a>, which at this time are not available for ActionScript 3.0.</p>
<p>Here are some examples of the Yahoo! ASTRA Charts:<br />
<a href="http://developer.yahoo.com/flash/astra-flash/charts/examples.html">http://developer.yahoo.com/flash/astra-flash/charts/examples.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashdev.ca/article/a-must-read-for-learning-actionscript-30/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Loading and Saving External XML Data in AIR (Apollo)</title>
		<link>http://www.flashdev.ca/article/loading-and-saving-xml-data-in-air-apollo/</link>
		<comments>http://www.flashdev.ca/article/loading-and-saving-xml-data-in-air-apollo/#comments</comments>
		<pubDate>Tue, 03 Jul 2007 22:59:31 +0000</pubDate>
		<dc:creator>Fraser Crosbie</dc:creator>
				<category><![CDATA[ActionScript 3.0 Tutorial]]></category>
		<category><![CDATA[AIR (Apollo) Tutorial]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[Apollo]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.flashdev.ca/article/loading-and-saving-xml-data-in-air-apollo/</guid>
		<description><![CDATA[I just finished an AIR (Apollo) application that loads and saves data from an external XML file. I figured I would share the code to accomplish this task as there is not a lot of Apollo info around at this time. First off lets start with loading an XML file and reading its contents. I [...]]]></description>
			<content:encoded><![CDATA[<p>I just finished an AIR (Apollo) application that loads and saves data from an external XML file. I figured I would share the code to accomplish this task as there is not a lot of Apollo info around at this time.</p>
<p>First off lets start with loading an XML file and reading its contents. I realize that there are much easier ways to load XML into Flash than this, but the advantage here is that I can use <em>File.applicationResourceDirectory</em> which allows me to target the installation directory for the XML file that was included with the AIR package. In this snippet I am using the synchronous open method.  This essentially pauses everything else in the Flash movie until it has completed its task (opening the file).</p>
<p><span id="more-47"></span></p>
<pre>
<code>
import flash.filesystem.*;

private var _data:String; // Data string pulled from the xml file.

/**
 * Load the xml file and read its data.
 */
private function loadData():void
{
  var dataFile:File = File.applicationResourceDirectory.resolve("data.xml");
  var stream:FileStream = new FileStream();
  stream.open(dataFile, FileMode.READ);
  _data = stream.readUTFBytes(stream.bytesAvailable);
  stream.close();
}
</code>
</pre>
<p>This next snippet shows how to save data to a file using the asynchronous openAsync method. The asynchronous methods allow Flash to continue running normally and use events to trigger user specified actions.</p>
<pre>
<code>
private var _dataXML:XML;	// The XML data.

/**
 * Save the modified data to the xml file.
 */
private function saveData():void
{
  var dataFile:File = File.applicationResourceDirectory.resolve("data.xml");
  var stream:FileStream = new FileStream();
  stream.openAsync(dataFile, FileMode.WRITE);
  stream.writeUTFBytes(_dataXML);
  stream.addEventListener(Event.CLOSE, onDataSaved);
  stream.close();
}

/**
 * Called when the data has been successfully saved.
 * Load the saved data back into the application.
 */
private function onDataSaved(event:Event):void
{
  loadData();
}
</code>
</pre>
<p>If you are planning on using AIR (Apollo) for your own projects I would highly recommend reading <a href="http://download.macromedia.com/pub/labs/apollo/documentation/apollo_for_flex_pocketguide_031907.pdf">Apollo for Adobe Flex Developers Pocket Guide</a> by Mike Chambers, Robert L. Dixon &#038; Jeff Swartz.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashdev.ca/article/loading-and-saving-xml-data-in-air-apollo/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>O&#8217;Reilly Excerpts Now On ActionScript.org</title>
		<link>http://www.flashdev.ca/article/oreilly-excerpts-now-on-actionscriptorg/</link>
		<comments>http://www.flashdev.ca/article/oreilly-excerpts-now-on-actionscriptorg/#comments</comments>
		<pubDate>Thu, 18 Jan 2007 06:20:35 +0000</pubDate>
		<dc:creator>Fraser Crosbie</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Redesign]]></category>

		<guid isPermaLink="false">http://www.flashdev.ca/article/oreilly-excerpts-now-on-actionscriptorg/</guid>
		<description><![CDATA[Earlier today I received a news letter from ActionScript.org. This threw me off for a second because the only emails I get from them are job postings. The email template was well done and mimics their new site redesign, which is quite nice compared to their old outdated design. If you have already forgotten what [...]]]></description>
			<content:encoded><![CDATA[<p>Earlier today I received a news letter from ActionScript.org. This threw me off for a second because the only emails I get from them are job postings. The email template was well done and mimics their new site redesign, which is quite nice compared to their old outdated design. If you have already forgotten what it looked like, you can kind of make it out <a href="http://web.archive.org/web/20060526174539/http://www.actionscript.org/">here</a> using the <a href="http://www.archive.org/web/web.php">Wayback Machine</a>.</p>
<p>I am currently in the process of reading the excerpt from Tom Muck&#8217;s Flash Remoting: The Definitive Guide. This excerpt is part of a new partnership between ActionScript.org and O&#8217;Reilly. It seems like a good deal for both sides. I am sure this will drive a lot more traffic to ActionScript.org and inevitably lead to more book sales for O&#8217;Reilly. So far the first few pages of the excerpt have been very well written and quite informative. </p>
<p>While reading the article I have realized that I will have to change my job title. Now that Flex has been released I am no longer a Flash Developer, but instead, a Client-Side ActionScript Programmer. I think that this is a much more dynamic sounding title, but it will take some getting used to after referring to myself as a Flash Developer for so long.</p>
<p>I am quite excited about the freshened up ActionScript.org site and enjoy having the ability to preview books before investing in them. Of course O&#8217;Reilly is one of my favorite publishers, so this is good news to me.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashdev.ca/article/oreilly-excerpts-now-on-actionscriptorg/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Building a Basic Menu in ActionScript 3.0 Tutorial &#8211; Part 2 &#8211; XML</title>
		<link>http://www.flashdev.ca/article/building-a-basic-menu-in-actionscript-30-tutorial-part-2-xml/</link>
		<comments>http://www.flashdev.ca/article/building-a-basic-menu-in-actionscript-30-tutorial-part-2-xml/#comments</comments>
		<pubDate>Tue, 19 Sep 2006 20:08:22 +0000</pubDate>
		<dc:creator>Fraser Crosbie</dc:creator>
				<category><![CDATA[ActionScript 3.0 Tutorial]]></category>
		<category><![CDATA[Flash Development]]></category>
		<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[E4X]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.flashdev.ca/?p=27</guid>
		<description><![CDATA[A few posts ago, I showed you how to build a basic menu using an Array of button names. Now, I will demonstrate how to build the same menu, but this time use the new XML class which is based on E4X. There are many benefits of using XML in your applications. The main reason [...]]]></description>
			<content:encoded><![CDATA[<p>A few posts ago, I showed you how to build a basic menu using an Array of button names. Now, I will demonstrate how to build the same menu, but this time use the new XML class which is based on E4X. There are many benefits of using XML in your applications. The main reason being that it allows you to update your application instantly without having to open up Flash to republish it. XML also allows your application to be easily updated from a server side page that generates XML output. This opens up the possibility of using a CMS to modify your application, thus enabling your clients to make updates on their own. Almost every project I develop uses XML.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_basicMenuXML_443622143"
			class="flashmovie"
			width="438"
			height="56">
	<param name="movie" value="http://www.flashdev.ca/flash/basicMenuXML.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.flashdev.ca/flash/basicMenuXML.swf"
			name="fm_basicMenuXML_443622143"
			width="438"
			height="56">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>And now for the code:</p>
<p><span id="more-27"></span></p>
<pre>
package ca.flashdev.example {		

  import flash.display.Sprite;
  import flash.display.Shape;
  import flash.events.MouseEvent;
  import flash.text.TextField;
  import flash.text.TextFieldAutoSize;
  import flash.text.TextFormat;
  import flash.net.URLLoader
  import flash.net.URLRequest
  import flash.xml.XML
  import flash.events.Event;
  import flash.error.Error;

  public class BasicMenuXML extends Sprite {		

    // Create an XML list to hold the buttons.
    private var __menuList:XMLList;	 

    // External file loader.
    private var __loader:URLLoader;

    /**
     * The constructor. This method is fired
     * automatically when the class is instantiated.
     */
    public function BasicMenuXML():void {
      loadXML();
    }

    /**
     * Load the XML.
     */
    private function loadXML():void {			

      // Create a URL loader.
      __loader = new URLLoader();

      // Attach a listener to the loader.
      __loader.addEventListener(Event.COMPLETE, onXMLLoaded);

      // Load the xml file.
      __loader.load(new URLRequest("menu.xml"));
    }

    /**
     * Called when the XML has been loaded.
     * @param   event   The event that called this method.
     */
    private function onXMLLoaded(event:Event):void {

      // Put some error catching in case the XML is malformed.
      try {

        // Load the data into the XML object.
        var menuXML:XML = new XML(__loader.data);

        // Create a list of the buttons.
        __menuList = menuXML.button; 

        // Now that the XML is loaded create the menu.
        drawMenu();	

      } catch(error:Error) {

        // Display an error message.
        var errorMessage:TextField = new TextField();
        errorMessage.autoSize = TextFieldAutoSize.LEFT;
        errorMessage.textColor = 0xFF0000;
        errorMessage.text = error.message;
        addChild(errorMessage);
        return;
      }
    }

    /**
     * Draw the menu.
     */
    private function drawMenu():void {

      // This variable will hold the x position for the next button.
      var xPos:Number = 0;

      // Create a holder that will contain the menu.
      var menuHolder:Sprite = new Sprite();

      // Add the holder to the stage.
      addChild(menuHolder);			

      // Create text formatting for the text fields in the menu.
      var format:TextFormat = new TextFormat();
      format.font = "Verdana";
      format.color = 0x000000;
      format.size = 12;
      format.bold = true;

      // Loop through the list and create each button in the list.
      var count:int = 0;
      for each (p in __menuList) {

        // Create the button.
        var button:Sprite = new Sprite();
        button.name = "button"+count;

        // Disable the mouse events of objects inside the button.
        button.mouseChildren = false;

        // Make the sprite behave as a button.
        button.buttonMode = true;

        // Create the label for the down button state.
        var label:TextField = new TextField();
        label.autoSize = TextFieldAutoSize.LEFT;
        label.selectable = false;
        label.defaultTextFormat = format;
        label.text = __menuList[count].text();

        // Create a up state for the button.
        var up:Sprite = new Sprite();
        up.graphics.lineStyle(1, 0x000000);
        up.graphics.beginFill(0x00FF00);
        up.graphics.drawRect(0, 0, 100, 30);
        up.name = "up";

        // Create a over state for the button.
        var over:Sprite = new Sprite();
        over.graphics.lineStyle(1, 0x000000);
        over.graphics.beginFill(0xFFCC00);
        over.graphics.drawRect(0, 0, 100, 30);
        over.name = "over";

        // Adder the states and label to the button.
        button.addChild(up);
        button.addChild(over);
        button.addChild(label);				

        // Position the text in the center of the button.
        label.x = (button.width/2) - (label.width/2);
        label.y = (button.height/2) - (label.height/2);

        // Add mouse events to the button.
        button.addEventListener(MouseEvent.MOUSE_OVER,
                                  displayActiveState);
        button.addEventListener(MouseEvent.MOUSE_OUT,
                                  displayInactiveState);
        button.addEventListener(MouseEvent.CLICK, displayMessage);

        // Add the button to the holder.
        menuHolder.addChild(button);

        // Position the button.
        button.x = xPos;

        // Increase the x position for the next button.
        xPos += button.width + 2;

        // Hide the over state of the button.
        over.alpha = 0;

        // Increase the count.
        count++;
      }

      // Postion The Menu.
      menuHolder.x = 20;
      menuHolder.y = 20;

    }

    /**
     * Show the active state of the button.
     */
    private function displayActiveState(event:MouseEvent):void {

      // Hide the over state of the button.
      event.currentTarget.getChildByName("over").alpha = 100;
    }

    /**
     * Hide the active state of the button.
     */
    private function displayInactiveState(event:MouseEvent):void {

      // Show the over state of the button.
      event.currentTarget.getChildByName("over").alpha = 0;
    }

    /**
     * Display a message in the Output window.
     */
    private function displayMessage(event:MouseEvent):void {

      // Output the name of the clicked button.
      trace(event.currentTarget.name)
    }
  }
}
</pre>
<p>Save this file as <em>BasicMenuXML.as</em> in a folder structure of <em>ca.flashdev.example</em>.<br />
Create a new movie and add <em>ca.flashdev.example.BasicMenuXML</em> to the ActionScript 3.0 Settings Document class field. Save this file as <em>basicMenuXML.fla</em> in the same directory as your <em>ca</em> folder. Publish (Ctrl+Enter) your movie and you should see the menu.</p>
<p><a id="p29" href="http://www.flashdev.ca/wp-content/uploads/2006/09/BasicMenuXML.zip">Download the source files</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashdev.ca/article/building-a-basic-menu-in-actionscript-30-tutorial-part-2-xml/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>O&#8217;Reilly Code Search</title>
		<link>http://www.flashdev.ca/article/oreilly-code-search/</link>
		<comments>http://www.flashdev.ca/article/oreilly-code-search/#comments</comments>
		<pubDate>Sun, 10 Sep 2006 17:45:52 +0000</pubDate>
		<dc:creator>Fraser Crosbie</dc:creator>
				<category><![CDATA[Flash Development]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Learning]]></category>

		<guid isPermaLink="false">http://www.flashdev.ca/?p=24</guid>
		<description><![CDATA[O&#8217;Reilly&#8217;s has recently launched a search engine that will scour through nearly 700 of their books, including over 123,000 individual examples, composed of 2.6 million lines of code. I think O&#8217;Reilly has published around 21 ActionScript related books at this time. http://labs.oreilly.com/code/]]></description>
			<content:encoded><![CDATA[<p>O&#8217;Reilly&#8217;s has recently launched a search engine that will scour through nearly 700 of their books, including over 123,000 individual examples, composed of 2.6 million lines of code. I think O&#8217;Reilly has published around 21 ActionScript related books at this time.</p>
<p><a href="http://labs.oreilly.com/code/">http://labs.oreilly.com/code/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashdev.ca/article/oreilly-code-search/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building a Basic Menu in ActionScript 3.0 Tutorial &#8211; Part 1 &#8211; Array</title>
		<link>http://www.flashdev.ca/article/building-a-basic-menu-in-actionscript-30-tutorial/</link>
		<comments>http://www.flashdev.ca/article/building-a-basic-menu-in-actionscript-30-tutorial/#comments</comments>
		<pubDate>Thu, 07 Sep 2006 07:19:01 +0000</pubDate>
		<dc:creator>Fraser Crosbie</dc:creator>
				<category><![CDATA[ActionScript 3.0 Tutorial]]></category>
		<category><![CDATA[Flash Development]]></category>
		<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.flashdev.ca/?p=22</guid>
		<description><![CDATA[Today I have decided to build a simple ActionScript 3.0 horizontal menu based on an array. This is a fairly common practice in Flash development as we are often using data provided from a XML file to dynamically update content within our movies. To simplify this tutorial I am going to use an array that [...]]]></description>
			<content:encoded><![CDATA[<p>Today I have decided to build a simple ActionScript 3.0 horizontal menu based on an array. This is a fairly common practice in Flash development as we are often using data provided from a XML file to dynamically update content within our movies. To simplify this tutorial I am going to use an array that is written within my code instead of parsing it from a XML file. </p>
<p>The following example will demonstrate how to loop through an array and draw a button for each item in that array. Each button will have a label, an up state and an over state. I have read that it is good practice to use the SimbleButton object whenever possible, but I am not going to use the it in this tutorial because I am interested in learning more about <em>addChild()</em>, <em>getChildByName()</em>, <em>currentTarget</em>, <em>mouseChildren</em> and other features of ActionScript 3.0 that could be avoided using the SimpleButton. </p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_basicMenu_1058532944"
			class="flashmovie"
			width="438"
			height="56">
	<param name="movie" value="http://www.flashdev.ca/flash/basicMenu.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.flashdev.ca/flash/basicMenu.swf"
			name="fm_basicMenu_1058532944"
			width="438"
			height="56">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p><span id="more-22"></span></p>
<pre>
package ca.flashdev.example {		

  import flash.display.Sprite;
  import flash.display.Shape;
  import flash.events.MouseEvent;
  import flash.text.TextField;
  import flash.text.TextFieldAutoSize;
  import flash.text.TextFormat;

  public class BasicMenu extends Sprite {		

    // Create the array of button names.
    private var __MenuArray:Array = new Array("Button 0",
                                              "Button 1",
                                              "Button 2",
                                              "Button 3",
                                              "Button 4");		 

    /**
     * The constructor. This method is fired automatically
     * when the class is instantiated.
     */
    public function BasicMenu():void {
      drawMenu();
    }

    /**
    * Draw the menu.
    */
    private function drawMenu():void {

      // This variable will hold the x position
      // of the next button in the menu.
      var xPos:Number = 0;

      // Create a holder that will contain the menu.
      var menuHolder:Sprite = new Sprite();

      // Add the holder to the stage.
      addChild(menuHolder);			

      // Create text formatting for the text fields in the menu.
      var format:TextFormat = new TextFormat();
      format.font = "Verdana";
      format.color = 0x000000;
      format.size = 12;
      format.bold = true;

      // Loop through the array.
      //Create each item listed in the array.
      for (var i in __MenuArray) {

        // Create the button.
        var button:Sprite = new Sprite();
        button.name = "button"+i;

        // Disable the mouse events of all the
        // objects within the button.
        button.mouseChildren = false;

        // Make the sprite behave as a button.
        button.buttonMode = true;

        // Create the label for the down button state.
        var label:TextField = new TextField();
        label.autoSize = TextFieldAutoSize.LEFT;
        label.selectable = false;
        label.defaultTextFormat = format;
        label.text = __MenuArray[i];

        // Create an up state for the button.
        var up:Sprite = new Sprite();
        up.graphics.lineStyle(1, 0x000000);
        up.graphics.beginFill(0x00FF00);
        up.graphics.drawRect(0, 0, 100, 30);
        up.name = "up";

        // Create an over state for the button.
        var over:Sprite = new Sprite();
        over.graphics.lineStyle(1, 0x000000);
        over.graphics.beginFill(0xFFCC00);
        over.graphics.drawRect(0, 0, 100, 30);
        over.name = "over";

        // Adder the states and label to the button.
        button.addChild(up);
        button.addChild(over);
        button.addChild(label);				

        // Position the text in the center of the button.
        label.x = (button.width/2) - (label.width/2);
        label.y = (button.height/2) - (label.height/2);

        // Add mouse events to the button.
        button.addEventListener(MouseEvent.MOUSE_OVER,
                                displayActiveState);
        button.addEventListener(MouseEvent.MOUSE_OUT,
                                displayInactiveState);
        button.addEventListener(MouseEvent.CLICK,
                                displayMessage);

        // Add the button to the holder.
        menuHolder.addChild(button);

        // Position the button.
        button.x = xPos;

        // Increase the x position for the next button.
        xPos += button.width + 2;

        // Hide the over state of the button.
        over.alpha = 0;
      }

      // Postion The Menu.
      menuHolder.x = 20;
      menuHolder.y = 20;

    }

    /**
     * Show the active state of the button.
     */
    private function displayActiveState(event:MouseEvent):void {

      // Show the over state of the button.
      event.currentTarget.getChildByName("over").alpha = 100;
    }

    /**
    * Hide the active state of the button.
    */
    private function displayInactiveState(event:MouseEvent):void {

      // Hide the over state of the button.
      event.currentTarget.getChildByName("over").alpha = 0;
    }

    /**
     * Display a message in the Output window.
     */
    private function displayMessage(event:MouseEvent):void {

      // Output the name of the clicked button.
      trace(event.currentTarget.name)
    }
  }
}
</pre>
<p>Save this file as <em>BasicMenu.as</em> in a folder structure of <em>ca.flashdev.example</em>.<br />
Create a new movie and add <em>ca.flashdev.example.BasicMenu</em> to the ActionScript 3.0 Settings Document class field. Save this file as <em>basicMenu.fla</em> in the same directory as your <em>ca</em> folder. Publish (Ctrl+Enter) your movie and you should see the menu.</p>
<p><a href="http://www.flashdev.ca/wp-content/uploads/2006/09/BasicMenu.zip">Download the source files</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashdev.ca/article/building-a-basic-menu-in-actionscript-30-tutorial/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>SimpleButton and Events in ActionScript 3.0 Tutorial</title>
		<link>http://www.flashdev.ca/article/simplebutton-and-events-in-as3/</link>
		<comments>http://www.flashdev.ca/article/simplebutton-and-events-in-as3/#comments</comments>
		<pubDate>Wed, 02 Aug 2006 18:16:02 +0000</pubDate>
		<dc:creator>Fraser Crosbie</dc:creator>
				<category><![CDATA[ActionScript 3.0 Tutorial]]></category>
		<category><![CDATA[Flash Development]]></category>
		<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.flashdev.ca/?p=17</guid>
		<description><![CDATA[In AS3, one of the most significant changes was to make the EventDispatch class the standard tool for calling events. This is a huge step in ActionScript as code written by different developers will become a lot more similar. In the following example I will demonstrate how to use addEventListener to add a click event [...]]]></description>
			<content:encoded><![CDATA[<p>In AS3, one of the most significant changes was to make the <em>EventDispatch</em> class the standard tool for calling events. This is a huge step in ActionScript as code written by different developers will become a lot more similar.</p>
<p>In the following example I will demonstrate how to use <em>addEventListener</em> to add a click event to a button that is built using the new <em>SimpleButton</em> object. The SimpleButton is a light weight alternative to the heavier MovieClip object. </p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_button_1112414871"
			class="flashmovie"
			width="120"
			height="50">
	<param name="movie" value="http://www.flashdev.ca/flash/button.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.flashdev.ca/flash/button.swf"
			name="fm_button_1112414871"
			width="120"
			height="50">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p><span id="more-17"></span></p>
<pre>
package ca.flashdev.example {		

  import flash.display.Sprite;
  import flash.display.Shape;
  import flash.display.SimpleButton;
  import flash.events.MouseEvent;
  import flash.events.Event;

  public class ButtonTrace extends Sprite {		

    private var __button:SimpleButton = new SimpleButton();

    public function ButtonTrace():void {
      drawButton();
      activateButton();
    }

    private function drawButton():void {

      var down:Sprite = new Sprite();
      down.graphics.lineStyle(1, 0x000000);
      down.graphics.beginFill(0xFFCC00);
      down.graphics.drawRect(10, 10, 100, 30);

      var up:Sprite = new Sprite();
      up.graphics.lineStyle(1, 0x000000);
      up.graphics.beginFill(0x0099FF);
      up.graphics.drawRect(10, 10, 100, 30);

      var over:Sprite = new Sprite();
      over.graphics.lineStyle(1, 0x000000);
      over.graphics.beginFill(0x9966FF);
      over.graphics.drawRect(10, 10, 100, 30);

      __button.upState = up;
      __button.overState = over;
      __button.downState = down;
      __button.useHandCursor = true;
      __button.hitTestState = up;

      addChild(__button);
    }

    private function activateButton():void {
      __button.addEventListener(MouseEvent.CLICK, displayMessage);
    }

    private function displayMessage(e:Event):void {
      trace("Don't push my buttons!");
    }
  }
}
</pre>
<p>Save this file as <em>ButtonTrace.as</em> in a folder structure of <em>ca.flashdev.example</em>.<br />
Create a new movie and add <em>ca.flashdev.example.ButtonTrace</em> to the ActionScript 3.0 Settings Document class field. Save this file as <em>button.fla</em> in the same directory as your <em>ca</em> folder. Publish (Ctrl+Enter) your movie and you should see a button that you can click.</p>
<p><a href="http://www.flashdev.ca/wp-content/uploads/2006/08/Button.zip">Download the source files</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashdev.ca/article/simplebutton-and-events-in-as3/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Drawing Shapes in ActionScript 3.0 Tutorial</title>
		<link>http://www.flashdev.ca/article/drawing-shapes-in-actionscript-3/</link>
		<comments>http://www.flashdev.ca/article/drawing-shapes-in-actionscript-3/#comments</comments>
		<pubDate>Fri, 28 Jul 2006 16:34:07 +0000</pubDate>
		<dc:creator>Fraser Crosbie</dc:creator>
				<category><![CDATA[ActionScript 3.0 Tutorial]]></category>
		<category><![CDATA[Flash Development]]></category>
		<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Drawing]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.flashdev.ca/?p=15</guid>
		<description><![CDATA[ActionScript 3.0 has some great new functions to simplify drawing shapes. Previously in ActionScript 2.0 you had to specify each point in a shape and draw lines between them. Now, you can use drawCircle, drawEllipse, drawRect &#038; drawRoundRect to speed up the process. 
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_drawShapes_1040801508"
			class="flashmovie"
			width="330"
			height="150">
	<param name="movie" value="http://www.flashdev.ca/flash/drawShapes.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.flashdev.ca/flash/drawShapes.swf"
			name="fm_drawShapes_1040801508"
			width="330"
			height="150">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object> Lets take a look at how it [...]]]></description>
			<content:encoded><![CDATA[<p>ActionScript 3.0 has some great new functions to simplify drawing shapes. Previously in ActionScript 2.0 you had to specify each point in a shape and draw lines between them. Now, you can use drawCircle, drawEllipse, drawRect &#038; drawRoundRect to speed up the process. </p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_drawShapes_1316538394"
			class="flashmovie"
			width="330"
			height="150">
	<param name="movie" value="http://www.flashdev.ca/flash/drawShapes.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.flashdev.ca/flash/drawShapes.swf"
			name="fm_drawShapes_1316538394"
			width="330"
			height="150">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>Lets take a look at how it is done:</p>
<p><span id="more-15"></span></p>
<pre>
package ca.flashdev.drawing {
  import flash.display.Sprite;
    public class DrawShapes extends Sprite {
      function DrawShapes():void {
        createCircle(50, 50, 25, 0x0099FF)
        createEllipse(100, 25, 50, 100, 0x9933CC)
        createRect(175, 25, 50, 100, 0xFFCC00)
        createRoundRect(250, 25, 50, 100, 20, 20, 0xFF3366)
      }
      public function createCircle(x:Number,
                                   y:Number,
                                   radius:Number,
                                   color:Number):void {
        var circle:Sprite = new Sprite();
        circle.graphics.beginFill(color);
        circle.graphics.drawCircle(x, y, radius);
        circle.graphics.endFill();
        addChild(circle);
      }
      public function createEllipse(x:Number,
                                    y:Number,
                                    width:Number,
                                    height:Number,
                                    color:Number):void {
        var ellipse:Sprite = new Sprite();
        ellipse.graphics.beginFill(color);
        ellipse.graphics.drawEllipse(x, y, width, height);
        ellipse.graphics.endFill();
        addChild(ellipse);
      }
      public function createRect(x:Number,
                                 y:Number,
                                 width:Number,
                                 height:Number,
                                 color:Number):void {
        var rect:Sprite = new Sprite();
        rect.graphics.beginFill(color);
        rect.graphics.drawRect(x, y, width, height);
        rect.graphics.endFill();
        addChild(rect);
      }
      public function createRoundRect(x:Number,
                                      y:Number,
                                      width:Number,
                                      height:Number,
                                      ellipseWidth:Number,
                                      ellipseHeight:Number,
                                      color:Number):void {
        var roundRect:Sprite = new Sprite();
        roundRect.graphics.beginFill(color);
        roundRect.graphics.drawRoundRect(x,
                                         y,
                                         width,
                                         height,
                                         ellipseWidth,
                                         ellipseHeight);
        roundRect.graphics.endFill();
        addChild(roundRect);
    }
  }
}
</pre>
<p>Add this code to a new actionScript file and save it as <em>DrawShapes.as</em> in a folder structure of <em>ca.flashdev.drawing</em>. </p>
<p>Now create a new movie in Flash and open the <em>Publish Settings (Ctrl+Shift+F12)</em> window. Click on the <em>Flash</em> tab, then on the <em>settings</em> button. In the <em>Document class:</em> field insert <em>ca.flashdev.drawing.DrawShapes</em>. <em>Test Movie (Ctrl+Enter)</em> and voila, you have shapes.</p>
<p>You will notice I am extending the <em>Sprite</em> object. Here is an explanation of what a Sprite is:</p>
<p><em>&#8220;The Sprite class is a basic display list building block: a display list node that can display graphics and can also contain children.<br />
A Sprite object is similar to a movie clip, but does not have a timeline. Sprite is an appropriate base class for objects that do not require timelines. For example, Sprite would be a logical base class for user interface (UI) components that typically do not use the timeline. The Sprite class is new in ActionScript 3.0. It provides an alternative to the functionality of the MovieClip class, which retains all the functionality of previous ActionScript releases to provide backward compatibility.&#8221;</em><br />
- ActionScript 3.0 Language Reference</p>
<p>If you previously coded in AS2 you will also notice the <em>addChild</em> function. Depth management has changed in AS3. In AS2 we would have used <em>getNextHighestDepth</em> in the same function that we are creating our object with. Now in AS3 we use <em>addChild</em> after our object is created, to add our object to the next highest depth, or <em>addChildAt</em> to specify a specific depth.</p>
<p><a href="http://www.flashdev.ca/wp-content/uploads/2006/07/drawShapes.zip">Download the source files</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashdev.ca/article/drawing-shapes-in-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>ActionScript 3.0 Document Class Tutorial</title>
		<link>http://www.flashdev.ca/article/document-class/</link>
		<comments>http://www.flashdev.ca/article/document-class/#comments</comments>
		<pubDate>Fri, 28 Jul 2006 16:01:51 +0000</pubDate>
		<dc:creator>Fraser Crosbie</dc:creator>
				<category><![CDATA[ActionScript 3.0 Tutorial]]></category>
		<category><![CDATA[Flash Development]]></category>
		<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.flashdev.ca/?p=14</guid>
		<description><![CDATA[Well, it appears that in my previous posts about ActionScript 3.0, I am a bit old school. I have been instantiating my code from the first frame of the timeline using the import statement. After opening up a few of the as3_labs_samples_062706 and realizing that there is no code on the timeline, just a disclaimer, [...]]]></description>
			<content:encoded><![CDATA[<p>Well, it appears that in my previous posts about ActionScript 3.0, I am a bit old school. I have been instantiating my code from the first frame of the timeline using the <em>import</em> statement. After opening up a few of the <a href="http://download.macromedia.com/pub/labs/flash9as3/as3_labs_samples_062706.zip">as3_labs_samples_062706</a> and realizing that there is no code on the timeline, just a disclaimer, I started to scratch my head. I checked the library of the .fla to see if I could see any linkages. Still, I could not find any reference to the external code. The next place I checked was the <em>Publish Settings (Ctrl-Shift+F12)</em> and lo and behold, I found my answer. If you click on the <em>Flash</em> tab, then on the <em>settings&#8230;</em> button you will see the new <em>Document class:</em> field. Using this field you can instantiate your code. This is a much cleaner way of doing things. Finally a Flash Developer&#8217;s dream come true, no more code on the timeline.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashdev.ca/article/document-class/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Debugging in ActionScript 3.0 &#8211; Part 2 &#8211; Objects Tutorial</title>
		<link>http://www.flashdev.ca/article/trace-objects/</link>
		<comments>http://www.flashdev.ca/article/trace-objects/#comments</comments>
		<pubDate>Wed, 26 Jul 2006 17:53:01 +0000</pubDate>
		<dc:creator>Fraser Crosbie</dc:creator>
				<category><![CDATA[ActionScript 3.0 Tutorial]]></category>
		<category><![CDATA[Flash Development]]></category>
		<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.flashdev.ca/?p=10</guid>
		<description><![CDATA[Last post I talked about using trace in order to debug variables in Flash. As I mentioned before, trace works great for Strings and Numbers, but not so good for Objects &#038; Arrays. Tracing an Object will return [object Object], which does not tell you much. To see the insides of an Object you can [...]]]></description>
			<content:encoded><![CDATA[<p>Last post I talked about using <em>trace</em> in order to debug variables in Flash. As I mentioned before, trace works great for <em>Strings</em> and <em>Numbers</em>, but not so good for <em>Objects</em> &#038; <em>Arrays</em>. Tracing an Object will return <em>[object Object]</em>, which does not tell you much. To see the insides of an Object you can use a <em>for</em>    loop. Add the following code to a new actionScript file called <em>ObjectDebug.as</em>:</p>
<p><span id="more-10"></span></p>
<pre>
package ca.flashdev.debug {
  public class ObjectDebug {
    public function traceObject(myObj:Object) {
      trace("Using a regular trace: " + myObj);
      trace("");
      trace("Using a for loop: ");
      for (var i in myObj) {
        trace(i + ' = ' + myObj[i]);
      }
    }
  }
}
</pre>
<p>Save this file in a folder structure of <em>ca\flashdev\debug</em>.</p>
<p>Create a new movie named <em>traceObject.fla</em> and add the following code to the first frame of the timeline:</p>
<pre>
import ca.flashdev.debug.ObjectDebug;
var classInstance:ObjectDebug = new ObjectDebug();
var myObj:Object = new Object();
myObj.firstName = "Fraser";
myObj.lastName = "Crosbie";
myObj.occupation = "Flash Developer";
classInstance.traceObject(myObj);
</pre>
<p>Save this file into the same directory as the <em>ca</em> folder and <em>Test Movie (Ctrl+Enter)</em>.<br />
The results in your Output window should be:</p>
<pre>
Using a regular trace: [object Object]  

Using a for loop:
firstName = Fraser
lastName = Crosbie
occupation = Flash Developer
</pre>
<p>In AS2 I would recommend using the <em>ObjectDumper</em> to trace the insides of an Object, but it appears that they have yet to write AS3 versions of the <em>mx</em> classes.</p>
<p><a id="p12" href="http://www.flashdev.ca/wp-content/uploads/2006/07/traceObject.zip">Download the source files</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashdev.ca/article/trace-objects/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

