<?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>Kyle's Pile</title>
	<atom:link href="http://as3.kylebrekke.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://as3.kylebrekke.com</link>
	<description>A Heap of Code and Prose...</description>
	<lastBuildDate>Wed, 31 Dec 2008 19:49:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Clarification for &#8220;First Class Ever&#8221;</title>
		<link>http://as3.kylebrekke.com/?p=30</link>
		<comments>http://as3.kylebrekke.com/?p=30#comments</comments>
		<pubDate>Wed, 13 Aug 2008 17:12:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Basics]]></category>
		<category><![CDATA[Flash AS3]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[first]]></category>
		<category><![CDATA[root]]></category>
		<category><![CDATA[stage]]></category>
		<category><![CDATA[timeline]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://www.kylebrekke.com/wordpress/?p=43</guid>
		<description><![CDATA[It was brought to my attention that some people would like to access not only the features of the stage (addChild(), eventListeners, etc) but also the DisplayObjects that reside there. If you played around with the files provided in the original post and tried to do something like this:
private function checkText(evt:Event):void {
if (_stage.myInput.text == "test [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Clarification for &#8220;First Class Ever&#8221;", url: "http://as3.kylebrekke.com/?p=30" });</script>]]></description>
			<content:encoded><![CDATA[<p>It was brought to my attention that some people would like to access not only the features of the stage (addChild(), eventListeners, etc) but also the DisplayObjects that reside there. If you played around with the <a href="http://www.kylebrekke.com/wordpress/wp-content/uploads/2008/04/testclass.rar" target="_blank">files</a> provided in <a href="http://www.kylebrekke.com/wordpress/2008/write-your-first-class-ever-in-flash-as3-with-access-to-the-stage-and-even-dispatching/" target="_blank">the original post</a> and tried to do something like this:</p>
<pre lang="actionscript">private function checkText(evt:Event):void {
if (_stage.myInput.text == "test text") {
_stage.addChild(customText);
dispatchEvent( new Event(correctText) );
}
}<span id="more-30"></span></pre>
<p>you would quickly learn that the AS3 compiler can get really annoying. Obviously this should work, right? I mean, its an explicit reference to the stage! Well, true, it is an explicit reference to the stage, but that isn&#8217;t what you need. What you need is an explicit reference to &#8220;root&#8221;. Now here is where I am going to vague because I don&#8217;t fully understand what the difference is, nor why its necessary, but I can tell you from exploring the children of &#8217;stage&#8217; that &#8220;root&#8221; seems to be a display object one level below &#8220;stage&#8221; where the real children (the ones we care about at least) reside.</p>
<p>That said, we will be passing &#8220;root&#8221; to the class in the same way we passed &#8220;stage&#8221; except that I don&#8217;t actually know what data type &#8220;root&#8221; is (called &#8220;MainTimeline&#8221; by Flash&#8217;s trace() function). My quick fix is to use *. Here is the updated code for the class:</p>
<pre lang="actionscript">package com.kylebrekke {
import flash.display.Sprite;

// Our class extends the Sprite base class
public class testClass extends Sprite {

// Imported files for the compiler
import fl.controls.TextInput;
import flash.text.TextField;
import flash.events.Event;
import flash.display.Stage;

// Public Event Constants
public static const correctText:String = "correctText";

// Private variables
private var stageTextfield:TextInput; //check using event change
private var customText:TextField = new TextField();
private var _stage:Stage;
private var _root:*;

// The 'getters' and the 'setters'
public function get customizedText():String {
return customText.text;
}
public function set customizedText(s:String):void {
customText.text = s;
}

// This is the constructor, the first function to fire during instantiation
public function testClass(alreadyOnStage:TextInput, s:Stage, r:*):void {

// We are passing a reference of the Input Text into a class variable
// so that we can access it from anywhere inside our class
stageTextfield = alreadyOnStage;
stageTextfield.addEventListener(Event.CHANGE, checkText);

_stage = s;
_root = r;

// This custom text can be overriden by the getters/setters
customText.text = "Correct Text!";
customText.x = 250;
customText.y = 35;
}

// This function processes the input text if its value ever changes
private function checkText(evt:Event):void {
if (_root.myInput.text == "test text") {
_stage.addChild(customText);
dispatchEvent( new Event(correctText) );
}
}

}
}</pre>
<p>and here is the one line you need to change in the .fla:</p>
<pre lang="actionscript">var test:testClass = new testClass(myInput, stage, root);</pre>
<p>I hope that clarifies everything. Please post any comments, especially if you happen to know a bunch about how the stage works in AS3.</p>
<p>Also, for another guide on this, try <a href="http://www.kirupa.com/forum/showthread.php?p=1952513" target="_blank">this link</a>.</p>
<p><a href="http://sharethis.com/item?&wp=2.9.2&amp;publisher=&amp;title=Clarification+for+%26%238220%3BFirst+Class+Ever%26%238221%3B&amp;url=http%3A%2F%2Fas3.kylebrekke.com%2F%3Fp%3D30">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://as3.kylebrekke.com/?feed=rss2&amp;p=30</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AMFPHP AS3 Class and Wrapper &#8211; MySQL Query Example</title>
		<link>http://as3.kylebrekke.com/?p=29</link>
		<comments>http://as3.kylebrekke.com/?p=29#comments</comments>
		<pubDate>Sat, 02 Aug 2008 04:24:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[AMFPHP]]></category>
		<category><![CDATA[Flash AS3]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[connect]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[load]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[netdebug]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.kylebrekke.com/wordpress/?p=41</guid>
		<description><![CDATA[Mysql to Flash via AMFPHP
Hopefully you&#8217;ve had a chance to read my other postings on AMFPHP and the classes and wrappers I&#8217;ve written for it. This post will be an example on how to query a mysql database from php and pass it into flash, then parse it into a multi-dimensional associative array (a big [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "AMFPHP AS3 Class and Wrapper &#8211; MySQL Query Example", url: "http://as3.kylebrekke.com/?p=29" });</script>]]></description>
			<content:encoded><![CDATA[<h2>Mysql to Flash via AMFPHP</h2>
<p>Hopefully you&#8217;ve had a chance to read my other postings on AMFPHP and the classes and wrappers I&#8217;ve written for it. This post will be an example on how to query a mysql database from php and pass it into flash, then parse it into a multi-dimensional associative array (a big array that gives you the ability to loop through its records by number, and access its columns by name &#8211; similar to PHP&#8217;s mysql_fetch_assoc() ). First, if you are unfamiliar with my other postings, you can view them below:</p>
<ul>
<li><a href="http://www.kylebrekke.com/wordpress/2008/amfphp-as3-class-and-wrapper-communication-between-flash-and-amfphp-made-even-easier/" target="_blank">AMFPHP Class and Wrapper</a></li>
<li><a href="http://www.kylebrekke.com/wordpress/2008/updated-amfphp-communication-class-in-flash-as3/" target="_blank">Updated version of the base class</a></li>
</ul>
<h2><span id="more-29"></span>Setting the Stage</h2>
<p>This project requires 4 files: the php service, the two as3 classes (amfphp.as and amfWrapper.as), and the FLA. You can download them below:</p>
<ul>
<li><a href="http://www.kylebrekke.com/wordpress/wp-content/uploads/2008/08/amfphp_mysql_example.rar">AMFPHP + MYSQL Connection Project</a></li>
</ul>
<h2>Understanding the PHP Service</h2>
<p>The service itself is fairly straight forward. First, note the important require_once line that includes the connection info to the MySQL database. This file should be basic and doesn&#8217;t necessarily have to be an external one. I keep mine external for convenience sake. Here&#8217;s the code:</p>
<pre lang="php">

$dbhost = "127.0.0.1";
$dbname = "my_database";
$dblogin = "mylogin";
$dbpass = "mypassword";

$failure = "MySQL problem. Connection to ".$dbhost." failed.";

if(!$connect = @mysql_connect($dbhost, $dblogin, $dbpass))
die($failure);
} else {
if(!@mysql_select_db($dbname,$connect)) {
die($failure);
}
</pre>
<p>Here is the class code:</p>
<pre lang="php">

require_once("connect.php");

class example {

/**
@desc - empty
*/
function example ( ){
}

/*
@desc loads the data from the mysql db, sends it to flash, which parses it
*/
function loadMysqlData($user_id) {

NetDebug::trace("Executing loadMysqlData");
NetDebug::trace("Argument user_id: ".$user_id);

$sql = sprintf("SELECT * FROM mytable WHERE id=".$user_id);
$result = mysql_query($sql);

return $result
}

}
</pre>
<p>As for the rest of the service, you have the class declaration, the constructor, and then class method called <em>loadMysqlData</em>, which is really the meat of the project. The NetDebug::trace() function is a debugging tool that outputs information to the AMFPHP Browser. Not really necessary, but I include it anyway out of habit. After that you have the MySQL Query statement, then the actual query when I pass that statement to the mysql_query() function that, if successful, outputs a valid resource id. Lucky for us, we can just return that resource id (as you can see from the code), and doing so passes all of the mysql info we request straight to flash (very quickly I might add; figures show amfphp is as fast as XML for most data sizes and quite a bit fast than JSON).</p>
<h2>Inside Flash &#8211; How to handle this SQL Data</h2>
<p>Luckily, if you are using my amfphp.as class then the function to parse out the MySQL data table is already done for you. The function is static (meaning you don&#8217;t need an instantiated class to access it) and it takes one parameter which is the object that AMFPHP gives to you &#8211; the result. The actual code for making use of this function is below:</p>
<pre lang="actionscript">dbData = amfphp.assocMySQL(remoteConn.serverResponse);</pre>
<p>dbData is the final array (you must declare it as an array beforehand). For a full example of this code, simply look at the attached amfWrapper.as class. The amfWrapper class is an example implementation of the amfphp class. Thus, in the final project (fla) you only need to instantiate the wrapper in order to access the mysql information. It keeps things clean and organized.</p>
<p>The project files can be downloaded below:</p>
<ul>
<li><a href="http://www.kylebrekke.com/wordpress/wp-content/uploads/2008/08/amfphp_mysql_example.rar">AMFPHP + MYSQL Connection Project</a></li>
</ul>
<p>As always, feel free to post any comments or questions. I&#8217;m always willing to help.</p>
<p><a href="http://sharethis.com/item?&wp=2.9.2&amp;publisher=&amp;title=AMFPHP+AS3+Class+and+Wrapper+%26%238211%3B+MySQL+Query+Example&amp;url=http%3A%2F%2Fas3.kylebrekke.com%2F%3Fp%3D29">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://as3.kylebrekke.com/?feed=rss2&amp;p=29</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Preloader Class Video Tutorial for AS3</title>
		<link>http://as3.kylebrekke.com/?p=28</link>
		<comments>http://as3.kylebrekke.com/?p=28#comments</comments>
		<pubDate>Mon, 12 May 2008 17:11:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flash AS3]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[preload]]></category>
		<category><![CDATA[preloader]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://www.kylebrekke.com/wordpress/?p=40</guid>
		<description><![CDATA[I can&#8217;t actually claim any credit for these videos, but I&#8217;ve been asked on several occasions to supply people with a way to preload your videos. I&#8217;m currently swamped right now with other work, but I figured I&#8217;d still provide you with some resources for getting started. I&#8217;ve watched most of these videos and they [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Preloader Class Video Tutorial for AS3", url: "http://as3.kylebrekke.com/?p=28" });</script>]]></description>
			<content:encoded><![CDATA[<p>I can&#8217;t actually claim any credit for these videos, but I&#8217;ve been asked on several occasions to supply people with a way to preload your videos. I&#8217;m currently swamped right now with other work, but I figured I&#8217;d still provide you with some resources for getting started. I&#8217;ve watched most of these videos and they look pretty good to me. One of these days I&#8217;ll sit down and write one and post it for everyone &#8211; not because the world needs my version, but because once I post it I&#8217;ll be able to support the people who have questions (it&#8217;s always easier to answer questions about one&#8217;s personal code, than about foreign code). I hope you enjoy the videos:<span id="more-28"></span></p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="540" height="438" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="bgcolor" value="#FFFFFF" /><param name="src" value="http://www.veoh.com/videodetails2.swf?permalinkId=v6525165naGjcPBf&amp;id=anonymous&amp;player=videodetailsembedded&amp;videoAutoPlay=0" /><embed type="application/x-shockwave-flash" width="540" height="438" src="http://www.veoh.com/videodetails2.swf?permalinkId=v6525165naGjcPBf&amp;id=anonymous&amp;player=videodetailsembedded&amp;videoAutoPlay=0" bgcolor="#FFFFFF"></embed></object></p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="540" height="438" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="bgcolor" value="#FFFFFF" /><param name="src" value="http://www.veoh.com/videodetails2.swf?permalinkId=v6519839BFrgdJWY&amp;id=11927689&amp;player=videodetailsembedded&amp;videoAutoPlay=0" /><embed type="application/x-shockwave-flash" width="540" height="438" src="http://www.veoh.com/videodetails2.swf?permalinkId=v6519839BFrgdJWY&amp;id=11927689&amp;player=videodetailsembedded&amp;videoAutoPlay=0" bgcolor="#FFFFFF"></embed></object></p>
<p><a href="http://sharethis.com/item?&wp=2.9.2&amp;publisher=&amp;title=Preloader+Class+Video+Tutorial+for+AS3&amp;url=http%3A%2F%2Fas3.kylebrekke.com%2F%3Fp%3D28">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://as3.kylebrekke.com/?feed=rss2&amp;p=28</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Tutorial: Event Listeners in Flash AS3 explained</title>
		<link>http://as3.kylebrekke.com/?p=27</link>
		<comments>http://as3.kylebrekke.com/?p=27#comments</comments>
		<pubDate>Wed, 30 Apr 2008 06:35:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Basics]]></category>
		<category><![CDATA[Flash AS3]]></category>
		<category><![CDATA[.as]]></category>
		<category><![CDATA[.fla]]></category>
		<category><![CDATA[.swf]]></category>
		<category><![CDATA[accessible]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[addChild]]></category>
		<category><![CDATA[addeventlistener]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[as2]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[change]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[constructor]]></category>
		<category><![CDATA[dispatch]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[eventlistener]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[interact]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[listener]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[package]]></category>
		<category><![CDATA[public]]></category>
		<category><![CDATA[sprite]]></category>
		<category><![CDATA[stage]]></category>
		<category><![CDATA[text]]></category>
		<category><![CDATA[textfield]]></category>
		<category><![CDATA[textinput]]></category>
		<category><![CDATA[timeline]]></category>
		<category><![CDATA[trigger]]></category>
		<category><![CDATA[variable]]></category>

		<guid isPermaLink="false">http://www.kylebrekke.com/wordpress/?p=39</guid>
		<description><![CDATA[Why should I care about Event Listeners?
If your ambitions in Flash AS3 extend beyond that of basic animation you will NEED to care about Event Listeners because the flow of your entire project will depend on them. They are the ignition to your movies. They allow you to respond to input from users (whether it [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Tutorial: Event Listeners in Flash AS3 explained", url: "http://as3.kylebrekke.com/?p=27" });</script>]]></description>
			<content:encoded><![CDATA[<h3>Why should I care about Event Listeners?</h3>
<p>If your ambitions in Flash AS3 extend beyond that of basic animation you will NEED to care about Event Listeners because the flow of your entire project will depend on them. They are the ignition to your movies. They allow you to respond to input from users (whether it be the mouse or the keyboard or any other form) and take action with that input. In short, Event Listeners are part of the life-blood of Flash programming.</p>
<p><span id="more-27"></span></p>
<h3><strong>What is an <em>Event Listener</em>?</strong></h3>
<p>Very simply, an event listener is a way to execute a function when a designated event takes place. Most importantly, an event listener is a way for Flash trigger certain actions (or alert the programmer) when a certain event has happened and then pass key information to that function.</p>
<p>Think about it like this. If a person clicks on a button, there are a couple of ways to logistically determine if the button was clicked. One option would be to run a timer that fired every millisecond to check if the mouse button was down. Technically this would work, but it would become very cumbersome for the programmer to keep track of so many timers. Many of the other options are equally as cumbersome and unhelpful. The preferred solution is to use an Event Listener.</p>
<h3><strong>Understanding the AS3 Event Listener Model</strong></h3>
<p>The event model is crucial to the flow of complex Flash applications. While you may not have a need for it if you only designing animations (in which case <em><strong>gotoAndPlay()</strong></em> and <strong><em>stop()</em></strong> will be your AS3 favorites) in any other application you will want to harness the power of events. They are crucial for doing things like determining when a user has clicked a button, or figuring out when a remote image has completed loading.</p>
<p>The model itself is part of AS3&#8217;s implementation of an Object Oriented Programming (OOP) style. Don&#8217;t be overwhelmed by its name, however, its really just a way of thinking about the world and modeling it inside your code. Think of it like this: everything in the world is an object. Some things are a combination of multiple objects that work together to create an even more complex object. And yet, each object by itself is a combination of THREE essentially things: its properties (states of being, characteristics, features, etc), its methods (the actions and functions it can perform), and its events (the things that happen to it, its circumstances). Events, then, are really only one third of the picture, but a very important third.</p>
<p>Continuing with this OOP idea, the event is only going to fire when something happens to it. However, in flash it is a two part system. Part One is telling Flash what event it should be on the look-out for. How should Flash know it needs to send an alert when a button is clicked if you never tell it? This is achieved using the <strong><em>addEventListener</em></strong> function. The Second Part is the actual firing function. This is the code that gets executed when the event happens. These functions are just like any other, except they take as their first parameter an object that contains VERY helpful information. More on that later.</p>
<h3><strong>Understanding Part One of the AS3 Event Listener Implementation</strong></h3>
<p>If you are joining us from Flash 8&#8217;s AS2 model then the newer AS3 Event Listener based language may give you some difficulty. I hope that you are familiar with the idea of an event listener, but it is actually implementation in AS3 will be slightly different. In the old model, we assigned the actual function, code and all, like in the example below:</p>
<pre lang="actionscript">var focusListener:Object  = new Object();
focusListener.onSetFocus = function(oldFocus:TextField, newFocus:TextField) {
oldFocus.border = false;
newFocus.border = true;
}</pre>
<p>In AS3, rather than assigned the entire function, we simply reference the function name within the <strong><em>addEventListener</em></strong> function, like below:</p>
<pre lang="actionscript">var focusListener:MovieClip  = new MovieClip();
focusListener.addEventListener(MouseEvent.MOUSE_CLICK, handleClick);</pre>
<p>Here we have create a new movie clip and assigned an event listener to it that will fire in the case of it being clicked on by the mouse. (Note: contrary to the example above, the Object class in AS3 does not have event dispatching capability. Instead, use the Sprite class or a derivative of the Sprite class, such as the MovieClip class).</p>
<p>In every case of assigning an event listener, you will want to start with the instance name. You can remember this because this is the name of the object to which you want the event to happen. For instance, it is the name of the button that you are assuming the user will click.</p>
<p>This is followed every time by the dot operator (&#8220;.&#8221;) and then the function name <strong><em>addEventListener</em></strong>. This tells Flash exactly what the name implies, that it should add an event listener to the object you have specified. Of course, the next question is &#8220;what kind of listener?&#8221; and of course, &#8220;what should I do once the event has occurred?&#8221;</p>
<p>The answer to the first question will depend on your project. The two most frequent types of events are the general <strong><em>Events</em></strong> and the <strong><em>MouseEvents</em></strong>. To access these types, you simply type the name of the event class, for instance <strong>MouseEvent</strong>, followed by the dot operator (&#8220;.&#8221;), and then the specific type of event you&#8217;d like to listen for. Don&#8217;t worry, a mini-pop-up will appear to help you select your event type. Some <strong>MouseEvent</strong> types include: <strong>MOUSE_UP</strong>, <strong>MOUSE_DOWN</strong>, <strong>MOUSE_CLICK</strong>, <strong>MOUSE_OVER</strong>, etc. Just chose your type, hit enter, and then on to the next question.</p>
<p>Now we must tell Flash what to do when the event has occurred. The only real answer is for Flash to execute a function, so the next item we tell Flash is the name of the function we want it to execute. (Note: you do not need to type any quotation marks to signify a string, just simply type the function name and Flash will understand). Once you have done this, part one of the event listener model is completed.</p>
<h3><strong>Understanding Part Two of the AS3 Event Listener Implementation</strong></h3>
<p>The second part of the Event Listener model is the actual function that the Event Listener will execute. This function is THE EXACT SAME as any other function you will make in flash with only one major exception &#8211; the first parameter of the function is an <strong><em>Event Object</em></strong>. This object is the home of many important pieces of information, most notably <strong><em>target</em></strong> and <strong><em>currentTarget</em></strong>. First, let me give you some example code:</p>
<pre lang="actionscript">function handleClick(evt:MouseEvent):void {
trace("You clicked the "+evt.currentTarget+" button");
}</pre>
<p>Notice how the syntax is the same. The one object that has been passed to the function I&#8217;ve called &#8220;evt&#8221; and is a <strong><em>MouseEvent</em></strong>.This object contains different properties that we&#8217;d like access to. The one I&#8217;ve used in this example is called <strong><em>currentTarget</em></strong> and it is a literal reference to the object that has been clicked, that is, our MovieClip. Thus, anything you do to <strong><em>currentTarget</em></strong> is the same as if you had done it to our MovieClip called &#8220;focusListener&#8221;. This is very powerful because now you can write just one function and instead of referring to the &#8220;focusListener&#8221; you can reference <strong><em>currentTarget</em></strong> and it can be ANY MovieClip you&#8217;ve passed. You&#8217;ve now made reusable code. And reusable code is the best code.</p>
<p>Other properties passed via the <strong><em>MouseEvent</em></strong> include <strong>localX</strong>, <strong>localY</strong>, <strong>shiftKey</strong>, <strong>stageX</strong>, <strong>stagey</strong>, etc. As the names imply, these are the coordinates of the mouse upon clicking (both local within the &#8220;focusListener&#8221; MovieClip and global to the stage). Each property is explained in detail in <a href="http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/js/html/wwhelp.htm">Adobe&#8217;s LiveDocs</a>.</p>
<p>The trick to implementing event listeners successfully is to learn to use the <strong><em>currentTarget</em></strong> property really well so that you can program powerful functions that leverage the reusability offered by this event model. Do not expect to be a master of this all in one sitting. It takes some practice to get use to the idea of events. With effort and some help from the community you will be a pro in no time.</p>
<p>If you&#8217;d like to see an example of these event listeners in action you can read the article <a title="Write your first class ever...with event dispatching" href="http://www.kylebrekke.com/wordpress/2008/write-your-first-class-ever-in-flash-as3-with-access-to-the-stage-and-even-dispatching/" target="_self">Write your first class ever&#8230; with event dispatching</a>. Please do not hesitate to leave any comments or questions you might have on the feedback below.</p>
<p><a href="http://sharethis.com/item?&wp=2.9.2&amp;publisher=&amp;title=Tutorial%3A+Event+Listeners+in+Flash+AS3+explained&amp;url=http%3A%2F%2Fas3.kylebrekke.com%2F%3Fp%3D27">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://as3.kylebrekke.com/?feed=rss2&amp;p=27</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Advanced Customizable AS3 Scrollbar Class for Adobe Flash CS3</title>
		<link>http://as3.kylebrekke.com/?p=26</link>
		<comments>http://as3.kylebrekke.com/?p=26#comments</comments>
		<pubDate>Wed, 30 Apr 2008 00:59:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Classes & Packages]]></category>
		<category><![CDATA[Flash AS3]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[amf]]></category>
		<category><![CDATA[AMFPHP]]></category>
		<category><![CDATA[arrow]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[button]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[clean]]></category>
		<category><![CDATA[communication]]></category>
		<category><![CDATA[customize]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[dispatch]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[explanation]]></category>
		<category><![CDATA[external]]></category>
		<category><![CDATA[fb:swf]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[netconnection]]></category>
		<category><![CDATA[new]]></category>
		<category><![CDATA[paramenter]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[previous]]></category>
		<category><![CDATA[response]]></category>
		<category><![CDATA[scroll]]></category>
		<category><![CDATA[scrollbar]]></category>
		<category><![CDATA[static]]></category>
		<category><![CDATA[track]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[version]]></category>

		<guid isPermaLink="false">http://www.kylebrekke.com/wordpress/?p=37</guid>
		<description><![CDATA[Why a Custom AS3 Scrollbar?
I&#8217;m sure this isn&#8217;t first nor will it be the last time you hear about the frustrations of dealing with Adobe&#8217;s pre-coded and pre-packaged components. Some complain about their design, their style, their customization, their size, and even (my personal experience) their functionality when embedded into pages with Facebook&#8217;s &#60;fb:swf&#62; tag. [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Advanced Customizable AS3 Scrollbar Class for Adobe Flash CS3", url: "http://as3.kylebrekke.com/?p=26" });</script>]]></description>
			<content:encoded><![CDATA[<h3><strong>Why a Custom AS3 Scrollbar?</strong></h3>
<p>I&#8217;m sure this isn&#8217;t first nor will it be the last time you hear about the frustrations of dealing with Adobe&#8217;s pre-coded and pre-packaged components. Some complain about their design, their style, their customization, their size, and even (my personal experience) their functionality when embedded into pages with Facebook&#8217;s &lt;fb:swf&gt; tag. The simple solution to all of these problems is to simply code your own. However, scrollbars can be a nightmare and take hours to code, debug and customize. So, I&#8217;ve tried to save you all that hassle by building a fairly customizable scrollbar class.</p>
<p>Download the example files (includes the classes): <a href="http://www.kylebrekke.com/wordpress/wp-content/uploads/2008/04/scrollbar.rar">AS3 Scrollbar Class and Example</a></p>
<p>In zip format: <a href="http://www.kylebrekke.com/wordpress/wp-content/uploads/2008/04/scrollbar.zip">AS3 Scrollbar Class and Example</a></p>
<p><a href="http://www.kylebrekke.com/wordpress/wp-content/uploads/2008/04/scrollbar.rar"><span id="more-26"></span></a></p>
<h3><strong>Quick Start Guide for the AS3 Scrollbar</strong></h3>
<p>For out of the box installation there are only a few lines of code you need once you place the files into the correct class path (default: com.kylebrekke.scrollbar &#8211; place &#8220;com&#8221; in the same root folder as your .fla). On whatever frame it is you&#8217;d like, place the following code:</p>
<pre lang="actionscript">import com.kylebrekke.scrollbar.scrollbar;
var viewableWidth:Number = 200;
var viewableHeight:Number = 100;

var hScroll:scrollbar = new scrollbar(stage, targetMC, scrollbar.HORIZONTAL, viewableWidth, viewableHeight);
hScroll.x = 40;
hScroll.y = 235;

var vScroll:scrollbar = new scrollbar(stage, targetMC, scrollbar.VERTICAL, viewableWidth, viewableHeight);
vScroll.x = 15;
vScroll.y = 20;</pre>
<p>I&#8217;ll give you a quick break down of this code. First, you must import the proper classes. Make sure that the path follows wherever you decide to place the class file (default shown above). The next two variables are the viewable width and height of the target you want to scroll. So, you may have a movie clip that is 700&#215;700, but you only have a place in your flash file to show a 300&#215;400 square. Then, to use the scroll bars within this area simply set the viewable width and height to 300 and 400 respectively.</p>
<p>Next, you will notice that the vertical and horizontal instantiation code is practically the same, with the exception of &#8220;scrollbar.&lt;direction&gt;&#8221;. That is where you set which direction you&#8217;d like that instance to scroll. The &#8220;stage&#8221; is the default stage you&#8217;d like to add the scrollbars to. This should be the same stage that &#8220;targetMC&#8221; is on; &#8220;targetMC&#8221; is the movie clip you&#8217;d like to scroll. Finally, if you&#8217;d like, you can set different positions for the instances of the scrollbar. You&#8217;ll most likely have to do use the set and check method &#8211; make a guess and compile the movie quickly to see if they show up properly.</p>
<h3><strong>Advanced Customization of the AS3 Scrollbar</strong></h3>
<p>To customize or skin the scrollbar assets (the movie clips that make up the scrollbar) you can simply edit them from the library of the .fla. However, a couple of things to note (1) be sure to center both vertically and horizontally the graphics within the movieclip and (2) most of the assets have two frames so that their &#8220;buttonmode&#8221; can be set to true which gives them a rollover effect. Currently, the style is a poor attempt to copy Vista-style buttons. I&#8217;m sure many designers out there could do a better job, but since this is only an example, I expect most people to do some modifications.</p>
<p>The other points that can be edited include the speeds at which the content scrolls from an arrow click or a mouse wheel move. These numbers represent the amount of pixel movement on each mouse input and can be changed using the set and check method. The other constant is the transition speed which essentially determines if there is any lag between the time the user scrolls and content moves. I&#8217;ve chosen to use <a href="http://blog.greensock.com/tweenliteas3/">TweenLite</a> because the size is much smaller than Caurina Tweener, though you can feel free to swap those out as well, it&#8217;s quite simple.</p>
<h3><strong>Feedback about the Scrollbar</strong></h3>
<p>I realize now, after the fact, that much of this scrollbar structure could be improved. I&#8217;ll attempt it again probably in the weeks to come, but if anyone would like to expand or alter this code and send me the updates it&#8217;d be much appreciated. As always, I&#8217;m only looking to provide the flash community with high quality with premade classes to save time and headaches. One requirement, however, is that the code is clean, concise and reusable. I feel that this code may not live up to the high expectations, but never fear, another version is on its way.</p>
<p><a href="http://sharethis.com/item?&wp=2.9.2&amp;publisher=&amp;title=Advanced+Customizable+AS3+Scrollbar+Class+for+Adobe+Flash+CS3&amp;url=http%3A%2F%2Fas3.kylebrekke.com%2F%3Fp%3D26">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://as3.kylebrekke.com/?feed=rss2&amp;p=26</wfw:commentRss>
		<slash:comments>47</slash:comments>
		</item>
		<item>
		<title>Updated: AMFPHP Communication Class in Flash AS3</title>
		<link>http://as3.kylebrekke.com/?p=25</link>
		<comments>http://as3.kylebrekke.com/?p=25#comments</comments>
		<pubDate>Tue, 15 Apr 2008 15:12:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[AMFPHP]]></category>
		<category><![CDATA[Classes & Packages]]></category>
		<category><![CDATA[Flash AS3]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[amf]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[clean]]></category>
		<category><![CDATA[communication]]></category>
		<category><![CDATA[customize]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[dispatch]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[explanation]]></category>
		<category><![CDATA[external]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[netconnection]]></category>
		<category><![CDATA[new]]></category>
		<category><![CDATA[paramenter]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[previous]]></category>
		<category><![CDATA[responder]]></category>
		<category><![CDATA[response]]></category>
		<category><![CDATA[static]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[version]]></category>
		<category><![CDATA[walkresponse]]></category>
		<category><![CDATA[wrapper]]></category>

		<guid isPermaLink="false">http://www.kylebrekke.com/wordpress/?p=36</guid>
		<description><![CDATA[This is a quick post to let everyone know minor updates have been made to the amfphp communication class. Thanks to the help of Joshua Logsdon I have been able to make several changes that either fixed bugs or added to the quality of the class. One very useful function is the assocResult function that [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Updated: AMFPHP Communication Class in Flash AS3", url: "http://as3.kylebrekke.com/?p=25" });</script>]]></description>
			<content:encoded><![CDATA[<p>This is a quick post to let everyone know minor updates have been made to the amfphp communication class. Thanks to the help of <a href="http://joshualogsdon.com/" target="_blank">Joshua Logsdon</a> I have been able to make several changes that either fixed bugs or added to the quality of the class. One very useful function is the assocResult function that turns the received object from amfphp into an associative array, which can be much easier to work with sometimes than an object.</p>
<p>The new file is available for download: <a href="http://www.kylebrekke.com/wordpress/wp-content/uploads/2008/04/amfphpwrapper.rar">AS3 AMFPHP Class and Wrapper</a></p>
<p>Older articles can be accessed:</p>
<p><a rel="bookmark" href="http://www.kylebrekke.com/wordpress/2008/amfphp-as3-class-and-wrapper-communication-between-flash-and-amfphp-made-even-easier">AMFPHP AS3 Class &#8211; Communication between Flash and AMFPHP made easy</a></p>
<p><a rel="bookmark" href="http://www.kylebrekke.com/wordpress/2008/amfphp-as3-class-and-wrapper-communication-between-flash-and-amfphp-made-even-easier">AMFPHP AS3 Class and Wrapper &#8211; Communication between Flash and AMFPHP made even easier</a></p>
<p><a rel="bookmark" href="../2008/amfphp-as3-class-and-wrapper-mysql-query-example/">AMFPHP AS3 Class and Wrapper &#8211; MySQL Query Example</a></p>
<p>Let me know what you think of the updates, and the additions from Joshua.</p>
<p><a href="http://sharethis.com/item?&wp=2.9.2&amp;publisher=&amp;title=Updated%3A+AMFPHP+Communication+Class+in+Flash+AS3&amp;url=http%3A%2F%2Fas3.kylebrekke.com%2F%3Fp%3D25">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://as3.kylebrekke.com/?feed=rss2&amp;p=25</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>AMFPHP AS3 Class and Wrapper &#8211; Communication between Flash and AMFPHP made even easier</title>
		<link>http://as3.kylebrekke.com/?p=24</link>
		<comments>http://as3.kylebrekke.com/?p=24#comments</comments>
		<pubDate>Sun, 13 Apr 2008 06:27:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[AMFPHP]]></category>
		<category><![CDATA[Classes & Packages]]></category>
		<category><![CDATA[Flash AS3]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[amf]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[clean]]></category>
		<category><![CDATA[communication]]></category>
		<category><![CDATA[customize]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[dispatch]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[explanation]]></category>
		<category><![CDATA[external]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[netconnection]]></category>
		<category><![CDATA[new]]></category>
		<category><![CDATA[paramenter]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[previous]]></category>
		<category><![CDATA[responder]]></category>
		<category><![CDATA[response]]></category>
		<category><![CDATA[static]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[version]]></category>
		<category><![CDATA[walkresponse]]></category>
		<category><![CDATA[wrapper]]></category>

		<guid isPermaLink="false">http://www.kylebrekke.com/wordpress/?p=34</guid>
		<description><![CDATA[After getting some positive response to my last project, I decided to spend some time, fix a few bugs and give you guys a new, cleaner amfphp class&#8230; but wait, thats not all, I even through in a free amfphp WRAPPER, ABSOLUTELY FREE! (right&#8230; well the entire site is free, but still, that makes me [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "AMFPHP AS3 Class and Wrapper &#8211; Communication between Flash and AMFPHP made even easier", url: "http://as3.kylebrekke.com/?p=24" });</script>]]></description>
			<content:encoded><![CDATA[<p>After getting some positive response to my last project, I decided to spend some time, fix a few bugs and give you guys a new, cleaner amfphp class&#8230; but wait, thats not all, I even through in a free amfphp WRAPPER, ABSOLUTELY FREE! (right&#8230; well the entire site is free, but still, that makes me a nice guy, right?)</p>
<p>Anyhow, here is the class for those who&#8217;d just like to download and tinker: <a href="http://www.kylebrekke.com/wordpress/wp-content/uploads/2008/04/amfphpwrapper.rar">AS3 AMFPHP Class and Wrapper<span id="more-24"></span></a></p>
<p>This latest version was possible thanks to help from <a href="http://joshualogsdon.com/" target="_blank">Joshua Logsdon</a> (credit can be seen <a href="http://www.kylebrekke.com/wordpress/2008/updated-amfphp-communication-class-in-flash-as3/" target="_self">here</a>).</p>
<p>And here is an important reference to my previous amfphp connection class (though its a bit out of date you can still download the older version): <a href="http://www.kylebrekke.com/wordpress/2008/amfphp-as3-class-communication-between-flash-and-amfphp-made-easy/" target="_blank">AMFPHP MADE EASY</a></p>
<p>Now, for the explanation. The original class works much like I describe in the previous article. During instantiation you supply the gateway url, the call function, and any extra parameters you&#8217;d like including a callback function for responses. Simple and clean. However, I do recognize that for complex projects you may need something a bit more robust, and thus I have extended the class with a wrapper class. Now, since wrapper classes should be customized to each project, what I&#8217;ve really done is given you an example of how to implement my amfphp communication class. It creates a class with a few custom methods and public variables for easy access to important info. It also shows you how you can dispatch events based on responses from the original amfphp class.</p>
<p>Note, I&#8217;ve made some changes suggested to me by Joshua Logsdon, though I didn&#8217;t have a chance to get it from him directly (thus, this is still my original code) he did give me the inspiration. These include making the assocMySQL and walkResponse classes static, and making object encoding and debugging constants (like preferences) at the top of the class. I also fixed a bug in the way I was checking for undefined values in extra parameters. All in all this is a much more solid version of the class. I hope you enjoy it.</p>
<p>Download the example and class files: <a href="http://www.kylebrekke.com/wordpress/wp-content/uploads/2008/04/amfphpwrapper.rar">AS3 AMFPHP Class and Wrapper</a></p>
<p>Download amfphp from it&#8217;s website: <a href="http://www.amfphp.org/" target="_blank">AMFPHP HOMEPAGE</a></p>
<p>View the older explanation on using the AS3 AMFPHP class: <a href="http://www.kylebrekke.com/wordpress/2008/amfphp-as3-class-communication-between-flash-and-amfphp-made-easy/" target="_blank">AMFPHP MADE EASY</a></p>
<p><a href="http://sharethis.com/item?&wp=2.9.2&amp;publisher=&amp;title=AMFPHP+AS3+Class+and+Wrapper+%26%238211%3B+Communication+between+Flash+and+AMFPHP+made+even+easier&amp;url=http%3A%2F%2Fas3.kylebrekke.com%2F%3Fp%3D24">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://as3.kylebrekke.com/?feed=rss2&amp;p=24</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Write your first class ever in Flash AS3 with access to the stage and event dispatching</title>
		<link>http://as3.kylebrekke.com/?p=23</link>
		<comments>http://as3.kylebrekke.com/?p=23#comments</comments>
		<pubDate>Thu, 10 Apr 2008 20:05:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Basics]]></category>
		<category><![CDATA[Flash AS3]]></category>
		<category><![CDATA[.as]]></category>
		<category><![CDATA[.fla]]></category>
		<category><![CDATA[.swf]]></category>
		<category><![CDATA[accessible]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[addChild]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[as2]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[change]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[compile-time]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[constructor]]></category>
		<category><![CDATA[dispatch]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[getter]]></category>
		<category><![CDATA[interact]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[listener]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[package]]></category>
		<category><![CDATA[public]]></category>
		<category><![CDATA[setter]]></category>
		<category><![CDATA[sprite]]></category>
		<category><![CDATA[stage]]></category>
		<category><![CDATA[testClass]]></category>
		<category><![CDATA[text]]></category>
		<category><![CDATA[textfield]]></category>
		<category><![CDATA[textinput]]></category>
		<category><![CDATA[timeline]]></category>
		<category><![CDATA[variable]]></category>

		<guid isPermaLink="false">http://www.kylebrekke.com/wordpress/?p=32</guid>
		<description><![CDATA[The switch for many users from Actionscript 2 (AS2) to Actionscript 3 (AS3) can be a difficult one mainly because of AS3&#8217;s preference for an Object Oriented (OOP) style of programming. Once users realize this they are often thrown head first into the realm of class creation in flash with really no idea how to [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Write your first class ever in Flash AS3 with access to the stage and event dispatching", url: "http://as3.kylebrekke.com/?p=23" });</script>]]></description>
			<content:encoded><![CDATA[<p>The switch for many users from Actionscript 2 (AS2) to Actionscript 3 (AS3) can be a difficult one mainly because of AS3&#8217;s preference for an Object Oriented (OOP) style of programming. Once users realize this they are often thrown head first into the realm of class creation in flash with really no idea how to make this &#8220;class&#8221; interact with their timelines. The hope is that by the end of this article one will have a basic understanding of how to create, design, and implement a class.</p>
<p>Before we get started, <a href="http://www.kylebrekke.com/wordpress/wp-content/uploads/2008/04/testclass.rar">here</a> is the example code you can use to follow along.<span id="more-23"></span></p>
<p>Step number one consists in creating the actual &#8220;*.as&#8221; file and placing it in the correct place in relation to your &#8220;*.fla&#8221; file. (classpath) Generally speaking, people tend to place their class in subfolders that use the &#8220;*.fla&#8221; as its base folder. For instance, if you .fla is in &#8220;C:\wamp\MyProject&#8221; then that would be the base folder. The first subfolder tends to be called &#8220;com&#8221; and the ones after that either the person&#8217;s online alias or simply a descriptor name. For instance, using the same base class as above, I would put my classes into a folder with the path of &#8220;C:\wamp\MyProject\com\kylebrekke&#8221;. This keeps things very simple and clean, and its easy to post your classes online later. All people have to do is drop the &#8220;com&#8221; folder into their base folder and everything is ready to go. So, assuming you&#8217;ve setup your files in this way (and we will use my example for the rest of this article) lets dig a little deeper into the code.</p>
<p>Next you will need a basic frame of code for your class. Each class resides inside what Adobe calls a &#8220;package&#8221;. This really is just a set of related classes. Note, however, that only ONE class per package is allowed to be public, that is, only one class can talk to the rest of flash, the rest of the classes in the package can only talk to other classes inside the package. Here is the basic look of the starter package:</p>
<pre lang="actionscript">package com.kylebrekke {
}</pre>
<p>Notice how after the keyword package you have a reference to the classpath using dot syntax. This is the same in windows language as &#8220;\com\kylebrekke&#8221; except we replace slashes with periods. After this we have to give the package a class to work with. We will call ours &#8220;testClass&#8221; to make it easy.</p>
<pre lang="actionscript">package com.kylebrekke {
public class testClass extends Sprite {
}
}</pre>
<p>We make this class public, so its accessible to our timeline, we call it testClass, and it extends Sprite. Sprite is the preferred base class of Flash CS3 because it comes with everything you could need such as event listeneing and stage capability, but it is not bulky like some other extended classes. Unless you know for a fact you want to extend with something else, I recommend always using the Sprite class.</p>
<p>Next, we have to give our class a constructor function. This is the function that ALWAYS gets called first when someone instantiates your class. You are not required to put anything inside it, but it&#8217;s a great place to gather info that you know the class will need, or need set.</p>
<p>Now I haven&#8217;t previously mentioned what we will use this class for. I think it will be helpful for demonstration purposes if our class, once instantiated, takes a textfield already on the stage and checks its value, and if it&#8217;s a certain value then displays a new textfield. That being said, the constructor is a great place to take the reference to the already created textfield. I&#8217;m going to take a big leap in the code and place a bunch of things we need access to within the package.</p>
<pre lang="actionscript">public function testClass(alreadyOnStage:TextInput, s:Stage):void { // We are passing a reference of the Input Text into a class variable
// so that we can access it from anywhere inside our class
stageTextfield = alreadyOnStage;
stageTextfield.addEventListener(Event.CHANGE, checkText);

_stage = s;

// This custom text can be overriden by the getters/setters
customText.text = "Correct Text!";
customText.x = 250;
customText.y = 35;
}</pre>
<p>Notice that the constructor has the same name as our class. Its also declared as public. These two things are vital and they will never change no matter the class. Next, notice the two parameters that are getting passed. One is a reference to the text field that we want to check, and the second is to the stage. This allows us to access things from the timeline that we normally wouldn&#8217;t.</p>
<p>Inside the constructor, we assign the parameters to their class variables so that we can access them throughout the class. This is a very typical method especially when you have a reference that you need access to outside the constructor function. In addition, we have added an event listener to the text input so that as a person types we are constantly verifying it against our predetermined text.</p>
<p>I almost forgot to mention how important it is to include to correct imports when working with a class like this. Without them the compiler will throw all types of errors at you that often come in the form of: 1046: Type was not found or was not a compile-time constant: Stage. If you get that error its because you forgot to import all of the necessary files for the compiler.</p>
<p>Here is the next piece of code:</p>
<pre lang="actionscript">private function checkText(evt:Event):void {
if (stageTextfield.text == "test text") {
_stage.addChild(customText);
dispatchEvent( new Event(correctText) );
}
}</pre>
<p>The event listener calls a function that I named checkText. This takes the Event as a parameter, and this event is an object that has access to the target that called it. We could easily use that  if we had more than one object calling this function, but since we don&#8217;t we will specifically check the text of the Input Text against our &#8220;test text&#8221; and if they are the same, we will add a new text field to the stage. Notice how I have referenced the addChild() of the stage and not of the class. If I were to forget the &#8220;stage&#8221; before addChild nothing would show up because the textfield would be added to the stage of our class, not the timeline. Thus, it is a very important piece of code.</p>
<p>The next piece is dispatching an event. You&#8217;ll notice that within the conditional statement of checkText, if we find a match then our class dispatches an event. This would be a great way to, for instance, make a &#8220;next&#8221; button appear on the stage from the timeline. I will show you that code a little further down the page. The important part of the dispatch function is that you should be dispatching an event. You have many possibilities including custom events, in this case we are just dispatching the even by name, but we could also pass on the Event.CHANGE event if we wanted the timeline to access to that as well.</p>
<p>Finally, I&#8217;d like to talk about the getters and setters. These are public functions that can make private variables accessible outside the class. The main reason you employ these as opposed to public variables is that you can control whether or not the variable has both capabilities, that is, to be read and written to. In addition, you can make alterations to the variable before passing it out of the class, which can be great leverage. Here is the code for the getter and setter of the customText variable:</p>
<pre lang="actionscript">public function get customizedText():String {
return customText.text;
}
public function set customizedText(s:String):void {
customText.text = s;
}</pre>
<p>In this case, I have not opened up the entire textfield to editing from the user, only the text portion of it. This can protect your code from getting sloppy and unmanageable in the future and it is an important piece of structure to build into all of your classes. Now, my class has a property that can be set very easily simply by doing code that looks like &#8220;instance.customText = &#8220;new text&#8221;;&#8221; and instead of &#8220;Correct Text&#8221; our textfield will show something different.</p>
<p>Ok, finally we can move on to our instantiation code that will be inside of our &#8220;*.fla&#8221; file. I&#8217;ll post all the code since it is not very much and discuss it point by point.</p>
<pre lang="actionscript">// Import the proper files for the compile
import com.kylebrekke.testClass;// Instantiate the new clas
var test:testClass = new testClass(myInput, stage);

// Add the event listene
test.addEventListener(testClass.correctText, nextQuestion);

// Use a setter to set custom tex
test.customizedText = "Bravo, correct answer!";

// This function is called by the event listener when the
// text is correct
function nextQuestion(evt:Event):void {
// You could place code to move to a next question here
}

stop();</pre>
<p>First, we have again imported our code using the correct dot syntax. Right after that we provide the instantiation code. This code takes two parameters, the input text and the stage. The input text MUST be already dragged onto the stage and been given an instance name, in this case I called it &#8220;myInput&#8221;. The stage variable &#8220;stage&#8221; will always be the same if you are passing from the timeline to the class.</p>
<p>After that I added an event listener that listens for the custom event of correct text. Notice that the event listener is placed onto &#8220;test&#8221; which is an instance, but that in order to access the constant&#8217;s name that we are dispatching I use the class. This is because the constant that I defined in the class is &#8220;static&#8221; and does not need to be instantiated. You must make sure that if you follow the same sort of coding that I am practicing here, must use the instance name and the class name in the proper places or the compiler will throw an error. This can be confusing at first, but you&#8217;ll get the hang of it in no time.</p>
<p>Just below that I am using a setter to reset the text that will display when user types in the correct text into the Text Input. You&#8217;ll see once you execute the code, it should be self-explanatory.</p>
<p>Finally we have the function called by the text. Now I didn&#8217;t actually write and code for the next question, but I did let you know that this function would be where you could execute the code for displaying a button for instance that you only want to display once the person has typed in the proper input.</p>
<p>Anyway, that is an explanation of the code piece by piece. I hope you found this useful. Please post any question or comments you may have.</p>
<p>Another great tutorial if you need some help is <a href="http://www.senocular.com/flash/tutorials/as3withmxmlc/" target="_blank">Senocular&#8217;s Beginners Guide</a>.</p>
<p><a href="http://www.kylebrekke.com/wordpress/wp-content/uploads/2008/04/testclass.rar">Here</a> is the example file for download so you can follow step by step and compile it yourself to see how it work. Enjoy!</p>
<p>(<a href="http://www.kylebrekke.com/wordpress/2008/clarification-for-first-class-ever/" target="_blank">Quick update on using root vs. stage</a>)</p>
<p><a href="http://sharethis.com/item?&wp=2.9.2&amp;publisher=&amp;title=Write+your+first+class+ever+in+Flash+AS3+with+access+to+the+stage+and+event+dispatching&amp;url=http%3A%2F%2Fas3.kylebrekke.com%2F%3Fp%3D23">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://as3.kylebrekke.com/?feed=rss2&amp;p=23</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Wordpress displays odd or foreign characters (after my web server switched platforms)</title>
		<link>http://as3.kylebrekke.com/?p=22</link>
		<comments>http://as3.kylebrekke.com/?p=22#comments</comments>
		<pubDate>Sun, 06 Apr 2008 20:40:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[apostrophe]]></category>
		<category><![CDATA[â€™]]></category>
		<category><![CDATA[characters]]></category>
		<category><![CDATA[charset]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[foreign]]></category>
		<category><![CDATA[hyphen]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[odd]]></category>
		<category><![CDATA[phpmyadmin]]></category>
		<category><![CDATA[replace]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[set]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[update]]></category>
		<category><![CDATA[vdeck]]></category>
		<category><![CDATA[wp_content]]></category>

		<guid isPermaLink="false">http://www.kylebrekke.com/wordpress/2008/wordpress-displays-odd-or-foreign-characters-after-my-web-server-switched-platforms/</guid>
		<description><![CDATA[Only a few days ago I was moved by my web server from their old vDeck platform to their newer, um, vDeck platform? Well, the actual platform is besides the point. The problem that arose was actually caused by MySQL&#8217;s faulty exporting function which may have been combined with some charset irregularities between my database [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Wordpress displays odd or foreign characters (after my web server switched platforms)", url: "http://as3.kylebrekke.com/?p=22" });</script>]]></description>
			<content:encoded><![CDATA[<p>Only a few days ago I was moved by my web server from their old vDeck platform to their newer, um, vDeck platform? Well, the actual platform is besides the point. The problem that arose was actually caused by MySQL&#8217;s faulty exporting function which may have been combined with some charset irregularities between my database tables and wordpress. All I&#8217;m trying to say, really, is that one day my blog was working great and the next it was filled with lots of &#8220;â€™&#8221; characters. Big problem.<span id="more-22"></span></p>
<p>Well I looked really closely at the pattern of these characters and realized that they pretty much represented either apostrophes, quotation marks or hyphens. There as an entirely different problem with the one essay I&#8217;ve posted in French &#8211; I just reposted it. I wasn&#8217;t about to sit down and hash out all the different foreign characters I used that text. However, I had enough other posts that I didn&#8217;t want to find all my old Word documents and repost each one &#8211; what a hassle!</p>
<p>I did some research and found lots of people who wanted to teach me how to re-export my MySQL databases or some other headache filled process that, in my opinion, was not actually going to do the trick. Instead, I used a very simple approach &#8211; search and replace. We&#8217;ve all done it folks, sometimes just inside a Word document when you realized that you&#8217;ve misspelled the name of the main character in your latest Shakespeare paper, but this time I needed to use some sql code to achieve the same thing, no CTRL + F GUI.</p>
<p>The way you want to go about doing this is to open up a mysql manager (usually written in php) like <a href="http://www.phpmyadmin.net/home_page/index.php">phpMyAdmin</a>. Click on the database you want to make the changes to (usually includes the name wordpress in it somewhere) and then click on the &#8220;SQL&#8221; tab. This page gives you the chance to execute SQL statements on the database. One important note: <strong><em>BE SURE TO BACKUP YOUR DATABASE BEFORE EXECUTING ANY QUERIES OR TRYING TO ALTER IT IN ANYWAY</em></strong>. From this page, insert the following code and execute it:</p>
<pre lang="PHP">UPDATE `wp_posts` SET `post_content` = REPLACE( `post_content` , "â€™", "'" );
UPDATE `wp_posts` SET `post_content` = REPLACE( `post_content` , "â€¦", "..." );
UPDATE `wp_posts` SET `post_content` = REPLACE( `post_content` , "â€“", "-" );
UPDATE `wp_posts` SET `post_content` = REPLACE( `post_content` , "â€œ", "\"" );
UPDATE `wp_posts` SET `post_content` = REPLACE( `post_content` , "â€", "\"" );</pre>
<p>Let me quickly explain the syntax. UPDATE just means that the query isn&#8217;t going to add or delete any data, only modify or update it. The next word inbetween the odd quote set is the table name. This is the table typically used by wordpress to hold the post content. SET is another sql keyword which is followed by the field within the table that you&#8217;d like to perform the replace function on. Next, REPLACE is the name of the function we are using (remember, we are performing a search and <em>replace</em>). Its parameters are the field name (yes again), the set of letters we are looking for in the field, and finally the set of letters we&#8217;d like to actually do the replacing (that is, be inserted into the field).</p>
<p>So, just simply execute those lines of code (you can place them all in the SQL text area at one time as long as you remember the semi-colons as separation) and presto, your content should be good as new.</p>
<p><a href="http://sharethis.com/item?&wp=2.9.2&amp;publisher=&amp;title=Wordpress+displays+odd+or+foreign+characters+%28after+my+web+server+switched+platforms%29&amp;url=http%3A%2F%2Fas3.kylebrekke.com%2F%3Fp%3D22">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://as3.kylebrekke.com/?feed=rss2&amp;p=22</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parsing Google Calendar XML in Flash CS3 AS3</title>
		<link>http://as3.kylebrekke.com/?p=21</link>
		<comments>http://as3.kylebrekke.com/?p=21#comments</comments>
		<pubDate>Sun, 06 Apr 2008 01:49:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Classes & Packages]]></category>
		<category><![CDATA[Flash AS3]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[attribute]]></category>
		<category><![CDATA[calendar]]></category>
		<category><![CDATA[entries]]></category>
		<category><![CDATA[entry]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[feed]]></category>
		<category><![CDATA[gcal]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[length]]></category>
		<category><![CDATA[namespace]]></category>
		<category><![CDATA[ns]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[startdate]]></category>
		<category><![CDATA[urlloader]]></category>
		<category><![CDATA[urlrequest]]></category>
		<category><![CDATA[where]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xmlData]]></category>

		<guid isPermaLink="false">http://www.kylebrekke.com/wordpress/2008/parsing-google-calendar-xml-in-flash-cs3-as3/</guid>
		<description><![CDATA[Honestly, when I first attempted to parse and access Google Calendar XML from flash I had a lot of trouble with it. I spent a lot of hours being frustrated by XML namespaces (it was the first time I&#8217;d had to use them) and consequently had to move to the forums at actionscript.org. I was [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Parsing Google Calendar XML in Flash CS3 AS3", url: "http://as3.kylebrekke.com/?p=21" });</script>]]></description>
			<content:encoded><![CDATA[<p>Honestly, when I first attempted to parse and access Google Calendar XML from flash I had a lot of trouble with it. I spent a lot of hours being frustrated by XML namespaces (it was the first time I&#8217;d had to use them) and consequently had to move to the forums at <a href="http://www.actionscript.org/forums/showthread.php3?t=165569&amp;highlight=google+xml" target="_blank">actionscript.org</a>. I was helped by a guy with the alias &#8220;wvxvw&#8221; (which is a nice palendrome, lol) so I&#8217;d like to extend credit to him for giving me a nudge in the right direction. Anyway, lets get on to the code.<span id="more-21"></span></p>
<p>First things first you need a URLLoader object to load Google Calendar&#8217;s xml. This looks like:</p>
<pre lang="actionscript">var xmlReq:URLRequest = new URLRequest(xmlURL);
var xmlLoader:URLLoader = new URLLoader(xmlReq);

xmlLoader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
xmlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
xmlLoader.addEventListener(Event.COMPLETE, xmlGCALLoaded);</pre>
<p>To pass the XML&#8217;s URL to the URLLoader you need to use the URLRequest class, but its really simple because the constructor takes your URL as an argument so its only one line of code. In fact, if you want it even shorter you could do this:</p>
<pre lang="actionscript">var xmlLoader:URLLoader = new URLLoader(new URLRequest(xmlURL));</pre>
<p>Either way is fine, obviously. Its important to note here that I am using the &#8220;full&#8221; version of the code that Google Calendar passes to you. If you use the basic you will find it much more difficult to work with the event startTime and endTime. After that be sure to add the proper Event Listeners. The IOError will be thrown if the URL doesn&#8217;t return any data (and perhaps for some other reasons too that I don&#8217;t know about). The Security Error is thrown when you violate your sandbox (which is a complicated idea, you should look it up if you&#8217;d like more info). And of course, the Event.COMPLETE is what is triggered when the data is finished loading, which takes us to the next block of code:</p>
<pre lang="actionscript">private function xmlGCALLoaded(evt:Event):void {
var xmlData:XML = XML(evt.target.data);
   var ns:Namespace = xmlData.namespace();
}</pre>
<p>In this function we take the supplied data (our XML) which is noted as &#8220;evt.target.data&#8221; and put it into the xmlData variable. Using the method supplied by the XML class we can access the first namespace available to us and place it into the &#8220;ns&#8221; variable. A namespace in XML is denoted by a tag attribute &#8220;xmlns&#8221; for instance in google&#8217;s opening tag:</p>
<p>This will be useful when we try to access different parts of the XML google has given us. From this first namespace we call any of the properties about the calendar it&#8217;s self such as the author or id:</p>
<pre lang="actionscript">var author:String = xmlData.ns::author;</pre>
<p>However, I imagine the primary reason you want this XML data is to access the &#8220;entry&#8221;, better known as the calendar events. To do this you&#8217;ll want to make another namespace (there is a deeper namespace level for accessing events and event properties). In AS3 we find out how many &#8220;entry&#8221; tags there are, loop through them, and pull the info that we want from it and place them into array or objects or whatever we&#8217;d like:</p>
<pre lang="actionscript">var numEntries:int = xmlData.ns::entry.length();
var xmlObj:Object;

for (var j:int=0; j&lt;numEntries; j++) {
   var gdns:Namespace = xmlData.ns::entry[j].namespace("gd");
   xmlObj = new Object();
   xmlObj.eventTitle = xmlData.ns::entry[j].children().(name().localName == "title");
   xmlObj.startDate = createXMLDate( xmlData.ns::entry[j].gdns::when.@startTime );
   xmlObj.endDate = createXMLDate( xmlData.ns::entry[j].gdns::when.@endTime );
   xmlObj.eventWhere = xmlData.ns::entry[j].gdns::where.@valueString;
   entries.push(xmlObj);
}</pre>
<p>We get the number of entries from the first namespace&#8217;s entry.length() which is a function provided by the XML Class. Then we loop those entries and for each one find the new namespace (also, this namespace was provided for us in the first tag, I just chose to do it this way instead). With this new namespace we are able to access the inner node of the given entry. The use of the &#8220;@&#8221; symbol lets us access the attributes of the tags, which is where the data we are seeking is. Anyway, once you have looped all the entries they are available to you in an easy to use array format.</p>
<p>If you&#8217;d like to see the <strong>full working AS3 Class for the Google XML Parser</strong>, you can <strong>download </strong>it from this link:<a href="http://www.kylebrekke.com/wordpress/wp-content/uploads/2008/04/googlecalendarxml.as"> googleCalendarXML Class</a></p>
<p>The rar&#8217;d version (<strong>includes the .fla</strong> for compilation) can be found from this link:<a href="http://www.kylebrekke.com/wordpress/wp-content/uploads/2008/04/google_calendar_xml_proj.rar">gCalXML Project</a></p>
<p>To see a <strong>full project</strong> that implements this <strong>Google Calendar XML Parser</strong>, click <a href="http://www.kylebrekke.com/wordpress/2008/a-dynamic-flash-as3-calendar-that-parses-basic-xml-and-google-calendar-events-in-atom-xml-and-ical-format/">here</a>.</p>
<p><a href="http://sharethis.com/item?&wp=2.9.2&amp;publisher=&amp;title=Parsing+Google+Calendar+XML+in+Flash+CS3+AS3&amp;url=http%3A%2F%2Fas3.kylebrekke.com%2F%3Fp%3D21">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://as3.kylebrekke.com/?feed=rss2&amp;p=21</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
