<?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"
	>

<channel>
	<title>Flash Blog by Jon Danao</title>
	<atom:link href="http://danao.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://danao.org</link>
	<description>Adobe Flash, ActionScript, Flex, FlashLite, AIR resource site... Straight from the Philippines!</description>
	<pubDate>Wed, 05 Nov 2008 12:19:39 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
	<language>en</language>
			<item>
		<title>Google Maps + Flex with Overlays</title>
		<link>http://danao.org/2008/08/06/google-maps-flex-with-overlays/</link>
		<comments>http://danao.org/2008/08/06/google-maps-flex-with-overlays/#comments</comments>
		<pubDate>Wed, 06 Aug 2008 01:57:23 +0000</pubDate>
		<dc:creator>jondanao</dc:creator>
		
		<category><![CDATA[ActionScript 3]]></category>

		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://danao.org/2008/08/06/googlemaps-flex-with-overlays/</guid>
		<description><![CDATA[
&#1082;&#1086;&#1083;&#1080; &#1087;&#1086;&#1076; &#1085;&#1072;&#1077;&#1084;GoogleMaps API makes it really easy to place typical overlay objects onto the map like lines, markers, polygons and images (as ground overlays). In this article, we&#8217;ll plot Polylines, Markers and Polygons. GroundOverlay maybe included in the next topic as I still can&#8217;t figure out what image to use.
As I&#8217;ve said, plotting these [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://danao.org/blog/wp-content/uploads/2008/08/googlemaps2.jpg" alt="Google Maps Overlays" /></p>
<p><a href="http://code.google.com/apis/maps/documentation/flash/reference.html" target="_blank"><font style="position: absolute;overflow: hidden;height: 0;width: 0"><a href="http://sikongroup.com/rentacar/index.htm">&#1082;&#1086;&#1083;&#1080; &#1087;&#1086;&#1076; &#1085;&#1072;&#1077;&#1084;</a></font>GoogleMaps API</a> makes it really easy to place typical overlay objects onto the map like lines, markers, polygons and images (as ground overlays). In this article, we&#8217;ll plot Polylines, Markers and Polygons. GroundOverlay maybe included in the next topic as I still can&#8217;t figure out what image to use.</p>
<p>As I&#8217;ve said, plotting these types of objects are very easy to do. For Markers, you only need 1 point of longitude/latitude values. For Polylines, you need at least 2 points. For Polygons, you need at least 3. Since Polylines and Polygons need more than 1 point (lat,lng) they require values placed in arrays. After that, just invoke the addOverlay() method then you&#8217;re done!</p>
]]></content:encoded>
			<wfw:commentRss>http://danao.org/2008/08/06/google-maps-flex-with-overlays/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Google Maps + Flex (Basic)</title>
		<link>http://danao.org/2008/05/28/google-maps-flex-basic/</link>
		<comments>http://danao.org/2008/05/28/google-maps-flex-basic/#comments</comments>
		<pubDate>Wed, 28 May 2008 07:31:01 +0000</pubDate>
		<dc:creator>jondanao</dc:creator>
		
		<category><![CDATA[ActionScript 3]]></category>

		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://danao.org/2008/05/28/google-maps-flex-basic/</guid>
		<description><![CDATA[
Since the release of Google Maps API for Flash, I wanted to start incorporating this free service in my apps as I&#8217;ve seen a lot of good examples being built around. One thing to take note is this ActionScript API will only work in Flex and not in your usual Flash app.
Google API Key
Before you [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://danao.org/blog/wp-content/uploads/2008/05/googlemaps1.jpg" title="googlemaps1.jpg" alt="googlemaps1.jpg" align="left" vspace="10" /></p>
<p>Since the release of <a href="http://code.google.com/apis/maps/documentation/flash/" target="_blank">Google Maps API for Flash</a>, I wanted to start incorporating this free service in my apps as I&#8217;ve seen a lot of good examples being built around. One thing to take note is this <strong>ActionScript API will only work in Flex</strong> and not in your usual Flash app.</p>
<p><strong>Google API Key</strong></p>
<p>Before you can even start coding, you need sign up for an API key so you can use their free service. Get the key <a href="http://code.google.com/apis/maps/signup.html" target="_blank">here</a>. You can get as many keys as you want using only 1 Google account. That being said, let&#8217;s get 2 keys instead - 1 for your site (http://www.mysite.com) and 1 for your local development server (http://localhost). This makes testing much faster rather than you constantly uploading files to your production server.</p>
<p><strong>Google Maps API</strong></p>
<p>Download the Google Maps API for <strike>Flash</strike> (Flex) <a href="http://maps.googleapis.com/maps/flash/release/sdk.zip" title="Google Maps API for Flash" target="_blank">here</a>.</p>
<p>Next, unzip this archive file and you&#8217;ll see docs and lib folders. Inside the lib folder, there exists the map_flex_1_3.swc Flash component. Drag and drop this to the &#8220;libs&#8221; folder in your Flex project. Now you&#8217;re ready to code.</p>
<p><span id="more-28"></span></p>
<p><strong>Code</strong></p>
<pre>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init(event)"&gt;

	&lt;mx:Script&gt;
		&lt;![CDATA[
			import com.google.maps.*;

			private var map:Map;
			private var mapZoom:uint = 5;
			private var defaultLatLng:LatLng = new LatLng(12, 122);

			private function init(event:Event):void
			{
				map = new Map();
				map.key = "ABQIAAAAxlyBsnIB7ByoEzHxPqwrxBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxRMsh6FE492FPeqacWKcMUwMDjw0w"; // localhost
				map.addEventListener(MapEvent.MAP_READY, mapReadyHandler);

				mapDisplay.addChild(map);
			}

			private function mapReadyHandler(event:MapEvent):void
			{
				map.setCenter(defaultLatLng, mapZoom, MapType.PHYSICAL_MAP_TYPE);
			}

			private function mapResizeHandler(event:Event):void
			{
 			    map.setSize(new Point(mapDisplay.width, mapDisplay.height));
 			}

		]]&gt;
	&lt;/mx:Script&gt;	

	&lt;mx:UIComponent id="mapDisplay" width="100%" height="100%" resize="mapResizeHandler(event)" /&gt;

&lt;/mx:Application&gt;</pre>
<p><strong>Demo App</strong></p>
<p><a href="http://danao.org/demo-apps/google-maps/" target="_blank">http://danao.org/demo-apps/google-maps/</a> &#8212; just right-click then view source. We will try to plot some overlay markers on the map in the next article.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://danao.org/2008/05/28/google-maps-flex-basic/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Flex Custom Events and Data Transfer Objects (DTO)</title>
		<link>http://danao.org/2008/03/15/flex-custom-events-and-data-transfer-objects-dto/</link>
		<comments>http://danao.org/2008/03/15/flex-custom-events-and-data-transfer-objects-dto/#comments</comments>
		<pubDate>Fri, 14 Mar 2008 16:11:25 +0000</pubDate>
		<dc:creator>jondanao</dc:creator>
		
		<category><![CDATA[ActionScript 3]]></category>

		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://danao.org/2008/03/15/flex-custom-events-and-data-transfer-objects-dto/</guid>
		<description><![CDATA[Using Custom Events and DTOs are a way to move data around the application. With Flex&#8217;s event-driven architecture, a component can trigger an event and have it carry some data. This data will be encapsulated in a Data Transfer Object which most of these programmers consider as &#8220;dumb object&#8221; simply because it only serves as [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://danao.org/blog/wp-content/uploads/2008/03/custom_events.gif" title="custom_events.gif" alt="custom_events.gif" align="left" />Using Custom Events and DTOs are a way to move data around the application. With Flex&#8217;s event-driven architecture, a component can trigger an event and have it carry some data. This data will be encapsulated in a Data Transfer Object which most of these programmers consider as &#8220;dumb object&#8221; simply because it only serves as a data holder and does nothing more&#8230; no functionalities, no extra processing.</p>
<p>I would like to make this explanation and the accompanying codes AS SIMPLE AS POSSIBLE. I won&#8217;t be concerned with the aesthetics of the sample application, I&#8217;d like you to see it in barebones. So don&#8217;t complain if the app is ugly. <img src='http://danao.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> For this discussion, let&#8217;s try to make a basic contact/email form. It should have fields for the recipient, sender, subject and body. This will not send the actual email but for purposes of demonstration, we&#8217;ll just populate the gathered data into another component.<br />
<span id="more-25"></span></p>
<p><strong>What we need:</strong></p>
<ul>
<li><strong>MainApp.mxml</strong> - this is always required. Place this at the <em>root </em>of your source folder.</li>
<li><strong>EmailForm.mxml</strong> - this a component and contains all the text fields and submit button. Place this under the <em>&#8220;views&#8221;</em> folder.</li>
<li><strong>EmailEvent.as</strong> - this is our custom event. Place this under the <em>&#8220;events&#8221;</em> folder.</li>
<li><strong>EmailDTO.as</strong> - this is our data transfer object which holds all data gathered from the email form. Place this under the <em>&#8220;dto&#8221;</em> folder.</li>
</ul>
<p><strong>EmaiDTO.as</strong></p>
<p>This is the easiest to write&#8230; very straightforward. We know that in our email form we have the typical fields for sender, recipient, subject and body. These will be the basis for our DTO&#8217;s properties. Assign a <strong>public </strong><a href="http://blog.oinam.com/2005/access-modifiers-in-actionscript-30/" target="_blank">access modifier</a> to all these properties. Make this class <a href="http://flexblog.faratasystems.com/?p=300" target="_blank"><strong>bindable</strong></a>.</p>
<pre lang="actionscript">//EmailDTO.as
package dto
{
	[Bindable]
	public class EmailDTO
	{
		public var sender:String;
		public var recipient:String;
		public var subject:String;
		public var body:String;

		public function EmailDTO(sender:String, recipient:String, subject:String, body:String)
		{
			this.sender = sender;
			this.recipient = recipient;
			this.subject = subject
			this.body = body;
		}
	}
}
</pre>
<p><strong>EmailEvent.as</strong></p>
<p>Another straightforward coding. When instantiating this event class, you need to supply the <strong>data </strong>which is the DTO itself and the <strong>type </strong>which you can define with anything you like. Invoke the <a href="http://livedocs.adobe.com/flex/2/langref/flash/events/Event.html#clone()" target="_blank">clone()</a> method to allow event bubbling.</p>
<pre lang="actionscript">//EmailEvent.as
package events
{
	import dto.EmailDTO;
	import flash.events.Event;

	public class EmailEvent extends Event
	{
		public var data:EmailDTO;

		public function EmailEvent(data:EmailDTO, type:String)
		{
			super(type);
			this.data = data;
		}

		override public function clone():Event
		{
			return new EmailEvent(data, type);
		}
	}
}
</pre>
<p><strong>EmailForm.mxml</strong></p>
<p>This is where you build your form with UI elements. At the top of the code, define a new event name in the Metadata for this component - in my case I wrote &#8220;onSendEmail&#8221;. I&#8217;m still used to the old style events - onPress, onClick, onLoad - anything with the &#8220;on&#8221; prefix. </p>
<p>In the event handler submitForm(), instantiate a new DTO with the data inside the form elements. Instantiate a new event supplying the DTO and the new event name (defined in the Metadata). Dispatch this event.</p>
<pre lang="xml"><?xml version="1.0" encoding="utf-8"?>
<mx:Form xmlns:mx="http://www.adobe.com/2006/mxml">

	<mx:Metadata>
		[Event(name="onSendEmail", type="events.EmailEvent")]
	</mx:Metadata>

	<mx:Script>
		<![CDATA[
			import dto.EmailDTO;
			import events.EmailEvent;

			private function submitForm():void
			{
				var dto:EmailDTO = new EmailDTO(tiSender.text, tiRecipient.text, tiSubject.text, taBody.text);
				var event:EmailEvent = new EmailEvent(dto, "onSendEmail");
				dispatchEvent(event);
			}
		]]&gt;
	</mx:Script>

	<mx:FormItem label="From:">
		<mx:TextInput id="tiSender"/>
	</mx:FormItem>

	<mx:FormItem label="To:">
		<mx:TextInput id="tiRecipient"/>
	</mx:FormItem>

	<mx:FormItem label="Subject:">
		<mx:TextInput id="tiSubject"/>
	</mx:FormItem>

	<mx:FormItem label="Message:">
		<mx:TextArea id="taBody"/>
	</mx:FormItem>

	<mx:FormItem>
		<mx:Button label="Submit" click="submitForm()"/>
	</mx:FormItem>

</mx:Form>
</pre>
<p><strong>MainApp.mxml</strong><br />
Lay your components down.  To be able to use your EmailForm component in the views folder, define a namespace the application - <strong>xmlns:view=&#8221;views.*&#8221;</strong>. You can now use the onSendEmail event. This event will be the carrier of the form data.</p>
<pre lang="xml"><?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:view="views.*" layout="vertical" backgroundGradientColors="[#FFFFFF,#FFFFFF]">

	<mx:Script>
		<![CDATA[
			import events.EmailEvent;

			private function sendEmail(event:EmailEvent):void
			{
				taEmailOutput.htmlText += "<b>From:</b> " + event.data.sender + "\\n";
				taEmailOutput.htmlText += "<b>To:</b> " + event.data.recipient + "\\n";
				taEmailOutput.htmlText += "<b>Subject:</b> " + event.data.subject + "\\n";
				taEmailOutput.htmlText += "<b>Message:</b> " + event.data.body + "\\n";
			}
		]]&gt;
	</mx:Script>

	<view:EmailForm onSendEmail="sendEmail(event)" />
	<mx:Label text="Email Output"/>
	<mx:TextArea id="taEmailOutput" width="250" height="250"/>

</mx:Application>
</pre>
<p><em><strong>Note:</strong></em><br />
<em>You might think that it&#8217;s a lot harder to create DTOs and Custom Events for such a simple application like this. But when you integrate your Flex app with a database, you can take advantage of class mapping or do reflection between the client and the server. The DTO can have properties same as the database&#8217;s column definition in a particular table.</em></p>
<p><em>For advanced reading, try Yakov Fain&#8217;s discussion in using a <a href="http://flex.sys-con.com/read/486677_2.htm" target="_blank">Single Event Class approach</a>.</em></p>
<p><strong>Demos &#038; Downloads</strong><br />
<a href="http://danao.org/demo-apps/custom-events/MainApp.html" target="_blank">http://danao.org/demo-apps/custom-events/MainApp.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://danao.org/2008/03/15/flex-custom-events-and-data-transfer-objects-dto/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Movie Utilities Panel Extension</title>
		<link>http://danao.org/2008/02/22/movie-utilities-panel-extension/</link>
		<comments>http://danao.org/2008/02/22/movie-utilities-panel-extension/#comments</comments>
		<pubDate>Fri, 22 Feb 2008 13:28:50 +0000</pubDate>
		<dc:creator>jondanao</dc:creator>
		
		<category><![CDATA[ActionScript 3]]></category>

		<category><![CDATA[Extensions/JSFL]]></category>

		<guid isPermaLink="false">http://www.danao.org/2008/02/22/movie-utilities-panel-extension/</guid>
		<description><![CDATA[After viewing Lee Brimelow&#8217;s tutorial in building Custom Flash Panels, I thought I&#8217;d take a crack at the Flash JavaScript API because I usually have a pretty standard way of setting up my default movies. This is my first attempt so definitely there&#8217;s a lot of room for improvement.
There are currently 2 buttons in the [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.danao.org/blog/wp-content/uploads/2008/02/movie_utilities.gif" title="Movie Utilities" alt="Movie Utilities" align="left" />After viewing <a href="http://www.theflashblog.com" target="_blank">Lee Brimelow</a>&#8217;s tutorial in building <a href="http://www.gotoandlearn.com/player.php?id=66" target="_blank">Custom Flash Panels</a>, I thought I&#8217;d take a crack at the <a href="http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/js/html/wwhelp.htm?href=00003831.html" title="LiveDocs: JavaScript API" target="_blank">Flash JavaScript API</a> because I usually have a pretty standard way of setting up my default movies. This is my first attempt so definitely there&#8217;s a lot of room for improvement.</p>
<p>There are currently 2 buttons in the panel - one to setup the movie and the other to insert a distribution licence agreement, which I normally do not put in my code but I thought it&#8217;ll be useful for other developers. I should start including this in my codes. <img src='http://danao.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
<span id="more-21"></span></p>
<p><strong> Setup Movie</strong></p>
<p><img src="http://www.danao.org/blog/wp-content/uploads/2008/02/movie_utilities_setup.gif" title="movie_utilities_setup.gif" alt="movie_utilities_setup.gif" align="right" />This function will create 3 layers on top of the default &#8220;Layer 1&#8243;:</p>
<ul>
<li>Logic (folder)</li>
<li>Stops (normal)</li>
<li>Scripts (normal)</li>
</ul>
<p>Both Stops and Scripts layers will have Logic as their <a href="http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&amp;file=00004516.html" title="LiveDocs: parentLayer" target="_blank">parentLayer</a> property. But before assigning a parentLayer, you should first access which layers you want this to be associated with through the <a href="http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&amp;file=00004542.html#wp134235" title="LiveDocs: layers" target="_blank">layers</a> property - a property returning an &#8220;array of layer objects&#8221;. One very important thing that LiveDocs failed to mention is the layers property reads timeline layers from top to bottom - so the top-most layer is index zero. But when you add layers using <a href="http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&amp;file=00004542.html#wp134235" title="LiveDocs: addNewLayer()" target="_blank">addNewLayer()</a> method it naturally adds a new layer on top of the current layer. Each new added layer will have an index zero.</p>
<p><img src="http://www.danao.org/blog/wp-content/uploads/2008/02/movie_utilities_library.gif" title="movie_utilities_library.gif" alt="movie_utilities_library.gif" align="left" />Here is where I got really confused. I always thought that when you add an item to a stack in an array, by default it should call Array.push(). But not in this case.</p>
<p>Logic folder layer will be locked and all child layers will inherit this property.</p>
<p>The Setup Movie button also adds folders into the library for better organization of assets. It modifies the stage properties:</p>
<ul>
<li>width: 1000</li>
<li>height: 600</li>
<li>frameRate: 30</li>
</ul>
<p><strong>Insert Licence</strong></p>
<p>Most codes I download over the internet have an attached distribution agreement and most of them are very long - occupying several lines. This will cause a problem when you set this long text - with carriage returns and special characters - as a string value to a variable. ActionScript will throw an error. <a href="http://dougmccune.com/blog/2007/05/15/multi-line-strings-in-actionscript-3/" target="_blank">Doug McCune</a> has a neat trick to this problem - encapsulate the text in CDATA sections.</p>
<pre>var longText:String = String(&lt;![CDATA[
	The quick brown
	fox jumped over
	the lazy dog.
]]&gt;);</pre>
<p>The 2nd problem. This text still has carriage returns and special characters. Escaping each special character by brute force defeats the purpose of programming. Here&#8217;s my little function utilizing RegExp.</p>
<pre>function formatJSFL(str:String):String
{
	var pattern:RegExp;
	var replace:String;
	var formattedString:String = str;

	// forward slashes
	pattern = /\//g;
	replace = '\/';
	formattedString = formattedString.replace(pattern, replace);

	// back slashes
	pattern = /\\/g;
	replace = '\\\\';
	formattedString = formattedString.replace(pattern, replace);

	// double quotes
	pattern = /\"/g;
	replace = '\"';
	formattedString = formattedString.replace(pattern, replace);

	// single quotes
	pattern = /\'/g;
	replace = '\\\'';
	formattedString = formattedString.replace(pattern, replace);

	// asterisks
	pattern = /\*/g;
	replace = '\\*';
	formattedString = formattedString.replace(pattern, replace);

	// colons
	pattern = /\:/g;
	replace = "\\\:";
	formattedString = formattedString.replace(pattern, replace);

	// carriage return
	pattern = /\r/g;
	replace = "";
	formattedString = formattedString.replace(pattern, replace);

	// new line feed
	pattern = /\n/g;
	replace = "\\n";
	formattedString = formattedString.replace(pattern, replace);

	return formattedString;
}
</pre>
<p>And here&#8217;s how this text should look like. I got this from one of <a href="http://www.gskinner.com/blog/" title="Grant Skinner" target="_blank">Grant Skinner&#8217;s</a> FLAs. I modified it a bit&#8230; (dude, I hope you don&#8217;t mind.)</p>
<pre>/*******************************************************************
* Application Name:
* Author:
* Date:
* Version:
* Website:
* Email Address:
* Country:
* Notes:
*
*
*
* Copyright (c) [YYYY] [Author Name]
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
********************************************************************/</pre>
<p>The next thing I want to happen is to be able to insert this licence agreement into an ActionScript file. I can&#8217;t figure out how to do this.</p>
<p><strong>Installation</strong></p>
<p>Copy and paste the Movie Utilities.swf into C:\Documents and Settings\{user}\Local Settings\Application Data\Adobe\Flash CS3\en\Configuration\WindowSWF. </p>
<p>In your Flash IDE, select Window > Other Panels > Movie Utilities. </p>
<p>Get the <a href="http://www.danao.org/flashsource/MovieUtilities.rar" target="_blank">source here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://danao.org/2008/02/22/movie-utilities-panel-extension/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Drag n&#8217; Drop in AS3</title>
		<link>http://danao.org/2007/12/03/drag-n-drop-in-as3/</link>
		<comments>http://danao.org/2007/12/03/drag-n-drop-in-as3/#comments</comments>
		<pubDate>Mon, 03 Dec 2007 09:41:39 +0000</pubDate>
		<dc:creator>jondanao</dc:creator>
		
		<category><![CDATA[ActionScript 3]]></category>

		<guid isPermaLink="false">http://www.danao.org/2007/12/03/drag-n-drop-in-as3/</guid>
		<description><![CDATA[
	
I used to teach drag-n-drop funtionality using startDrag() and stopDrag() MovieClip methods. This is the easiest and fastest way but it tends to be choppy when the framerate is low. To solve this problem, you should employ MOUSE_MOVE event as shown in this tutorial by Flash and Math.
Their tutorial is great and I&#8217;ll use their [...]]]></description>
			<content:encoded><![CDATA[<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="495" height="300" id="drag_and_drop" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="false" /><param name="movie" value="/flashsource/drag_and_drop.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="/flashsource/drag_and_drop.swf" quality="high" bgcolor="#ffffff" width="495" height="300" name="drag_and_drop" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /><br />
	</object></p>
<p>I used to teach drag-n-drop funtionality using startDrag() and stopDrag() MovieClip methods. This is the easiest and fastest way but it tends to be choppy when the framerate is low. To solve this problem, you should employ <strong>MOUSE_MOVE</strong> event as shown in this <a href="http://www.flashandmath.com/basic/dragdroptour/dd_tour1.html" title="Drag and Drop by Flash and Math" target="_blank">tutorial by Flash and Math</a>.</p>
<p>Their tutorial is great and I&#8217;ll use their concept in this article. But I don&#8217;t want the draggable object to snap to its center when dragging. I&#8217;ll put in a <strong>lockcenter </strong>option and a <strong>swapDepths()</strong> alternative.</p>
<p><strong>Notes:</strong></p>
<ul>
<li>We capture the broadcasted MOUSE_MOVE event from the stage and not from the draggable object. This ensures it will keep on dragging even if the mouse cursor moves outside the object. I guess Flash and Math already explained this.</li>
<li>1 is subtracted from numChildren because children are placed in an Array thus child index is length-1.</li>
<li>updateAfterEvent() just makes things a lot smoother.</li>
</ul>
<p>Here&#8217;s the code:</p>
<pre lang="actionscript">
var object:Sprite;
var offsetX:Number;
var offsetY:Number;
var snapToCenter:Boolean = false;

for(var i:uint = 0; i < 20; i++)
{
	var newColor:uint = Math.random() * 0xFFFFFF;
	var newX:Number = Math.random() * stage.stageWidth;
	var newY:Number = Math.random() * stage.stageHeight;
	var newRadius:Number = Math.random() * 50 + 20;

	var sprite:Sprite = new Sprite();
	sprite.graphics.beginFill(newColor);
	sprite.graphics.drawCircle(0, 0, newRadius);
	sprite.graphics.endFill();
	sprite.x = newX;
	sprite.y = newY;
	sprite.buttonMode = true;
	sprite.addEventListener(MouseEvent.MOUSE_DOWN, drag);
	sprite.addEventListener(MouseEvent.MOUSE_UP, drop);

	addChild(sprite);
}

function drag(e:MouseEvent):void
{
	stage.addEventListener(MouseEvent.MOUSE_MOVE, move);
	object = e.target as Sprite;
	swap(e.target);
}

function drop(e:MouseEvent):void
{
	stage.removeEventListener(MouseEvent.MOUSE_MOVE, move);
}

function swap(o:*):void
{
	var highestDepth:uint = numChildren - 1;
	setChildIndex(o, highestDepth);

	if(snapToCenter)
	{
		offsetX = 0;
		offsetY = 0;

		o.x = mouseX;
		o.y = mouseY;
	}
	else
	{
		offsetX = o.x - mouseX;
		offsetY = o.y - mouseY;
	}
}

function move(e:MouseEvent):void
{
	object.x = mouseX + offsetX;
	object.y = mouseY + offsetY;
	e.updateAfterEvent();
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://danao.org/2007/12/03/drag-n-drop-in-as3/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Pixelizer using BitmapData Class</title>
		<link>http://danao.org/2007/11/12/pixelizer-using-bitmapdata-class/</link>
		<comments>http://danao.org/2007/11/12/pixelizer-using-bitmapdata-class/#comments</comments>
		<pubDate>Mon, 12 Nov 2007 06:36:11 +0000</pubDate>
		<dc:creator>jondanao</dc:creator>
		
		<category><![CDATA[ActionScript 3]]></category>

		<guid isPermaLink="false">http://www.danao.org/2007/11/12/pixelizer-using-bitmapdata-class/</guid>
		<description><![CDATA[I am trying to recreate the Pixelizer plugin by Joe&#8217;s Filters. This will be a work-in-progress. I&#8217;m planning to include several things into this class like different shapes for the block, color averaging, blur effect, random rotation, jitter, etc.


Download the source here.
]]></description>
			<content:encoded><![CDATA[<p>I am trying to recreate the Pixelizer plugin by <a href="http://www.joesfilters.com/joes_pixelizer" target="_blank">Joe&#8217;s Filters</a>. This will be a work-in-progress. I&#8217;m planning to include several things into this class like different shapes for the block, color averaging, blur effect, random rotation, jitter, etc.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="495" height="330" id="01" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="false" /><param name="movie" value="/flashsource/Pixelizer.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#FFFFFF" /><embed src="/flashsource/Pixelizer.swf" quality="high" bgcolor="#FFFFFF" width="495" height="330" name="01" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p></object></p>
<p>Download the source <a href="/flashsource/pixelizer.rar?PHPSESSID=e6fa269a0abf916d1e1369f98cf6a6f0" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://danao.org/2007/11/12/pixelizer-using-bitmapdata-class/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Sound Visualization</title>
		<link>http://danao.org/2007/11/02/sound-visualization/</link>
		<comments>http://danao.org/2007/11/02/sound-visualization/#comments</comments>
		<pubDate>Fri, 02 Nov 2007 05:55:54 +0000</pubDate>
		<dc:creator>jondanao</dc:creator>
		
		<category><![CDATA[ActionScript 3]]></category>

		<guid isPermaLink="false">http://www.danao.org/2007/11/02/sound-visualization/</guid>
		<description><![CDATA[
Here&#8217;s my first take on using the SoundMixer and ByteArray classes to create a simple sound visualization app. After reading tutorials on this topic, I discovered that there are a few basic things you need to get started.

Sound object to hold the sound
ByteArray object to hold the spectrum data
Renderer function to extract and draw the [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.danao.org/blog/wp-content/uploads/2007/11/soundvisualizer_screencap2.gif" title="Sound Visualizer ScreenCap" alt="Sound Visualizer ScreenCap" height="200" width="495" /></p>
<p>Here&#8217;s my first take on using the SoundMixer and ByteArray classes to create a simple sound visualization app. After reading <a href="http://ultrashock.com/tutorials/flash8/spectrum.php" target="_blank" title="Ultrashock tutorial">tutorials</a> on this topic, I discovered that there are a few basic things you need to get started.</p>
<ul>
<li>Sound object to hold the sound</li>
<li>ByteArray object to hold the spectrum data</li>
<li>Renderer function to extract and draw the visualization</li>
<li>Timer object to constantly refresh the spectrum data:</li>
</ul>
<p>I used a MovieClip with a gradient fill as my base color for the equalizer and a Sprite with bars (drawn using the Drawing API) as the mask for the colors. The gradient fill can be drawn programmatically but I&#8217;m too lazy to do that now. <img src='http://danao.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Download the <a href="/flashsource/SoundVisualizer.fla?PHPSESSID=e6fa269a0abf916d1e1369f98cf6a6f0" target="_blank" title="Sound Visualizer source">source</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://danao.org/2007/11/02/sound-visualization/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Chart Label Rotation</title>
		<link>http://danao.org/2007/06/25/chart-label-rotation/</link>
		<comments>http://danao.org/2007/06/25/chart-label-rotation/#comments</comments>
		<pubDate>Tue, 26 Jun 2007 02:50:53 +0000</pubDate>
		<dc:creator>jondanao</dc:creator>
		
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.danao.org/2007/06/25/chart-label-rotation/</guid>
		<description><![CDATA[The Flex&#8217;s Charting component has a property called labelRotation that tilts / rotates the chart labels for them not to overlap each other and make a mess of your pretty charts. This will not work automatically. You have to first embed the font outline into Flash and the rotation will finally be applied.
Here&#8217;s the sample [...]]]></description>
			<content:encoded><![CDATA[<p>The Flex&#8217;s Charting component has a property called <strong>labelRotation</strong> that tilts / rotates the chart labels for them not to overlap each other and make a mess of your pretty charts. This will not work automatically. You have to first embed the font outline into Flash and the rotation will finally be applied.</p>
<p>Here&#8217;s the sample code:</p>
<pre lang="xml"><?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">

<mx:Script>
        <![CDATA[
        import mx.collections.ArrayCollection;

        [Bindable] private var dpAmount:ArrayCollection = new ArrayCollection( [
            {Date: "25 Dec 2006", Amount: 4000},
            {Date: "14 Feb 2007", Amount: 3000},
            {Date: "1 Apr 2007", Amount: 5500},
            {Date: "4 July 2007", Amount: 2800},
            {Date: "8 Aug 2007", Amount: 800},
            {Date: "11 Sep 2007", Amount: 2800},
            {Date: "1 Nov 2007", Amount: 3400} ]);
        ]]&gt;
    </mx:Script>

    <mx:Style>
    	@font-face
	{
		fontFamily: myFont;
		src: local("Verdana");
	}

	LineChart
	{
		fontFamily: myFont;
	}
    </mx:Style>

    <mx:LineChart dataProvider="{dpAmount}">

    	<mx:horizontalAxis>
    		<mx:CategoryAxis categoryField="Date" />
    	</mx:horizontalAxis>

    	<mx:horizontalAxisRenderer>
		<mx:AxisRenderer labelRotation="45" />
	</mx:horizontalAxisRenderer>

    	<mx:series>
    		<mx:LineSeries yField="Amount" />
    	</mx:series>

    </mx:LineChart>

</mx:Application>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://danao.org/2007/06/25/chart-label-rotation/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Page-Up, Page-Down Scroll</title>
		<link>http://danao.org/2007/06/21/page-up-page-down-scroll/</link>
		<comments>http://danao.org/2007/06/21/page-up-page-down-scroll/#comments</comments>
		<pubDate>Thu, 21 Jun 2007 07:42:12 +0000</pubDate>
		<dc:creator>jondanao</dc:creator>
		
		<category><![CDATA[ActionScript 3]]></category>

		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.danao.org/2007/06/21/page-up-page-down-scroll/</guid>
		<description><![CDATA[By default, Flex does not implement the PageUp, PageDown, Home, End, ArrowUp and ArrowDown scrolling like most browsers do. These functions will try to make keystroke/keyboard scrolling happen.
First, invoke registerGlobalKeyHandler() upon applicationComplete. Got this from the Adobe Flex Cookbook by Kristopher Schultz.
A point for improvement - this scrolling script will only work  after the [...]]]></description>
			<content:encoded><![CDATA[<p>By default, Flex does not implement the PageUp, PageDown, Home, End, ArrowUp and ArrowDown scrolling like most browsers do. These functions will try to make keystroke/keyboard scrolling happen.</p>
<p>First, invoke <strong>registerGlobalKeyHandler() </strong>upon applicationComplete. Got this from the <a href="http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&amp;postId=304&amp;productId=2&amp;loc=en_US" target="_blank">Adobe Flex Cookbook</a> by Kristopher Schultz.</p>
<p>A point for improvement - this scrolling script will only work  after the user clicks on the flash app itself. I do not know how to set focus on the app after it has loaded. Maybe you can help?</p>
<p>Code:</p>
<pre lang="actionscript">public function registerGlobalKeyHandler() :void
{
	stage.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);
}

public function handleKeyDown(event:KeyboardEvent) :void
{
	var newKeyCode:uint = event.keyCode;

	switch(newKeyCode)
	{
		case 33: // PAGE UP
			Application.application.verticalScrollPosition -= 200;
			break;
		case 34: // PAGE DOWN
			Application.application.verticalScrollPosition += 200;
			break;
		case 35: // END
			Application.application.verticalScrollPosition = Application.application.maxVerticalScrollPosition;
			break;
		case 36: // HOME
			Application.application.verticalScrollPosition = 0;
			break;
		case 38: // UP
			Application.application.verticalScrollPosition -= 50;
			break;
		case 40: // DOWN
			Application.application.verticalScrollPosition += 50;
			break;
	}
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://danao.org/2007/06/21/page-up-page-down-scroll/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Adobe Flex: Second Encounter</title>
		<link>http://danao.org/2007/03/25/adobe-flex-second-encounter/</link>
		<comments>http://danao.org/2007/03/25/adobe-flex-second-encounter/#comments</comments>
		<pubDate>Sun, 25 Mar 2007 10:21:15 +0000</pubDate>
		<dc:creator>jondanao</dc:creator>
		
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.danao.org/blog/2007/03/25/adobe-flex-second-encounter/</guid>
		<description><![CDATA[As I mentioned in the First Encounter, Flex is primarily built for web developers and not designers. The way I see it, it&#8217;s just like writing HTML with JavaScript but with a slight difference. Let&#8217;s take a simple sneak peek to support this claim.
Here we compare HTML and MXML when using a button:
HTML:
 &#60;button name=&#8221;myButton&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>As I mentioned in the <a href="http://www.danao.org/blog/2007/03/24/adobe-flex-first-encounter/">First Encounter</a>, Flex is primarily built for web developers and not designers. The way I see it, it&#8217;s just like writing HTML with JavaScript but with a slight difference. Let&#8217;s take a simple sneak peek to support this claim.</p>
<p>Here we compare HTML and MXML when using a button:</p>
<p><strong>HTML:</strong><br />
<strong> &lt;button name=&#8221;myButton&#8221; onclick=&#8221;processClick()&#8221; class=&#8221;myButtonStyle&#8221;&gt;Click Me&lt;/button&gt;</strong></p>
<p><strong>MXML:</strong><br />
<strong> &lt;mx:Button id=&#8221;myButton&#8221;  click=&#8221;processClick()&#8221; styleName=&#8221;myButtonStyle&#8221; label=&#8221;Click Me&#8221; /&gt;</strong></p>
<p>Let&#8217;s read these two lines of codes. First - <strong>component declaration</strong>(button/mx:button), then <strong>instance name</strong>(name/id), <strong>event</strong>(onclick/click), <strong>event handler</strong>(processClick), <strong>style property</strong>(class/styleName), <strong>style name</strong>(myButtonStyle) and lastly, the <strong>label</strong>. Both of them can use either an inline or linked CSS styles. How cool is that?!</p>
]]></content:encoded>
			<wfw:commentRss>http://danao.org/2007/03/25/adobe-flex-second-encounter/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
