<?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>Francois Faubert &#187; Actionscript 2</title>
	<atom:link href="http://www.francoisfaubert.com/tag/actionscript-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.francoisfaubert.com</link>
	<description></description>
	<lastBuildDate>Tue, 08 Sep 2009 19:00:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Eureka Follow up</title>
		<link>http://www.francoisfaubert.com/2006/02/07/eureka-follow-up/</link>
		<comments>http://www.francoisfaubert.com/2006/02/07/eureka-follow-up/#comments</comments>
		<pubDate>Tue, 07 Feb 2006 16:38:19 +0000</pubDate>
		<dc:creator>francoisfaubert</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Actionscript 2]]></category>
		<category><![CDATA[Event Delegation]]></category>
		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://themusictank.com/fake/?p=12</guid>
		<description><![CDATA[The use of a static method to delegate events in Flash is one of the easiest ways of associating functions to an event.]]></description>
			<content:encoded><![CDATA[<p>As I mentioned in my last post, the Delegate class is quite useful even if I couldn&#8217;t pass parameters as easily as I would have wanted. While looking around today, I stumbled on <a href="http://www.person13.com/articles/proxy/Proxy.htm">this method</a> which also makes things much easier. I don&#8217;t like how it&#8217;s written because of the in-line functions, but it really does solve the problem. Here&#8217;s the code, which I took the liberty to customize a little bit:</p>
<pre><code>class Utils {
// Desc		:	Usually, when you attach a function to an event, you can't pass
//			parameters, using this function instead of the Delegate class
//			will allow you to do the same thing but with unlimitted parameters
// 			Window: General Information.
// 			http://www.person13.com/articles/proxy/Proxy.htm
public static function delegateEvent(oTarget:Object, fFunction:Function):Function {
    // Create an array of the extra parameters passed to the method. Loop
    // through every element of the arguments array starting with index 2,
    // and add the element to the aParameters array.
    var aParameters:Array = new Array();
    for(var i:Number = 2; i &lt; arguments.length; i++) {
        aParameters[i - 2] = arguments[i];
    }
    // Create a new function that will be the proxy function.
    var fProxy:Function = function():Void {
        var aActualParameters:Array = arguments.concat(aParameters);
        fFunction.apply(oTarget, aActualParameters);
    };
    return fProxy;
}</code></pre>
<p>And you can call it like this:</p>
<pre><code>private function someFunction():Void {
    this._xml.onLoad = Utils.delegateEvent(this, xml_onLoad, "GeneralInformation");
}

private function xml_onLoad(success:Boolean, nextStep:String):Void {
    if(success)
    // Get the contents of xml
    switch (nextStep) {
        case "GeneralInformation" :
            this.open_GeneralInformation(); break;
    //etc...
    }
}</code></pre>
<p>This was a huge time savor and suits how I like to write code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.francoisfaubert.com/2006/02/07/eureka-follow-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eureka!</title>
		<link>http://www.francoisfaubert.com/2006/02/01/eureka/</link>
		<comments>http://www.francoisfaubert.com/2006/02/01/eureka/#comments</comments>
		<pubDate>Wed, 01 Feb 2006 19:13:52 +0000</pubDate>
		<dc:creator>francoisfaubert</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Actionscript 2]]></category>
		<category><![CDATA[Event Delegation]]></category>
		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://themusictank.com/fake/?p=11</guid>
		<description><![CDATA[I’ve been having a lot of trouble having Event (clicks, loads, etc&#8230;) in Flash for as long as I’ve been doing Object-Oriented ActionScript. I barely managed to call inline functions and having to use the absolute path to the property. Example:
class Foo {
	public var _someProperty:String
	public function Foo() {
		// Lets skip how I actually make the [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been having a lot of trouble having Event (clicks, loads, etc&#8230;) in Flash for as long as I’ve been doing Object-Oriented ActionScript. I barely managed to call inline functions and having to use the absolute path to the property. Example:</p>
<pre><code>class Foo {
	public var _someProperty:String
	public function Foo() {
		// Lets skip how I actually make the button,
		// but I usually use .attach() and I make
		// exportable the object in the Library. I
		// think I should use createClassComponent however.
		var but:MovieClip = new MovieClip();
		but.onPress = function () {
		_root.MyFooObject._someProperty = “Clicked”;
		}
	}
}</code></pre>
<p>To access my attribute, I must leave my class and follow the absolute, practically hard-coded, path to my value. It&#8217;s really not a good thing to do. Instead, I found you can use the Delegate class to forward events to a function inside the parent class. Like this:</p>
<pre><code>class Foo {
	private var _someProperty:String
	public function Foo() {
		// Lets skip how I actually make the button here too.
		var but:MovieClip = new movieclip();
		but.onPress = mx.utils.Delegate.create(this, button_onClick);
	}
	private function button_onClick():Void {
		this._someProperty = “Clicked”;
	}
}</code></pre>
<p>Where &#8220;this&#8221; means the class you are in (could be another one), and &#8220;button_onClick&#8221; is the name of the function you will be calling after the event is triggered.</p>
<p>There you go! It’s a lot more powerful, much more logical from a semantic point of view and it makes the code a lot clearer. Notice how I can protect my call properties now using the private attribute.</p>
<p>Speaking of being semantic, you always should call you call properties with &#8220;getters and setters&#8221; instead of calling it directly like I did in my example. It should look like this instead:</p>
<pre><code>private var _someProperty:String
public function get someProperty():String { return this._someProperty;}
public function set someProperty(val:String):Void {
    // validation if needed; this._someProperty = val;
}</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.francoisfaubert.com/2006/02/01/eureka/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mx.transitions.Tween</title>
		<link>http://www.francoisfaubert.com/2005/12/08/mxtransitionstween/</link>
		<comments>http://www.francoisfaubert.com/2005/12/08/mxtransitionstween/#comments</comments>
		<pubDate>Fri, 09 Dec 2005 03:52:05 +0000</pubDate>
		<dc:creator>francoisfaubert</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Actionscript 2]]></category>
		<category><![CDATA[Animation]]></category>
		<category><![CDATA[Tweening]]></category>

		<guid isPermaLink="false">http://themusictank.com/fake/?p=9</guid>
		<description><![CDATA[One of my current assignments at work is to make something similar to Google Maps for my employer’s Oil website. I must build a map browser that is completely dynamic that will need to generate 3 dynamic layers for 3 different types of maps of Oil Wells.
I decided on making this using Flash, just like [...]]]></description>
			<content:encoded><![CDATA[<p>One of my current assignments at work is to make something similar to Google Maps for my employer’s Oil website. I must build a map browser that is completely dynamic that will need to generate 3 dynamic layers for 3 different types of maps of Oil Wells.</p>
<p>I decided on making this using Flash, just like Yahoo Maps have. From the start, the most important feature was how I had to permit a click event somewhere on the map and to center the map on these X and Y coordinates. At first, I approached the project by planning on incrementing a value to the <code>_x</code> and <code>_y</code> properties of the map MovieClip for some period of time to mimic movement until the map was re-centered, but I’ve had no success doing so.</p>
<p>That’s when I had a revelation. Once you start trying to build Object-Oriented applications in Flash, you tend to forget all the design tools built-in Flash. Why didn’t I call the Tween function from within ActionScript? And so I did.</p>
<p>Here’s the relatively simple function call to move a MovieClip object using the Tween class:</p>
<pre><code>new mx.transitions.Tween(MovieClip, "_x", easeType, begin, end, speed of execution, time unit boolean);</code></pre>
<p>You pass on a MovieClip, the property you wish to edit (in Flash, the properties all start with “_”), the effect you wish to use for the transition, the starting value (for the <code>_x</code> property, <code>MovieClip ._x</code> for instance), the end value (passing <code>MovieClip ._x  + 50</code> would create a motion tween that would move the MovieClip 50 pixels to the right from its original location), and the speed of execution which is either counted in seconds or in frames depending on the last Boolean parameter (<code>true</code> meaning seconds).</p>
<p>It’s really flexible and powerful. Passing in a different easing type will allow you to apply built-in elastic or bouncing effects to a MovieClip. Now all of the bouncing menus we see all over the Internet seem much simpler.</p>
<p>You can also pause, rewind and do other operations on the Tween process because it generates events as the animation plays.</p>
<p>It opens a lot of doors to OOP in Flash. You no longer need to bother with sketchy animations when forcing movement on your MovieClips from within a Class.</p>
<p>If you code in Flash and have never come across this function, I strongly suggest you <a href="http://www.designcontest.net/tutorials/tween_easing/index.html ">read more on this undocumented function</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.francoisfaubert.com/2005/12/08/mxtransitionstween/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Love/hate relationship with Flash&#8217;s components</title>
		<link>http://www.francoisfaubert.com/2005/11/12/lovehate-relationship-with-flash%e2%80%99s-components/</link>
		<comments>http://www.francoisfaubert.com/2005/11/12/lovehate-relationship-with-flash%e2%80%99s-components/#comments</comments>
		<pubDate>Sat, 12 Nov 2005 15:11:20 +0000</pubDate>
		<dc:creator>francoisfaubert</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Actionscript 2]]></category>
		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://themusictank.com/fake/?p=5</guid>
		<description><![CDATA[Macromedia have brought a lot more depth into Flash by adding pre-compiled components (or movie clips) to the software&#8217;s library. Mostly available only in the professional edition, these components make building application faster and easier.
One of the components I&#8217;ve played with it the Window object. It&#8217;s simple to understand and it&#8217;s possible to create a [...]]]></description>
			<content:encoded><![CDATA[<p>Macromedia have brought a lot more depth into Flash by adding pre-compiled components (or movie clips) to the software&#8217;s library. Mostly available only in the professional edition, these components make building application faster and easier.</p>
<p>One of the components I&#8217;ve played with it the Window object. It&#8217;s simple to understand and it&#8217;s possible to create a Window on the fly using ActionScript only. Let me put some emphasis on that. Within a few lines, I was able to program my way into a graphic application. We can all agree that&#8217;s the goal behind the general direction Macromedia is taking and to a certain extent they are succeeding in doing so.</p>
<p>However, other components are much harder to instantiate or create/call straight from ActionScript. The documentation on Live Docs is also somewhat deficient. I&#8217;ve tried a gazillion times to have the XML connector work when created dynamically but couldn&#8217;t make it work yet. The media playback was a bit easier to build with dynamic values, but as I write this, the Mp3 player on The Music Tank still has trouble opening .mp3 files consistently.</p>
<p>What I hate about components is how I never know if it&#8217;s my fault if it&#8217;s not working. If it is (which is probably the case) there are two questions I can rarely find answers for:</p>
<ul>
<li>Am I supplying invalid values which failed validation once the control is speaking with my website? And</li>
<li> Is the control not working because I instantiated its properties with wrong values?</li>
</ul>
<p>I hope Flex will make it easier for graphic artists who are able to do real Object-Oriented programming. Right now, I feel pretty dumb having to use illogical code just to make up for Flash&#8217;s &#8220;almost-there&#8221; programming language.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.francoisfaubert.com/2005/11/12/lovehate-relationship-with-flash%e2%80%99s-components/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
