<?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>Lon Hosford&#039;s Bitbox &#187; Adobe</title>
	<atom:link href="http://www.lonhosford.com/lonblog/category/technologies/adobe/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lonhosford.com/lonblog</link>
	<description>Lon (Alonzo) Hosford&#039;s Professional Consulting Blog</description>
	<lastBuildDate>Fri, 03 Feb 2012 00:55:07 +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>Tap, Move, Shake: Turning Your Game Ideas into iPhone &amp; iPad Apps</title>
		<link>http://www.lonhosford.com/lonblog/2012/01/22/tap-move-shake-turning-your-game-ideas-into-iphone-ipad-apps/</link>
		<comments>http://www.lonhosford.com/lonblog/2012/01/22/tap-move-shake-turning-your-game-ideas-into-iphone-ipad-apps/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 21:51:10 +0000</pubDate>
		<dc:creator>Lon Hosford</dc:creator>
				<category><![CDATA[Gaming]]></category>
		<category><![CDATA[IPhone]]></category>
		<category><![CDATA[Objective C]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://www.lonhosford.com/lonblog/?p=2845</guid>
		<description><![CDATA[Todd Moore&#8217;s new book, Tap, Move, Shake: Turning Your Game Ideas into iPhone &#038; iPad Apps, is currently the best choice for getting started with writing and publishing IOS games. A key feature is that the apps in the book are IN THE APP STORE. Never saw that trick before and I think is a [...]]]></description>
			<content:encoded><![CDATA[<div id="fb-root"></div>
<p><script src="http://connect.facebook.net/en_US/all.js#appId=105467682877384&amp;xfbml=1"></script><fb:like href="http://www.lonhosford.com/lonblog/2012/01/22/tap-move-shake-turning-your-game-ideas-into-iphone-ipad-apps/" send="true" width="450" show_faces="true" font=""></fb:like><!-- Place this tag where you want the +1 button to render --><br />
<g:plusone annotation="inline"></g:plusone></p>
<p>Todd Moore&#8217;s new book, <strong><a href="http://www.amazon.com/gp/product/1449303455/ref=as_li_ss_tl?ie=UTF8&#038;tag=hosfordusa&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=1449303455">Tap, Move, Shake: Turning Your Game Ideas into iPhone &#038; iPad Apps</a></strong>, is currently the best choice for getting started with writing and publishing IOS games. </p>
<p>A key feature is that <strong>the apps in the book are IN THE APP STORE</strong>. Never saw that trick before and I think is a standard for anyone writing IOS books. I actually followed the steps of creating an app I could download suffice it had a tad more flash in the store.</p>
<div class="wp-caption alignleft" style="width: 131px"><a href="http://www.amazon.com/gp/product/1449303455/ref=as_li_ss_tl?ie=UTF8&#038;tag=hosfordusa&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=1449303455" target="_blank"><img  src="http://ecx.images-amazon.com/images/I/51erZvLUPaL._BO2,204,203,200_PIsitb-sticker-arrow-click,TopRight,35,-76_AA300_SH20_OU01_.jpg" alt="Tap, Move, Shake: Turning Your Game Ideas into iPhone &#038; iPad Apps" width="121" height="160" class="  " title="Tap, Move, Shake: Turning Your Game Ideas into iPhone &#038; iPad Apps"/></a><p class="wp-caption-text">Tap, Move, Shake: Turning Your Game Ideas into iPhone &#038; iPad Apps</p></div>
<p>This is the first book I have seen in XCode/ObjectiveC that takes the submission to the App store as important a learning step as is the process of writing code. I loved the give and take App store rejection emails that provided a lot of insight for anyone who is going to submit an app the first time.</p>
<p>Also insightful is the special effort in giving the coder who is light on media creation great chapters on creating graphics and sound. Links provided are well researched.</p>
<p>On the wish list for me was not to dismiss ARC (Automatic Reference Counting) at the onset. Gee the book kinda assumes the beginner and ARC leans to that. But I suspect a case of examples completed at a time Apple was busy upsetting the cart for writers in progress.</p>
<p>The chapters are extremely well thought out especially the progression of development with the sections in each chapter. </p>
<p>I think you need a basic skill in XCode and Objective C to follow the book. XCode is introduced nicely for beginners and Objective C is learned more by example and less by explanation. I could not have solved some bugs without a basic skill in Objective C. The architecture of IOS app is explained well. I loved the clarity of explaining the bootstrap of an IOS app. I finally got it!</p>
<p>The book covers EVERYTHING you need from setting up for development, coding, basic testing, resource creation, app submission and even app marketing. All at a very clear to the point approach. The book examples make you feel you are starting at the beginning because they are from the gaming industry beginnings tuned to the phone.</p>
<p>This is 254 page book that has a good number of images taking up pages. Compared to 3 and 4 inch opus magnum IOS books out there that are OMGs difficult to hold open on the desk or in a lounge chair, Todd gets a great deal done as a focused writer. Cutting content is key. I rather buy more books than have big monsters.</p>
<p>Want to get started in IOS gaming without a gaming engine or better understand your gaming engine, then do this book.</p>
<div id="fb-root"></div>
<p><script src="http://connect.facebook.net/en_US/all.js#appId=105467682877384&amp;xfbml=1"></script><fb:like href="http://www.lonhosford.com/lonblog/2012/01/22/tap-move-shake-turning-your-game-ideas-into-iphone-ipad-apps/" send="true" width="450" show_faces="true" font=""></fb:like></p>
<div id="fb-root"></div>
<p><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:comments href="http://www.lonhosford.com/lonblog/2012/01/22/tap-move-shake-turning-your-game-ideas-into-iphone-ipad-apps/" num_posts="3" width="500"></fb:comments></p>
<p><div style = "text-align:center"><script type="text/javascript"><!--
google_ad_client = "pub-8926707286265620";
/* 300x250, created 7/29/10 */
google_ad_slot = "4548376258";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><br />
<!-- Place this render call where appropriate --><br />
<script type="text/javascript">
  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lonhosford.com/lonblog/2012/01/22/tap-move-shake-turning-your-game-ideas-into-iphone-ipad-apps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Basic Parsley MVC Flash Builder Actionscript Project</title>
		<link>http://www.lonhosford.com/lonblog/2011/02/07/basic-parsley-mvc-flash-builder-actionscript-project/</link>
		<comments>http://www.lonhosford.com/lonblog/2011/02/07/basic-parsley-mvc-flash-builder-actionscript-project/#comments</comments>
		<pubDate>Mon, 07 Feb 2011 15:35:12 +0000</pubDate>
		<dc:creator>Lon Hosford</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Parsley]]></category>
		<category><![CDATA[Actionscript]]></category>

		<guid isPermaLink="false">http://www.lonhosford.com/lonblog/?p=1296</guid>
		<description><![CDATA[This is a basic model view controller example of a Parsley Actionscript project created in Flash Builder. I posted in this blog a minimalist example of using Parsley without implementing model view controller. See Parsley Hello World For A Flash Builder Actionscript Project.. In that post I explained the messaging in Parsley and will not [...]]]></description>
			<content:encoded><![CDATA[<div id="fb-root"></div>
<p><script src="http://connect.facebook.net/en_US/all.js#appId=105467682877384&amp;xfbml=1"></script><fb:like href="http://www.lonhosford.com/lonblog/2011/02/07/basic-parsley-mvc-flash-builder-actionscript-project/" send="true" width="450" show_faces="true" font=""></fb:like></p>
<p>This is a basic model view controller example of a <a href="http://www.spicefactory.org/parsley/" target = "_blank">Parsley</a> Actionscript project created in Flash Builder. I posted in this blog a minimalist example of using Parsley without implementing model view controller. See <a href="http://www.lonhosford.com/lonblog/2011/01/26/parsley-hello-world-for-a-flash-builder-actionscript-project/">Parsley Hello World For A Flash Builder Actionscript Project.</a>. <img alt="" src="http://lh6.ggpht.com/_e5pwU0LJbN8/TUDbXBX15QI/AAAAAAAAFyI/yx_5bTk9wBc/s800/ParselyHelloWorld_AS_published.png" class="alignleft" width="370" height="201" />In that post I explained the messaging in Parsley and will not repeat that explanation in this post other than to point them out where used in the model view controller implementation.</p>
<p>This model view controller example is as basic as I can make it while best trying to show the decoupling magic in Parsley. This is accomplished using the Parsley messaging and injection. I attempted to keep the view decoupled from the controller and model. The model and the controller could be decoupled from each other. How far you go with this depends on how many messages you want to design. To keep simple I did have the controller include the model and directly call model methods. This could be decoupled with a Parsley message.</p>
<p>This example follows a few techniques in a referenced example found in the <a href="http://spicefactory.org/parsley/documentation.php" target = "_blank">Spicefactory Parsley Developer Manual</a> in chapter 1 under &#8220;Other Resources&#8221;. This example is found at <a href="http://www.sitronnier.com/blog/parsley-2-basic-flash-example" target = "_blank">BloggingLemon</a>. It was written in July 2009.  There is a live demo and you can view the source code. Unfortunately the article has no explanations. It did provide me a good template for the Parsley bootstrapping. I tried to streamline that example even further and document what I know here.</p>
<p>You can build this with the free Flex SDK by using the code in the src folder and be sure to include a path to the Parsley and Spicelib library. I have included the Flash Builder 4 project file here you can download.</p>
<ul style = "padding-top:10px">
<li><a href="http://www.lonhosford.com/content/flex/Parsley/ParsleyFramework_MVC_AS.zip"  onClick="javascript: pageTracker._trackPageview('/downloads/Parsley/ParsleyFramework_MVC_AS.zip'); ">Flex Builder 4 Actionscript Project</a></li>
</ul>
<p><div style = "text-align:center"><script type="text/javascript"><!--
google_ad_client = "pub-8926707286265620";
/* 300x250, created 7/29/10 */
google_ad_slot = "4548376258";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><br />
<strong>Application Class &#8211; ParsleyFramework_MVC_AS.as</strong></p>
<p>This is the bootstrap application class. One of the issues in Flash using the XML Parsley configuration file are classes not tied to the view. These classes need to be compiled early so that Parsley can reflect on them. In our case the ApplicationModel and ApplicationController classes fall into this category. There are three techniques to include them for Parsley and I repeated the Parsley Developer&#8217;s Manual notes in the comments on line 35 &#8211; 39. I borrowed the first technique also used in the <a href="http://www.sitronnier.com/blog/parsley-2-basic-flash-example" target = "_blank">BloggingLemon</a> example which is considered by some a hack. Line 41 shows including these classes in an array that has no other use in this class and seems simple enough but should be clearly documented so they are not removed as orphaned code. </p>
<p>Lines 53 &#8211; 60 configure the Parsley log messaging useful for debugging Parsley. Here we are suppressing the Parsley messaging so you can view the trace statements I added to help follow the application model view controller and Parsely messaging. </p>
<p>Lines 89 and 90 of the initApp method load the Parsley xml configuration file shown later in this post.</p>
<p>Lines 100 and 103 of the contextEventInitializedHandler method create Parsley managed objects for the two views in this application. The input view allows you to enter and send a message. The output view is a Flash TextField that shows all the messages in reverse entry order. Actually the ApplicationModel maintains the reverse order and the view only displays the model.</p>
<p>The trace statements will show you the flow of the class as it bootstraps.</p>
<pre class="brush: as3; wrap-lines: false;">
package
{
	import controllers.ApplicationController;

	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;

	import models.ApplicationModel;

	import org.spicefactory.lib.flash.logging.Appender;
	import org.spicefactory.lib.flash.logging.FlashLogFactory;
	import org.spicefactory.lib.flash.logging.LogLevel;
	import org.spicefactory.lib.flash.logging.impl.DefaultLogFactory;
	import org.spicefactory.lib.flash.logging.impl.TraceAppender;
	import org.spicefactory.lib.logging.LogContext;
	import org.spicefactory.lib.logging.Logger;
	import org.spicefactory.parsley.core.context.Context;
	import org.spicefactory.parsley.core.events.ContextEvent;
	import org.spicefactory.parsley.flash.logging.FlashLoggingXmlSupport;
	import org.spicefactory.parsley.xml.XmlContextBuilder;

	import views.InputView;
	import views.OutputView;

	[SWF(frameRate=&quot;30&quot;, width=&quot;800&quot;, height=&quot;650&quot;, backgroundColor=&quot;0x666666&quot;)]	

	public class ParsleyFramework_MVC_AS extends Sprite
	{
		/**
		 * Hack to force compiling of classes configured in ParsleyConfiguration.xml
		 * not used in this class so Parsley can reflect on them.
		 *
		 * Alternatives to this hack include either
		 * compiling them into an SWC (with compc you can include
		 * whole source folders into the SWC) and then include the whole SWC into your SWF
		 * with the -include-libraries option of the mxmlc compiler.
		 * or include individual classes with the -includes option of the mxmlc compiler.
		 * */
		protected var classImporter:Array = [ApplicationModel, ApplicationController];
		/**
		 * This app's context for Parsley.
		 * */
		protected var mainContext:Context;
		/**
		 * Application bootstrap class.
		 * */
		public function ParsleyFramework_MVC_AS()
		{
			super();
			trace(&quot;INIT: ParsleyFramework_MVC_AS()&quot;);
			var factory:FlashLogFactory = new DefaultLogFactory();
			// Spicefactory warning level for logging.
			factory.setRootLogLevel(LogLevel.WARN);
			var traceApp:Appender = new TraceAppender();
			// Suppress SpiceFactory lib tracing.
			traceApp.threshold = LogLevel.OFF;
			factory.addAppender(traceApp);
			LogContext.factory = factory;
			if (stage == null)
			{
				addEventListener(Event.ADDED_TO_STAGE, addedToStageEventHandler);
			}
			else
			{
				initApp();
			}
		}
		/**
		 * Handler for ADDED_TO_STAGE EVENT
		 */
		protected function addedToStageEventHandler(event:Event):void
		{
			trace(&quot;INIT: ParsleyFramework_MVC_AS.addedToStageEventHandler(...)&quot;);
			removeEventListener(Event.ADDED_TO_STAGE, addedToStageEventHandler);
			initApp();
		}
		/**
		 * Initialize the stage and load Parsley configuration.
		 */
		protected function initApp():void
		{
			trace(&quot;INIT: ParsleyFramework_MVC_AS.initApp()&quot;);
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			FlashLoggingXmlSupport.initialize();
			// INITIALIZE CONTEXT
			mainContext = XmlContextBuilder.build(&quot;ParsleyConfiguration.xml&quot;);
			mainContext.addEventListener(ContextEvent.INITIALIZED, contextEventInitializedHandler);
		}
		/**
		 * Handler for Parsley ContextEvent.INITIALIZED event.
		 */
		protected function contextEventInitializedHandler(event:ContextEvent):void
		{
			trace(&quot;INIT: ParsleyFramework_MVC_AS.contextEventInitializedHandler(...)&quot;);
			mainContext.removeEventListener(ContextEvent.INITIALIZED, contextEventInitializedHandler);
			// Add in the views.
			var inputView:InputView = mainContext.getObjectByType(InputView) as InputView;
			addChild(inputView);
			inputView.y = 50;
			var outputView:OutputView = mainContext.getObjectByType(OutputView) as OutputView;
			addChild(outputView);
			outputView.y = inputView.y + inputView.height + 5;
		}
	}
}
</pre>
<p><strong>Parsley Configuration XML File – ParsleyConfiguration.xml</strong><br />
For Parsley to look for the Parsley metatags and other management tasks, it needs to know which classes to search. Loading an XML configuration file is how that is done. Here you see the model, controller and two views referenced by their package identification.</p>
<pre class="brush: as3; wrap-lines: false;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;objects
    xmlns=&quot;http://www.spicefactory.org/parsley&quot;
    xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
    xsi:schemaLocation=&quot;http://www.spicefactory.org/parsley 

http://www.spicefactory.org/parsley/schema/2.3/parsley-core.xsd&quot;

    &gt;
     &lt;!-- Objects managed by Parsley --&gt;
 	&lt;object type=&quot;models.ApplicationModel&quot; /&gt;
 	&lt;object type=&quot;controllers.ApplicationController&quot; /&gt;

	&lt;object type=&quot;views.InputView&quot; /&gt;
	&lt;object type=&quot;views.OutputView&quot;  /&gt;
&lt;/objects&gt;
</pre>
<p><div style = "text-align:center"><script type="text/javascript"><!--
google_ad_client = "pub-8926707286265620";
/* 300x250, created 7/29/10 */
google_ad_slot = "4548376258";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><br />
<strong>The Input View – InputView.as</strong><br />
This is an input TextField and an extended SimpleButton to take any typed message and send a Parsley message.</p>
<p>Line 102 is where a message is dispatched for Parsley to broadcast. Lines 37 and 38 show the Parsley injection for the messaging method.</p>
<p>There is no reference to a controller or a model in this view. The message on line 102 is dispatched for the chosen controller to handle. That choice is made in the controller.</p>
<pre class="brush: as3; wrap-lines: false;">
package views
{
	import events.SendTextMessageEvent;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	import flashx.textLayout.formats.TextAlign;
	import ui.simple.QuickButton;
	/**
	 * Demonstrates UI components sending messages confined to this view while
	 * using Parsley to send the SendTextMessageEvent outside for a controller to handle.
	 * */
	public class InputView extends Sprite
	{
		/**
		 * Output TextField component.
		 * */
		private var input_tf:TextField;
		/**
		 * TextFormat for input_tf.
		 * */
		private var tfFormat:TextFormat;
		/**
		 * The send button
		 * */
		private var sendButton:QuickButton;
		/**
		 * The off button
		 * */
		private var offButton:QuickButton;
		/**
		 * Parsley injected message dispatcher
		 * */
		[MessageDispatcher]
		public var dispatcher:Function;
		/**
		 * Constructor
		 * */
		public function InputView()
		{
			trace(&quot;VIEW: InputView()&quot;);
			super();
			createChildren();
		}
		/**
		 * Parsley calls automatically after context parsing.
		 */
		[Init]
		public function parsleyInit():void
		{
			trace(&quot;VIEW: InputView.parsleyInit()&quot;);
		}
		/**
		 * Build the UI for this display object.
		 */
		public function createChildren():void
		{
			trace(&quot;VIEW: InputView.createChildren()&quot;);
			// TextFormat
			tfFormat = new TextFormat();
			tfFormat.align = TextAlign.LEFT;
			tfFormat.bold = true;
			tfFormat.font = &quot;_typewriter&quot;;
			// Input TextField.
			input_tf = new TextField();
			input_tf.border = true;
			input_tf.multiline = false;
			input_tf.type = TextFieldType.INPUT;
			input_tf.background = true;
			input_tf.width = 600;
			input_tf.height = 20;
			input_tf.addEventListener(Event.CHANGE, input_tf_changeHandler);
			addChild(input_tf);
			// Create QuickButton and add to display list.
			sendButton = new QuickButton(&quot;Send&quot;,60);
			sendButton.addEventListener(MouseEvent.CLICK, sendButtonClickHandler);
			addChild(sendButton);
			input_tf.width -= sendButton.width + 10;
			sendButton.x = input_tf.x + input_tf.width + 10;
		}
		/**
		 * Handler for input_tf_changeHandler Event.CHANGE. To maintain format while changing input
		 * text.
		 * */
		private function input_tf_changeHandler(e:Event):void
		{
			//trace(&quot;VIEW: InputView.input_tf_changeHandler(...)&quot;);
			input_tf.setTextFormat(tfFormat);
		}
		/**
		 * Handler for sendButton MouseEvent.CLICK
		 * */
		private function sendButtonClickHandler(e:MouseEvent):void
		{
			trace(&quot;VIEW: InputView.sendButtonClickHandler(...)&quot;);
			// There is text to send
			if (input_tf.length &gt; 0)
			{
				dispatcher( new SendTextMessageEvent(SendTextMessageEvent.SEND, input_tf.text) );
				input_tf.text = &quot;&quot;;
				stage.focus = input_tf;
			}
		}
	}
}
</pre>
<p><strong>The Output View – OutputView.as</strong></p>
<p>As in the InputView there is no reference to a controller or a model. Line 68 shows using Parsley to pick up a message. Of course in a model-view-controller implementation the model should dispatch this message when the model updates.</p>
<pre class="brush: as3; wrap-lines: false;">
package views
{
	import events.SendTextMessageEvent;
	import events.SentTextMessagesUpdateEvent;

	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;

	import flashx.textLayout.formats.TextAlign;

	/**
	 * Simple output view. Demonstrates receiving Parsley managed messages and updating from model changes.
	 * */
	public class OutputView extends Sprite
	{
		/**
		 * Output TextField component.
		 * */
		private var output_tf:TextField;
		/**
		 * TextFormat for output_tf.
		 * */
		private var tfFormat:TextFormat;
		/**
		 * Constructor
		 * */
		public function OutputView()
		{
			trace(&quot;VIEW: OutputView()&quot;);
			super();
			createChildren();
		}
		/**
		 * Parsley calls automatically after context parsing.
		 */
		[Init]
		public function parsleyInit():void
		{
			trace(&quot;VIEW: OutputView.parsleyInit()&quot;);
		}
		/**
		 * Build the UI for this display object.
		 */
		public function createChildren():void
		{
			trace(&quot;VIEW: OutputView.createChildren()&quot;);
			// TextFormat
			tfFormat = new TextFormat();
			tfFormat.align = TextAlign.LEFT;
			tfFormat.bold = true;
			tfFormat.font = &quot;_typewriter&quot;;
			// TextField.
			output_tf = new TextField();
			output_tf.border = true;
			output_tf.multiline = true;
			output_tf.background = true;
			output_tf.width = 600;
			output_tf.height = 100;
			addChild(output_tf);
		}
		/**
		 * Parsley event handler. Listening for SentTextMessagesUpdateEvent.UPDATE type. Shows using a selector.
		 * Other Parsley managed views can do the same.
		 */
		[MessageHandler(selector=&quot;event.SentTextMessagesUpdateEvent.UPDATED&quot;)]
		public function sentTextMessagesUpdateEventHandler(event:SentTextMessagesUpdateEvent):void
		{
			trace(&quot;VIEW: OutputView.sentTextMessagesUpdateEventHandler(...) - event.type: &quot; + event.type);
			output_tf.text = event.sentTextMessages;
			output_tf.setTextFormat(tfFormat);
		}
	}
}
</pre>
<p><strong>The Model – ApplicationModel.as</strong></p>
<p>On line 12 of the model the one data element, sentTextMessages, holds all the text messages sent in the application. The addSentTextMessage method is where the model is updated with new text messages and where sentTextMessages is maintained. The text messages in sentTextMessages are kept in &#8220;last in&#8221; order.</p>
<p>Line 30 notifies the Parsley framework of changes in sentTextMessages. The wiring we applied in the Parsley framework incudes the views and the views have handlers to receive the message. In our case it is the OutputView which simply displays the sentTextMessages value as is.</p>
<pre class="brush: as3; wrap-lines: false;">
package models
{
	import events.SentTextMessagesUpdateEvent;
	/**
	 * The model responsible for application data.
	 * */
	public class ApplicationModel
	{
		/**
		 * All text messages sent separated by new line \n.
		 * */
		private var sentTextMessages:String = &quot;&quot;;
		/**
		 * Parsley injected message dispatcher
		 * */
		[MessageDispatcher]
		public var dispatcher:Function;
		/**
		 * Updates the sentTextMessages property and broadcasts SentTextMessagesUpdateEvent.
		 * @param messageText A text message sent.
		 * */
		public function addSentTextMessage(messageText:String):void
		{
			trace(&quot;MODEL: ApplicationModel.addSentTextMessage(...)&quot;);
			if (sentTextMessages.length &gt; 0)
			{
				messageText += &quot;\n&quot;;
			}
			sentTextMessages = messageText + sentTextMessages;
			dispatcher( new SentTextMessagesUpdateEvent(SentTextMessagesUpdateEvent.UPDATED, sentTextMessages) );
		}
	}
}
</pre>
<p><div style = "text-align:center"><script type="text/javascript"><!--
google_ad_client = "pub-8926707286265620";
/* 300x250, created 7/29/10 */
google_ad_slot = "4548376258";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><br />
<strong>The Controller– ApplicationController.as</strong></p>
<p>Lines 34 and 35 uses the Parsley messaging to listen for view messages and in this case the event.SendTextMessageEvent.SEND message. Views do not need to couple to this controller. Neither does the controller need to know anything about the views.</p>
<p>Line 38 shows the updating of the model. However you could replace this with Parsley messaging to decouple the controller from the model. I did not in order to reduce the number of messages for the example. </p>
<pre class="brush: as3; wrap-lines: false;">
package controllers
{
	import events.SendTextMessageEvent;

	import models.ApplicationModel;

	/**
	 * The controller responsible for application level control.
	 * */
	public class ApplicationController
	{
		/**
		 * The model injected by Parsley.
		 * */
		[Inject]
		public var model:ApplicationModel;
		/**
		 * Parsley injected message dispatcher
		 * */
		[MessageDispatcher]
		public var dispatcher:Function;
		/**
		 * Parsley calls automatically after context parsing.
		 */
		[Init]
		public function parsleyInit():void
		{
			trace(&quot;CONTROLLER: ApplicationController.parsleyInit()&quot;);
		}
		/**
		 * Parsley event handler. Listening for SendTextMessageEvent.SEND type. Shows using a selector.
		 * Other Parsley managed views can do the same.
		 */
		[MessageHandler(selector=&quot;event.SendTextMessageEvent.SEND&quot;)]
		public function sendTextMessageEventHandler(event:SendTextMessageEvent):void
		{
			trace(&quot;CONTROLLER: ApplicationController.sendTextMessageEventHandler(...) - event.type: &quot; + event.type);
			model.addSentTextMessage(event.messageText);
		}
	}
}
</pre>
<p><strong>The SendTextMessageEvent– SendTextMessageEvent.as</strong></p>
<p>This is a custom Actionscript event. The purpose is to carry a new text message.</p>
<pre class="brush: as3; wrap-lines: false;">
package events
{
	import flash.events.Event;
	/**
	 * Event for demonstrating Parsley. View sending a new text message.
	 * */
	public class SendTextMessageEvent extends Event
	{
		/**
		 * The event send type.
		 * */
		public static const SEND:String = &quot;event.SendTextMessageEvent.SEND&quot;;
		/**
		 * The text sent.
		 * */
		public var messageText:String;
		/**
		 * Constructor
		 * @param messageText The text sent.
		 * */
		public function SendTextMessageEvent(type:String, messageText:String, bubbles:Boolean=false, cancelable:Boolean=false)
		{
			super(type, bubbles, cancelable);
			this.messageText = messageText;
			trace (&quot;EVENT: SendTextMessageEvent(...) type: &quot; + type);
		}
		override public function clone():Event
		{
			return new SendTextMessageEvent(type, messageText, bubbles, cancelable);
		}
	}
}
</pre>
<p><strong>The SentTextMessagesUpdateEvent – SentTextMessagesUpdateEvent .as</strong></p>
<p>Another custom Actionscript event. The model&#8217;s sentTextMessages property is carried in this event.</p>
<pre class="brush: as3; wrap-lines: false;">
package events
{
	import flash.events.Event;
	/**
	 * Event for demonstrating Parsley with mvc. Model notification of sentTextMessages updated.
	 * The event does not need to be specific to the model so references to the model in
	 * documentation is for helping in tracing the Parsley mvc being demonstrated.
	 * */
	public class SentTextMessagesUpdateEvent extends Event
	{
		/**
		 * The event updated type.
		 * */
		public static const UPDATED:String = &quot;event.SentTextMessagesUpdateEvent.UPDATED&quot;;
		/**
		 * The model value of all the sent text messages.
		 * */
		public var sentTextMessages:String;
		/**
		 * Constructor
		 * @param sentTextMessages The model's value of the sentTextMessages.
		 * */
		public function SentTextMessagesUpdateEvent(type:String, sentTextMessages:String, bubbles:Boolean=false, cancelable:Boolean=false)
		{
			super(type, bubbles, cancelable);
			this.sentTextMessages = sentTextMessages;
			trace (&quot;EVENT: SentTextMessagesUpdateEvent(...) type: &quot; + type);
		}
		override public function clone():Event
		{
			return new SentTextMessagesUpdateEvent(type, sentTextMessages, bubbles, cancelable);
		}
	}
}
</pre>
<p><strong>The QuickButton- QuickButton.as</strong><br />
This is just an Actionscript SimpleButton to use for the demo.</p>
<pre class="brush: as3; wrap-lines: false;">
package ui.simple
{
	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.display.SimpleButton;
	import flash.events.MouseEvent;
	public class QuickButton extends SimpleButton
	{
		/**
		 * The up state background color;
		 * */
		private var upColor:uint   = 0xFFCC00;
		/**
		 * The over state background color;
		 * */
		private var overColor:uint = 0xCCFF00;
		/**
		 * The down state background color;
		 * */
		private var downColor:uint = 0x00CCFF;
		/**
		 * Width.
		 * */
		private var buttonWidth:Number;;
		/**
		 * Label.
		 * */
		private var label:String;
		/**
		 * Constructor.
		 * @param label The caption for button.
		 * @param buttonWidth Width of the button. Height is 1/3 of buttonWidth
		 * */
		public function QuickButton(label:String = &quot;Button&quot;, buttonWidth:Number = 80)
		{
			trace(&quot;UI: QuickButton() - label: &quot; + label);
			this.label = label;
			this.buttonWidth = buttonWidth;
			downState      = new QuickButtonDisplayShape(label, downColor, buttonWidth);
			overState      = new QuickButtonDisplayShape(label, overColor, buttonWidth);
			upState        = new QuickButtonDisplayShape(label, upColor, buttonWidth);
			hitTestState   = new QuickButtonDisplayShape(label, upColor, buttonWidth);
			useHandCursor  = true;
		}
	}
}
</pre>
<p><strong>The QuickButton Skin &#8211; QuickButtonDisplayShape.as</strong><br />
How I skinned the QuickButton.</p>
<pre class="brush: as3; wrap-lines: false;">
package ui.simple
{
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flashx.textLayout.formats.TextAlign;
	/**
	 * Rounded button with text label. Width and height and not margins or padding.
	 * */
	public class QuickButtonDisplayShape extends Sprite
	{
		/**
		 * Background color.
		 * */
		private var bgColor:uint;
		/**
		 * Width.
		 * */
		private var buttonWidth:Number;
		/**
		 * Height.
		 * */
		private var buttonHeight:Number;
		/**
		 * Label TextField component.
		 * */
		private var tf:TextField;
		/**
		 * Left padding for tf inside the button shape.
		 * */
		private const TF_LEFT_PADDING:Number = 6;
		/**
		 * Right padding for tf inside the button shape.
		 * */
		private const TF_RIGHT_PADDING:Number = 6;
		/**
		 * Ratio of button height to the buttonWidth.
		 * */
		private const BUTTON_HEIGHT_RATIO:Number = 1/3;
		/**
		 * Constructor.
		 * @param label The caption for button.
		 * @param bgColor Color for the button background.
		 * @param buttonWidth Width of the button. Height is 1/3 of buttonWidth
		 * */
		public function QuickButtonDisplayShape(label:String,bgColor:Number, buttonWidth:Number)
		{
			// Consume parameters
			this.bgColor = bgColor;
			this.buttonWidth = buttonWidth;
			this.buttonHeight = buttonWidth * BUTTON_HEIGHT_RATIO;
			// Draw button graphics.
			draw();
			// TextField for the button caption.
			tf = new TextField();
			var tfFormat:TextFormat = new TextFormat();
			tf.text = label;
			// Format for centering.
			tfFormat.align = TextAlign.CENTER;
			tfFormat.bold = true;
			tfFormat.font = &quot;_sans&quot;;
			//tf.border = true; // Design guide for layout.
			tf.setTextFormat(tfFormat);
			// Position and size the caption.
			tf.x = TF_LEFT_PADDING;
			tf.width = buttonWidth - (TF_LEFT_PADDING + TF_RIGHT_PADDING);
			tf.height = tf.textHeight + 2;
			tf.y = Math.max(0, ( buttonHeight - (tf.textHeight + 4)) / 2);
			// Add caption.
			addChild(tf);
		}
		/**
		 * Draw graphics.
		 * */
		private function draw():void
		{
			graphics.beginFill(bgColor);
			graphics.drawRoundRect(0, 0, buttonWidth, buttonHeight, 20, 20);
			graphics.endFill();
		}
	}
}
</pre>
<div id="fb-root"></div>
<p><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:comments href="http://www.lonhosford.com/lonblog/2011/02/07/basic-parsley-mvc-flash-builder-actionscript-project/" num_posts="2" width="500"></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lonhosford.com/lonblog/2011/02/07/basic-parsley-mvc-flash-builder-actionscript-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using ExternalInterface To Send Messages to Firebug Console</title>
		<link>http://www.lonhosford.com/lonblog/2011/01/29/using-externalinterface-to-send-messages-to-firebug-console/</link>
		<comments>http://www.lonhosford.com/lonblog/2011/01/29/using-externalinterface-to-send-messages-to-firebug-console/#comments</comments>
		<pubDate>Sat, 29 Jan 2011 20:41:23 +0000</pubDate>
		<dc:creator>Lon Hosford</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[ExternalInterface]]></category>

		<guid isPermaLink="false">http://www.lonhosford.com/lonblog/?p=1274</guid>
		<description><![CDATA[There are times that you do not have the debugger version of Flash Player running when testing in a web browser so you cannot use various extensions and plugins such as Flashbug that will display Actionscript tracing to the browser window. Flashbug is a Firefox Firebug extension. However you can use the Firebug console window [...]]]></description>
			<content:encoded><![CDATA[<p>There are times that you do not have the debugger version of Flash Player running when testing in a web browser so you cannot use various extensions and plugins such as <a href="https://addons.mozilla.org/en-US/firefox/addon/flashbug/" target = "_blank">Flashbug</a> that will display Actionscript tracing to the browser window. <img alt="" src="https://lh3.googleusercontent.com/_e5pwU0LJbN8/TUR6_4ErS3I/AAAAAAAAFyQ/KAIXHNv-3GM/s800/FirebugExternalInterface_published.png" class="alignleft" width="337" height="232" /> <a href="https://addons.mozilla.org/en-US/firefox/addon/flashbug/" target = "_blank">Flashbug</a> is a Firefox <a href="http://getfirebug.com/" target = "_blank">Firebug</a> extension.</p>
<p>However you can use the <a href="http://getfirebug.com/" target = "_blank">Firebug</a> console window directly from Actionscript using ExternalInterface. In fact you can use it for sending messages to any Javascript console you may have created or use. </p>
<p>ExternalInterface allows you to call Javascript function from within Actionscript. So we can apply it to calling the Firebug console.log method as well. </p>
<p>I have seen other examples of this code on the internet. Most have a few problems with handling errors. The most egregious is not testing if there is a Firebug console available. The problem is that it is easy to overlook removing Firebug console.log statements when you are working in Javascript. The result is errors when viewing the page in a browser like IE or any browser not having Firebug. The same applies to Actionscript calling Javascript functions. A test is needed to verify that the console.log method is available.</p>
<p>Second it the matter of fact inclusion of testing if ExternalInterface is available. ExternalInterface does not support all web browsers. You can check this out on the <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html?filter_flex=4.1&#038;filter_flashplayer=10.1&#038;filter_air=2"  target = "_blank">ExternalInterface documentation page</a>.</p>
<p>This example contains a method you can add to a class in your Flash or Flex classes and call. </p>
<p><div style = "text-align:center"><script type="text/javascript"><!--
google_ad_client = "pub-8926707286265620";
/* 300x250, created 7/29/10 */
google_ad_slot = "4548376258";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><br />
<strong>Sending a Message To Firebug console.log Method</strong></p>
<p>This log method demonstrates code you might want to use. I gave it two purposes. One to trace to the standard Flash log you see on line 3. The second is to trace to the Firebug console. Putting all of this into one method makes it easy enough to turn off all tracing by commenting out the body of the method. Of course you may want to integrate this into a singleton class and use it throughout your code.</p>
<p>Line 4 insures the browser has ExternalInterface capability available.</p>
<p>Lines 7 to 9 compose a anonymous Javascript function that looks like this:<br />
<code>function(){if (window.console) console.log('Hello World');}</code></p>
<p>Then line 11 calls the function.</p>
<pre class="brush: as3; wrap-lines: false;">
		private function log(message:String):void
		{
			trace (message);
			if (ExternalInterface.available)
			{
				// Create Javascript function to call the Firebug console log method and append the message.
				message = &quot;function(){if (window.console) console.log('&quot; + message;
				// Close the Firebug console log method and the Javascript function.
				message +=  &quot;');}&quot;;
				// Request running the function.
				ExternalInterface.call(message);
			}
		}
</pre>
<p><div style = "text-align:center"><script type="text/javascript"><!--
google_ad_client = "pub-8926707286265620";
/* 300x250, created 7/29/10 */
google_ad_slot = "4548376258";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div></p>
<p>To use the function, simply call it with your tracing message and you will get the message both in the regular Flash trace consoles you are using and as well in the Firebug console.</p>
<pre class="brush: as3; wrap-lines: false;">
log(&quot;Hello Firebug Console From Actionscript&quot;);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lonhosford.com/lonblog/2011/01/29/using-externalinterface-to-send-messages-to-firebug-console/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Parsley Hello World For A Flash Builder Actionscript Project</title>
		<link>http://www.lonhosford.com/lonblog/2011/01/26/parsley-hello-world-for-a-flash-builder-actionscript-project/</link>
		<comments>http://www.lonhosford.com/lonblog/2011/01/26/parsley-hello-world-for-a-flash-builder-actionscript-project/#comments</comments>
		<pubDate>Thu, 27 Jan 2011 02:46:51 +0000</pubDate>
		<dc:creator>Lon Hosford</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Parsley]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[TextField]]></category>

		<guid isPermaLink="false">http://www.lonhosford.com/lonblog/?p=1246</guid>
		<description><![CDATA[I had reasonable success using the SpiceFactory Parsley framework for Flex and AIR projects. I posted a basic Flex Example in this blog. I also wanted to use it for Actionscript projects in Flash Builder. This is as minimalist example as I could make. It shows how to configure the Actionscript project for Parsley, how [...]]]></description>
			<content:encoded><![CDATA[<div id="fb-root"></div>
<p><script src="http://connect.facebook.net/en_US/all.js#appId=105467682877384&amp;xfbml=1"></script><fb:like href="http://www.lonhosford.com/lonblog/2011/01/26/parsley-hello-world-for-a-flash-builder-actionscript-project/" send="true" width="450" show_faces="true" font=""></fb:like><br />
I had reasonable success using the  <a href="http://www.spicefactory.org/parsley/" target = "_blank">SpiceFactory Parsley</a> framework for Flex and AIR projects. I posted a <a href="http://www.lonhosford.com/lonblog/2010/09/14/basic-parsley-framework-flex-example-explained/">basic Flex Example</a> in this blog. I also wanted to use it for Actionscript projects in Flash Builder. <img alt="" src="http://lh6.ggpht.com/_e5pwU0LJbN8/TUDbXBX15QI/AAAAAAAAFyI/yx_5bTk9wBc/s800/ParselyHelloWorld_AS_published.png" class="alignleft" width="370" height="201" />This is as minimalist example as I could make. It shows how to configure the Actionscript project for Parsley, how to wire in your view and how to access the Parsley messaging framework. </p>
<p>[UPDATE] I posted a second example that includes a minimalist model view controller with Parsley: <a href="http://www.lonhosford.com/lonblog/2011/02/07/basic-parsley-mvc-flash-builder-actionscript-project/">Basic Parsley MVC Flash Builder Actionscript Project</a>.</p>
<p>The only basic example for Flash I could find is referenced from the <a href="http://spicefactory.org/parsley/documentation.php" target = "_blank">Spicefactory Parsley Developer Manual</a> in chapter 1 under &#8220;Other Resources&#8221;. This example is found at <a href="http://www.sitronnier.com/blog/parsley-2-basic-flash-example" target = "_blank">BloggingLemon</a>. It was written in July 2009.  There is a live demo and you can view the source code. Unfortunately the article has no explanations. It did provide me a good template for the Parsley bootstrapping.</p>
<p>The BloggingLemon article attempts to show using model-view-controller with Parsley.  I stripped that out so you have a real basic example that, to my search efforts, is not available on the web or at the SpiceFactory web site.</p>
<p>You can build this with the free Flex SDK by using the code in the src folder and be sure to include a path to the Parsley and Spicelib library. I have included the Flash Builder 4 project file here you can download.</p>
<ul style = "padding-top:10px">
<li><a href="http://www.lonhosford.com/content/flex/Parsley/ParsleyFramework_HelloWorld_AS.zip"  onClick="javascript: pageTracker._trackPageview('/downloads/ParsleyFramework_HelloWorld_AS.zip'); ">Flex Builder 4 Actionscript Project</a></li>
</ul>
<p><div style = "text-align:center"><script type="text/javascript"><!--
google_ad_client = "pub-8926707286265620";
/* 300x250, created 7/29/10 */
google_ad_slot = "4548376258";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><br />
<strong>Application Class &#8211; ParsleyFramework_HelloWorld_AS.as</strong><br />
This is the bootstrap application class. The constructor lines 33 &#8211; 40 configure the Parsley log messaging useful for debugging Parsley. Here we are suppressing the Parsley messaging so you can view the trace statements I added to help follow the application and Parsely messaging. </p>
<p>Lines 69 and 70 of the initApp method load the Parsley xml configuration file shown later in this post.</p>
<p>Lines 79 an 81 of the contextEventInitializedHandler method create Parsley managed objects for the two views in this application. The input view is two buttons labeled on and off. The output view is a Flash TextField.</p>
<p>The trace statements will show you the flow of the class.</p>
<pre class="brush: as3; wrap-lines: false;">
package
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import org.spicefactory.lib.flash.logging.Appender;
	import org.spicefactory.lib.flash.logging.FlashLogFactory;
	import org.spicefactory.lib.flash.logging.LogLevel;
	import org.spicefactory.lib.flash.logging.impl.DefaultLogFactory;
	import org.spicefactory.lib.flash.logging.impl.TraceAppender;
	import org.spicefactory.lib.logging.LogContext;
	import org.spicefactory.lib.logging.Logger;
	import org.spicefactory.parsley.core.context.Context;
	import org.spicefactory.parsley.core.events.ContextEvent;
	import org.spicefactory.parsley.flash.logging.FlashLoggingXmlSupport;
	import org.spicefactory.parsley.xml.XmlContextBuilder;
	import views.InputView;
	import views.OutputView;
	[SWF(frameRate=&quot;30&quot;, width=&quot;800&quot;, height=&quot;650&quot;, backgroundColor=&quot;0x666666&quot;)]
	public class ParsleyFramework_HelloWorld_AS extends Sprite
	{
		/**
		 * This app's context for Parsley.
		 * */
		protected var _mainContext:Context;
		/**
		 * Application bootstrap class.
		 * */
		public function ParsleyFramework_HelloWorld_AS()
		{
			super();
			var factory:FlashLogFactory = new DefaultLogFactory();
			// Spicefactory warning level for logging.
			factory.setRootLogLevel(LogLevel.WARN);
			var traceApp:Appender = new TraceAppender();
			// Suppress SpiceFactory lib tracing.
			traceApp.threshold = LogLevel.OFF;
			factory.addAppender(traceApp);
			LogContext.factory = factory;
			if (stage == null)
			{
				addEventListener(Event.ADDED_TO_STAGE, addedToStageEventHandler);
			}
			else
			{
				initApp();
			}
		}
		/**
		 * Handler for ADDED_TO_STAGE EVENT
		 */
		protected function addedToStageEventHandler(event:Event):void
		{
			trace(&quot;INIT: ParsleyFramework_HelloWorld01_AS.addedToStageEventHandler(...)&quot;);
			removeEventListener(Event.ADDED_TO_STAGE, addedToStageEventHandler);
			initApp();
		}
		/**
		 * Initialize the stage and load Parsley configuration.
		 */
		protected function initApp():void
		{
			trace(&quot;INIT: ParsleyFramework_HelloWorld01_AS.initApp()&quot;);
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			FlashLoggingXmlSupport.initialize();
			// INITIALIZE CONTEXT
			_mainContext = XmlContextBuilder.build(&quot;ParsleyConfiguration.xml&quot;);
			_mainContext.addEventListener(ContextEvent.INITIALIZED, contextEventInitializedHandler);
		}
		/**
		 * Handler for Parsley ContextEvent.INITIALIZED event.
		 */
		protected function contextEventInitializedHandler(event:ContextEvent):void
		{
			trace(&quot;INIT: ParsleyFramework_HelloWorld01_AS.contextEventInitializedHandler(...)&quot;);
			_mainContext.removeEventListener(ContextEvent.INITIALIZED, contextEventInitializedHandler);
			var inputView:InputView = _mainContext.getObjectByType(InputView) as InputView;
			addChild(inputView);
			var outputView:OutputView = _mainContext.getObjectByType(OutputView) as OutputView;
			addChild(outputView);
			outputView.y = inputView.y + inputView.height + 5;
		}
	}
}
</pre>
<p><strong>Parsley Configuration XML File &#8211; ParsleyConfiguration.xml</strong><br />
For Parsley to look for the Parsley metatags and other management tasks, it needs to know which classes to search. Loading an XML configuration file is how that is done.</p>
<p>Lines 11 and 12 show how to wire in the two classes we are using.</p>
<pre class="brush: as3; wrap-lines: false;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;objects
    xmlns=&quot;http://www.spicefactory.org/parsley&quot;
    xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
    xsi:schemaLocation=&quot;http://www.spicefactory.org/parsley 

http://www.spicefactory.org/parsley/schema/2.3/parsley-core.xsd&quot;

    &gt;
    &lt;!-- Classes managed by Parsley --&gt;
	&lt;object type=&quot;views.InputView&quot;  /&gt;
	&lt;object type=&quot;views.OutputView&quot;  /&gt;
&lt;/objects&gt;
</pre>
<p><strong>The Input View &#8211; InputView.as</strong><br />
This input view is two buttons labeled on and off. The UI classes for the buttons is shown later in this post.</p>
<p>The key items to see here are the Parsley metatags. The first is line 25 where [MessageDispatcher] defines this class as a dispatcher of Parsley messages. Line 26 follows with the name of the function for message sending.  Lines 65 and 73 show this dispatcher function in action.</p>
<p>Line 39 shows the [Init] metatag. There may be times that you need to wait until Parsley is fully configured before adding display objects or performing other class initialization tasks. The [Init] metatag defines the function that Parsley will call when it is fully configured. An example is included here for demonstration purposes but we have no need for it other than to display a trace message for you to follow in your output console.</p>
<p>You can appreciate the two buttons sending their messages within the InputView and then the InputView dispatching messages to Parsley for other objects to handle. InputView is decoupled from the overall application and can be easily inserted into another application without a concern about the application messaging framework.</p>
<p>I made the InputView class so it would also handle the messages is gives to Parsley. You see this on lines 79, 89 and 97 with the [MessageHandler] metatags. These lines indentify functions that will act as Parsley message handlers. These are the methods that follow the [MessageHandler] metatags on lines 80, 90 and 98.</p>
<p>The message selection works by comparing the event in the [MessageHandler] method&#8217;s argument. A further feature can target the message using a selector. You see this with lines 89 and 89 where the event&#8217;s type becomes a filter for calling the method. You will see these event types later in the OnOffEvent class which is a common custom Actionscript event class.</p>
<pre class="brush: as3; wrap-lines: false;">
package views
{
	import events.OnOffEvent;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import ui.simple.QuickButton;
	/**
	 * Demonstrates UI components sending messages confined to this view while
	 * using Parsley to send messages outside. This view also
	 * handles the Parsley messages it dispatches.
	 * */
	public class InputView extends Sprite
	{
		/**
		 * The on button
		 * */
		private var onButton:QuickButton;
		/**
		 * The off button
		 * */
		private var offButton:QuickButton;
		/**
		 * Parsley injected message dispatcher
		 * */
		[MessageDispatcher]
		public var dispatcher:Function;
		/**
		 * Constructor
		 * */
		public function InputView()
		{
			trace(&quot;VIEW: InputView()&quot;);
			super();
			createChildren();
		}
		/**
		 * Parsley calls automatically after context parsing.
		 */
		[Init]
		public function parsleyInit():void
		{
			trace(&quot;VIEW: InputView.parsleyInit()&quot;);
		}
		/**
		 * Build the UI for this display object.
		 */
		public function createChildren():void
		{
			trace(&quot;VIEW: InputView.createChildren()&quot;);
			// Create two QuickButtons and add to display list.
			onButton = new QuickButton(&quot;On&quot;);
			onButton.addEventListener(MouseEvent.CLICK, onButtonClickHandler);
			addChild(onButton);
			offButton = new QuickButton(&quot;Off&quot;);
			offButton.addEventListener(MouseEvent.CLICK, offButtonClickHandler);
			offButton.x = onButton.x + onButton.width + 10;
			addChild(offButton);
		}
		/**
		 * Handler for onButton MouseEvent.CLICK
		 * */
		private function onButtonClickHandler(e:MouseEvent):void
		{
			trace(&quot;VIEW: InputView.onButtonClickHandler(...)&quot;);
			dispatcher( new OnOffEvent(OnOffEvent.ON) );
		}
		/**
		 * Handler for offButton MouseEvent.CLICK
		 * */
		private function offButtonClickHandler(e:MouseEvent):void
		{
			trace(&quot;VIEW: InputView.offButtonClickHandler(...)&quot;);
			dispatcher( new OnOffEvent(OnOffEvent.OFF) );
		}
		/**
		 * Parsley event handler. Listening for OnOffEvent all types.
		 * Other Parsley managed views can do the same.
		 */
		[MessageHandler]
		public function offOnEventHandler(event:OnOffEvent):void
		{
			trace(&quot;VIEW: InputView.offOnEventHandler(...) - event.type: &quot; + event.type);
		}
		/**
		 * Parsley event handler. Listening for OnOffEvent ON type. Shows using a selector.
		 * Other Parsley managed views can do the same.
		 */
		[MessageHandler(selector=&quot;event.OnOffEvent.OFF&quot;)]
		public function offEventHandler(event:OnOffEvent):void
		{
			trace(&quot;VIEW: InputView.offEventHandler(...)&quot;);
		}
		/**
		 * Parsley event handler. Listening for OnOffEvent all types. Shows using a selector.
		 * Other Parsley managed views can do the same.
		 */
		[MessageHandler(selector=&quot;event.OnOffEvent.ON&quot;)]
		public function onEventHandler(event:OnOffEvent):void
		{
			trace(&quot;VIEW: InputView.onEventHandler(...)&quot;);
		}
	}
}
</pre>
<p><div style = "text-align:center"><script type="text/javascript"><!--
google_ad_client = "pub-8926707286265620";
/* 300x250, created 7/29/10 */
google_ad_slot = "4548376258";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><br />
<strong>The Output View &#8211; OutputView.as</strong><br />
The OutputView class receives Parsley messages in the same way the InputView class does. In fact they are both receiving the same Parsley messages on line 64, 73 and 82. The one difference is that the view is updated. </p>
<p>The messaging is the InputView buttons result in Parsley messages that the OutputView receives. </p>
<p>You also see the [Init] metatag on line 36 to further demonstrate Parsley providing its ready message to managed objects.</p>
<pre class="brush: as3; wrap-lines: false;">
package views
{
	import events.OnOffEvent;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	import flashx.textLayout.formats.TextAlign;
	/**
	 * Simple output view. Demonstrates receiving Parsley managed messages.
	 * */
	public class OutputView extends Sprite
	{
		/**
		 * Output TextField component.
		 * */
		private var tf:TextField;
		/**
		 * TextFormat for tf.
		 * */
		private var tfFormat:TextFormat;
		/**
		 * Constructor
		 * */
		public function OutputView()
		{
			trace(&quot;VIEW: OutputView()&quot;);
			super();
			createChildren();
		}
		/**
		 * Parsley calls automatically after context parsing.
		 */
		[Init]
		public function parsleyInit():void
		{
			trace(&quot;VIEW: OutputView.parsleyInit()&quot;);
		}
		/**
		 * Build the UI for this display object.
		 */
		public function createChildren():void
		{
			trace(&quot;VIEW: OutputView.createChildren()&quot;);
			// TextFormat
			tfFormat = new TextFormat();
			tfFormat.align = TextAlign.LEFT;
			tfFormat.bold = true;
			tfFormat.font = &quot;_typewriter&quot;;
			// TextField.
			tf = new TextField();
			tf.border = true;
			tf.multiline = true;
			tf.background = true;
			tf.width = 600;
			tf.height = 400;
			addChild(tf);
		}
		/**
		 * Parsley event handler. Listening for OnOffEvent all types.
		 * Other Parsley managed views can do the same.
		 */
		[MessageHandler]
		public function offOnEventHandler(event:OnOffEvent):void
		{
			addText(&quot;VIEW: OutputView.offOnEventHandler(...) - event.type: &quot; + event.type);
		}
		/**
		 * Parsley event handler. Listening for OnOffEvent ON type. Shows using a selector.
		 * Other Parsley managed views can do the same.
		 */
		[MessageHandler(selector=&quot;event.OnOffEvent.OFF&quot;)]
		public function offEventHandler(event:OnOffEvent):void
		{
			addText(&quot;VIEW: OutputView.offEventHandler(...)&quot;);
		}
		/**
		 * Parsley event handler. Listening for OnOffEvent all types. Shows using a selector.
		 * Other Parsley managed views can do the same.
		 */
		[MessageHandler(selector=&quot;event.OnOffEvent.ON&quot;)]
		public function onEventHandler(event:OnOffEvent):void
		{
			addText(&quot;VIEW: OutputView.onEventHandler(...)&quot;);
		}
		/**
		 * Appends to tf and adds to Flash trace output.
		 * @param message Text to append
		 * */
		private function addText(message:String):void
		{
			trace(message);
			tf.appendText(message + &quot;\n&quot;);
			tf.setTextFormat(tfFormat);
		}
	}
}
</pre>
<p><div style = "text-align:center"><script type="text/javascript"><!--
google_ad_client = "pub-8926707286265620";
/* 300x250, created 7/29/10 */
google_ad_slot = "4548376258";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><br />
<strong>The OnOffEvent &#8211; OnOffEvent.as</strong><br />
This is a typical Actionscript custom event class. The clone method is optional for Parsley messaging. However you might need to use the event for both Parsley and Flash messaging so it is no bother to include it for consistency.</p>
<p>Lines 9 and 10 show the event types. The string descriptors are used as selectors in two of the [MessageHandler] metatag methods in both the InputView and OutputView. Since these need to be hardwired in the selector for the [MessageHandler] metatag, you must manually manage any changes to the string descriptors throughout the application. An alternative is to create two separate events.</p>
<p>Data can be sent with the event via Parsley in the same way you are accustomed with Actionscript custom events.</p>
<pre class="brush: as3; wrap-lines: false;">
package events
{
	import flash.events.Event;
	/**
	 * Event for demonstrating Parsley. Simply reports an on or off state event.
	 * */
	public class OnOffEvent extends Event
	{
		public static const ON:String = &quot;event.OnOffEvent.ON&quot;;
		public static const OFF:String = &quot;event.OnOffEvent.OFF&quot;;
		public function OnOffEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false)
		{
			super(type, bubbles, cancelable);
			trace (&quot;EVENT: OnOffEvent(...) type: &quot; + type);
		}
		override public function clone():Event
		{
			return new OnOffEvent(type, bubbles, cancelable);
		}
	}
}
</pre>
<p><strong>The QuickButton- QuickButton.as</strong><br />
This is just an Actionscript SimpleButton to use for the demo.</p>
<pre class="brush: as3; wrap-lines: false;">
package ui.simple
{
	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.display.SimpleButton;
	import flash.events.MouseEvent;
	public class QuickButton extends SimpleButton
	{
		/**
		 * The up state background color;
		 * */
		private var upColor:uint   = 0xFFCC00;
		/**
		 * The over state background color;
		 * */
		private var overColor:uint = 0xCCFF00;
		/**
		 * The down state background color;
		 * */
		private var downColor:uint = 0x00CCFF;
		/**
		 * Width.
		 * */
		private var buttonWidth:Number;;
		/**
		 * Label.
		 * */
		private var label:String;
		/**
		 * Constructor.
		 * @param label The caption for button.
		 * @param buttonWidth Width of the button. Height is 1/3 of buttonWidth
		 * */
		public function QuickButton(label:String = &quot;Button&quot;, buttonWidth:Number = 80)
		{
			trace(&quot;UI: QuickButton() - label: &quot; + label);
			this.label = label;
			this.buttonWidth = buttonWidth;
			downState      = new QuickButtonDisplayShape(label, downColor, buttonWidth);
			overState      = new QuickButtonDisplayShape(label, overColor, buttonWidth);
			upState        = new QuickButtonDisplayShape(label, upColor, buttonWidth);
			hitTestState   = new QuickButtonDisplayShape(label, upColor, buttonWidth);
			useHandCursor  = true;
		}
	}
}
</pre>
<p><strong>The QuickButton Skin &#8211; QuickButtonDisplayShape.as</strong><br />
How I skinned the QuickButton.</p>
<pre class="brush: as3; wrap-lines: false;">
package ui.simple
{
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flashx.textLayout.formats.TextAlign;
	/**
	 * Rounded button with text label. Width and height and not margins or padding.
	 * */
	public class QuickButtonDisplayShape extends Sprite
	{
		/**
		 * Background color.
		 * */
		private var bgColor:uint;
		/**
		 * Width.
		 * */
		private var buttonWidth:Number;
		/**
		 * Height.
		 * */
		private var buttonHeight:Number;
		/**
		 * Label TextField component.
		 * */
		private var tf:TextField;
		/**
		 * Left padding for tf inside the button shape.
		 * */
		private const TF_LEFT_PADDING:Number = 6;
		/**
		 * Right padding for tf inside the button shape.
		 * */
		private const TF_RIGHT_PADDING:Number = 6;
		/**
		 * Ratio of button height to the buttonWidth.
		 * */
		private const BUTTON_HEIGHT_RATIO:Number = 1/3;
		/**
		 * Constructor.
		 * @param label The caption for button.
		 * @param bgColor Color for the button background.
		 * @param buttonWidth Width of the button. Height is 1/3 of buttonWidth
		 * */
		public function QuickButtonDisplayShape(label:String,bgColor:Number, buttonWidth:Number)
		{
			// Consume parameters
			this.bgColor = bgColor;
			this.buttonWidth = buttonWidth;
			this.buttonHeight = buttonWidth * BUTTON_HEIGHT_RATIO;
			// Draw button graphics.
			draw();
			// TextField for the button caption.
			tf = new TextField();
			var tfFormat:TextFormat = new TextFormat();
			tf.text = label;
			// Format for centering.
			tfFormat.align = TextAlign.CENTER;
			tfFormat.bold = true;
			tfFormat.font = &quot;_sans&quot;;
			//tf.border = true; // Design guide for layout.
			tf.setTextFormat(tfFormat);
			// Position and size the caption.
			tf.x = TF_LEFT_PADDING;
			tf.width = buttonWidth - (TF_LEFT_PADDING + TF_RIGHT_PADDING);
			tf.height = tf.textHeight + 2;
			tf.y = Math.max(0, ( buttonHeight - (tf.textHeight + 4)) / 2);
			// Add caption.
			addChild(tf);
		}
		/**
		 * Draw graphics.
		 * */
		private function draw():void
		{
			graphics.beginFill(bgColor);
			graphics.drawRoundRect(0, 0, buttonWidth, buttonHeight, 20, 20);
			graphics.endFill();
		}
	}
}
</pre>
<div id="fb-root"></div>
<p><script src="http://connect.facebook.net/en_US/all.js#appId=105467682877384&amp;xfbml=1"></script><fb:like href="http://www.lonhosford.com/lonblog/2011/01/26/parsley-hello-world-for-a-flash-builder-actionscript-project/" send="true" width="450" show_faces="true" font=""></fb:like></p>
<div id="fb-root"></div>
<p><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:comments href="http://www.lonhosford.com/lonblog/2011/01/26/parsley-hello-world-for-a-flash-builder-actionscript-project/" num_posts="2" width="500"></fb:comments></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lonhosford.com/lonblog/2011/01/26/parsley-hello-world-for-a-flash-builder-actionscript-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FLVPlayback Component in a Flash Builder 4 Actionscript Project</title>
		<link>http://www.lonhosford.com/lonblog/2011/01/19/flvplayback-component-in-a-flash-builder-4-actionscript-project/</link>
		<comments>http://www.lonhosford.com/lonblog/2011/01/19/flvplayback-component-in-a-flash-builder-4-actionscript-project/#comments</comments>
		<pubDate>Thu, 20 Jan 2011 03:02:40 +0000</pubDate>
		<dc:creator>Lon Hosford</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Actionscript]]></category>

		<guid isPermaLink="false">http://www.lonhosford.com/lonblog/?p=1231</guid>
		<description><![CDATA[This is an example of how to include the Flash CS5 Actionscript 3 FLVPlayback component in a Flash Builder 4 Actionscript project. I used Mark Walters&#8217;s FLVPlayback directly in Flex article to understand how to get the FLVPlaybackAS3.swc file needed and the rest was very similar to doing this in Flash CS5. In locating the [...]]]></description>
			<content:encoded><![CDATA[<p>This is an example of how to include the Flash CS5 Actionscript 3 FLVPlayback component in a Flash Builder 4 Actionscript project. <img class="alignleft" src="http://lh5.ggpht.com/_e5pwU0LJbN8/TTeeXBUhJiI/AAAAAAAAFxw/9C9c7O64eT4/s800/FlashBuilder4VideoPlayer_published.png" alt="" width="400" height="305" />I used Mark Walters&#8217;s <a href="http://yourpalmark.com/2008/04/30/flvplayback-directly-in-flex/" target="_blank">FLVPlayback directly in Flex</a> article to understand how to get the FLVPlaybackAS3.swc file needed and the rest was very similar to doing this in Flash CS5. </p>
<p>In locating the FLVPlaybackAS3.swc I was on a Mac and just used Finder to locate the files with &#8220;FLVPlaybackAS&#8221; as my search string. </p>
<p>You need include the FLVPlaybackAS swc in your project. Create a folder in your project and then in the project properties include the folder in the Actionscript Build Path under Library Path. I like to call this folder libs.</p>
<p>You need to get a skin SWF file for the FLVPlayer. The easiest method is to create a Flash CS5 document and add the FLVPlayer component. Then include your video and select the skin in the component properties. Then publish. You will see the SWF file for the skin for example SkinOverAll.swf is one possible from CS5. </p>
<p><strong>Downloads</strong></p>
<ul style="padding-top: 10px;">
<li><a href="http://www.lonhosford.com/content/flex/flvplayer/FLVPlayBackEx01.zip" onClick="javascript: pageTracker._trackPageview('/downloads/flvplayer/FLVPlayBackEx01.zip'); ">Flex Builder Actionscript Project</a></li>
</ul>
<p><div style = "text-align:center"><script type="text/javascript"><!--
google_ad_client = "pub-8926707286265620";
/* 300x250, created 7/29/10 */
google_ad_slot = "4548376258";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><br />
<strong>Application Class &#8211; FLVPlayerEx01</strong><br />
You need to add your Flash video FLV file on line 19 and the FLVPlayer skin SWF file on line 21. These could be in the debug-bin folder or another project level folder. This all depends on where you plan to keep these files in relation to the published swf.</p>
<pre class="brush: as3; wrap-lines: false;">
package
{
	import fl.video.FLVPlayback;
	import fl.video.VideoScaleMode;
	import flash.display.Sprite;
	[SWF (width=640, height=450, backgroundColor=0xeeeeee, frameRate=24)]
	/**
	 * Starter application class demonstration loading the FLVPlayer Component.
	 * */
	public class FLVPlayBackEx01 extends Sprite
	{
		private var flashVars:Object;
		public function FLVPlayBackEx01()
		{
			var videoPlayer:FLVPlayback = new FLVPlayback();
			videoPlayer.width = 640;
			videoPlayer.height = 450;
			addChild( videoPlayer );
			videoPlayer.play( &quot;YOUR_FLV_FILE_NAME_HERE&quot; );
			videoPlayer.scaleMode = VideoScaleMode.MAINTAIN_ASPECT_RATIO;
			videoPlayer.skin = &quot;YOUR_SKIN_SWF_FILE_NAME_HERE&quot;;
			videoPlayer.skinAutoHide = true;
		}
	}
}
</pre>
<div id="fb-root"></div>
<p><script src="http://connect.facebook.net/en_US/all.js#appId=105467682877384&amp;xfbml=1"></script><fb:like href="http://www.lonhosford.com/lonblog/2011/01/19/flvplayback-component-in-a-flash-builder-4-actionscript-project/" send="true" width="450" show_faces="true" font=""></fb:like></p>
<div id="fb-root"></div>
<p><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:comments href="http://www.lonhosford.com/lonblog/2011/01/19/flvplayback-component-in-a-flash-builder-4-actionscript-project/" num_posts="2" width="500"></fb:comments><br />
<div style = "text-align:center"><script type="text/javascript"><!--
google_ad_client = "pub-8926707286265620";
/* 300x250, created 7/29/10 */
google_ad_slot = "4548376258";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lonhosford.com/lonblog/2011/01/19/flvplayback-component-in-a-flash-builder-4-actionscript-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

