<?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>Simplistika &#187; custom</title>
	<atom:link href="http://simplistika.com/tag/custom/feed/" rel="self" type="application/rss+xml" />
	<link>http://simplistika.com</link>
	<description>Think Simple</description>
	<lastBuildDate>Thu, 13 May 2010 11:48:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Creating Custom Methods in ActionScript 3</title>
		<link>http://simplistika.com/creating-custom-methods-in-actionscript-3/</link>
		<comments>http://simplistika.com/creating-custom-methods-in-actionscript-3/#comments</comments>
		<pubDate>Sat, 09 Feb 2008 04:18:08 +0000</pubDate>
		<dc:creator>jared</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[creating custom]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[property]]></category>
		<category><![CDATA[simplistika]]></category>

		<guid isPermaLink="false">http://jared.simplistika.com/creating-custom-methods-in-actionscript-3/</guid>
		<description><![CDATA[Click here to download the sample files. Methods are simply functions inside a class. Think of a class as an object, lets say a car engine. So here&#8217;s the basic setup for a Car engine class object in ActionScript 3. (CarEngine.as) Open up CarEngine.as. Here we have a class named CarEngine. Inside the class we have [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.simplistika.com/files/Car.zip">Click here to download the sample files.</a></p>
<p>Methods are simply functions inside a class. Think of a class as an object, lets say a car engine.</p>
<p><img src="http://simplistika.com/wp-content/uploads/2008/02/car-150x150.jpg" alt="Car picture" /></p>
<p>So here&#8217;s the basic setup for a Car engine class object in ActionScript 3. (CarEngine.as)</p>
<p>Open up CarEngine.as. Here we have a class named <strong>CarEngine</strong>.</p>
<p>Inside the class we have declared a boolean (boolean returns either a true or false value) variable called <strong>_engineStatus </strong>to check the status of the car engine.</p>
<pre lang="actionscript">public class <strong>CarEngine</strong> extends MovieClip {

     private var _engineStatus:<strong>Boolean</strong>;

     public function CarEngine() {</pre>
<p>Inside the <strong>constructor </strong>(code inside the constructor is executed immediately when the class is initialized) we find the following</p>
<pre lang="actionscript">_engineStatus = false;trace("Car's engine is currently " + this._engineStatus);</pre>
<p>What these two lines do is first declare the _engineStatus (that we declared earlier as a boolean variable) as false, and send a trace statement to return the current value of the car engine.</p>
<p>The next two functions enables the CarEngine class to &#8220;get&#8221; and &#8220;set&#8221; the current status of the engine.</p>
<pre lang="actionscript">public function get engineStatus() {
     return _engineStatus;
}</pre>
<pre lang="actionscript">public function set engineStatus(value) {
     _engineStatus = value;
}</pre>
<p>Now all that&#8217;s left is to call this class from an external source. Open up Car.fla, click on the first frame and press F9 on your keyboard. It should open up the actions panel and you should see some code in there.</p>
<p>The first line initializes an instance of the Car Engine class.</p>
<pre lang="actionscript">var _carEngine:CarEngine = new CarEngine();</pre>
<p>As mentioned above, code inside the constructor is executed immediately when the CarEngine class is initialized. Therefore it should return us a trace statement in the output window, telling us that the engine is <strong>currently false</strong>.</p>
<p>Now lets modify the engine status and change it to true.</p>
<pre lang="actionscript">_carEngine.engineStatus = true;</pre>
<p>And finally lets check if the engine is now true</p>
<pre lang="actionscript">trace("Car's engine is changed to " + _carEngine.engineStatus);</pre>
<p>And it is!</p>
<p><a href="http://www.simplistika.com/files/Car.zip">Click here to download the sample files.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://simplistika.com/creating-custom-methods-in-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
