<?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; Events</title>
	<atom:link href="http://www.flashdev.ca/article/tag/events/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>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_2075680613"
			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_2075680613"
			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>
	</channel>
</rss>

