<?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; Tutorial</title>
	<atom:link href="http://www.flashdev.ca/article/tag/tutorial/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>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_13586864"
			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_13586864"
			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>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_1465980160"
			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_1465980160"
			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_1893601162"
			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_1893601162"
			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_2026825232"
			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_2026825232"
			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_1253135890"
			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_1253135890"
			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>

