<?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>markstar</title>
	<atom:link href="http://markstar.co.uk/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://markstar.co.uk/blog</link>
	<description>blogging about the flash platform</description>
	<lastBuildDate>Mon, 08 Mar 2010 15:13:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Twitter Search Demo using Robotlegs and Signals</title>
		<link>http://markstar.co.uk/blog/2010/flashplatform/twitter-search-demo-using-robotlegs-and-signals/</link>
		<comments>http://markstar.co.uk/blog/2010/flashplatform/twitter-search-demo-using-robotlegs-and-signals/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 12:00:09 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Flash Platform]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Robotlegs]]></category>
		<category><![CDATA[AS3-Signals]]></category>
		<category><![CDATA[Demo]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Signals]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://markstar.co.uk/blog/?p=292</guid>
		<description><![CDATA[In light of my recent post about why Robotlegs benefits from AS3-Signals I thought it was only fitting that I updated my Twitter Search demo.]]></description>
			<content:encoded><![CDATA[<p>In light of my recent post about <a title="Why Robotlegs benefits from AS3-Signals" href="http://markstar.co.uk/blog/2010/flashplatform/why-robotlegs-benefits-from-as3-signals/" target="_blank">why Robotlegs benefits from AS3-Signals</a> I thought it was only fitting that I updated my Twitter Search demo! This was really easy to do; partly because the demo is so small. It also allowed me to use interfaces to reference view components in the mediators (one of the advantages of using Signals). The use of interfaces makes it really easy to swap out the view for something different, like a mobile version, without changing any core functionality. Anyway, click the image below to view the demo; view source is enabled and I&#8217;ve included the libs and html-template folders this time so it should be easier for you to compile!</p>
<p><span id="more-292"></span></p>
<p style="text-align: center;"><a href="http://markstar.co.uk/flash/Robotlegs/TwitterSearchSignals/TwitterSearchSignals.html" target="_blank"><img class="aligncenter size-full wp-image-293" title="Twitter Search Demo using Signals" src="http://markstar.co.uk/blog/wp-content/uploads/2010/03/TwitterSearchDemoSignals.jpg" alt="Click to view Twitter Search Demo using Signals" width="300" height="495" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://markstar.co.uk/blog/2010/flashplatform/twitter-search-demo-using-robotlegs-and-signals/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Why Robotlegs benefits from AS3-Signals</title>
		<link>http://markstar.co.uk/blog/2010/flashplatform/why-robotlegs-benefits-from-as3-signals/</link>
		<comments>http://markstar.co.uk/blog/2010/flashplatform/why-robotlegs-benefits-from-as3-signals/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 09:00:27 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Flash Platform]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Robotlegs]]></category>
		<category><![CDATA[AS3-Signals]]></category>
		<category><![CDATA[Signals]]></category>

		<guid isPermaLink="false">http://markstar.co.uk/blog/?p=282</guid>
		<description><![CDATA[This post discusses one of the benefits of using AS3-Signals with Robotlegs over the standard Event model.]]></description>
			<content:encoded><![CDATA[<h3>My problem with using the Event Model and Robotlegs</h3>
<p>One of the things that bugs me about the use of the event model with <a title="Robotlegs website" href="http://www.robotlegs.org/" target="_blank">Robotlegs</a> is that Mediators are tightly coupled with the views. Take my <a title="Twitter Search Demo using Robotlegs and Events" href="http://markstar.co.uk/blog/?p=261" target="_blank">Twitter Search Demo</a> for example, the SearchEntryMediator class expects an instance of the SearchEntry class as its view, see below.</p>
<p><span id="more-282"></span></p>
<p><script src="http://gist.github.com/324461.js"></script></p>
<p>One suggestion could be type the view to an interface in the mediator, but this is too loosely coupled because an interface cannot define the events an object can dispatch. There are a few solutions to this issue, for example we could use function callbacks, however <a title="Robert Penner on Twitter" href="http://twitter.com/robpenner/" target="_blank">Robert Penner</a> has come up with a better solution, <a title="AS3-Signals at GitHub" href="http://github.com/robertpenner/as3-signals" target="_blank">AS3-Signals</a>.</p>
<h3>The solution: AS3-Signals</h3>
<p><a title="Robotlegs website" href="http://www.robotlegs.org/" target="_blank">Robotlegs</a> and <a title="AS3-Signals at GitHub" href="http://github.com/robertpenner/as3-signals" target="_blank">AS3-Signals</a> work really well together, especially with the introduction of the <a title="Command Signal Extension at GitHub" href="http://github.com/joelhooks/signals-extensions-CommandSignal" target="_blank">Command Signal Extension</a>. Each of these libraries don&#8217;t rely on string constants to function, they are strongly typed, therefore the compiler is able to throw errors much sooner if something is wrong.</p>
<p>A Signal gives an event a concrete membership in a class, for this reason we are able to include Signals in interfaces. Using this the SearchEntryMediator in my <a title="Twitter Search Demo using Robotlegs and Events" href="http://markstar.co.uk/blog/?p=261" target="_blank">Twitter Search Demo</a> can type the view to an ISearchEntry, and any class that implements this interface must include the searchRequested signal, see below.</p>
<p><script src="http://gist.github.com/324470.js"></script></p>
<p>The interface is very simple and just defines the searchRequested signal.</p>
<p><script src="http://gist.github.com/324484.js"></script></p>
<h3>Why bother?</h3>
<p>It&#8217;s a good question, why should we go to the effort of creating interfaces for our views? We could quite easily continue to use the Event model with Robotlegs and it would work, but the use of interfaces would be beneficial for a multi-platform Flash application or for a workflow that involved more than one person.</p>
<p>Imagine an application that is to be deployed to many different devices that have various screen sizes, some can use a mouse, some can be touch enabled and some are restricted to keys. To create the best user experience you would want the view of your application, and the interaction with that view, to be tailored to that device. By using interfaces for our views we can use the same code base for all applications but have different views for each device; as long as our views implement our interfaces the application will work. More advantages to this are seen if different people implement the views; by using Signals in the interface the person developing the view must implement them whereas there&#8217;s nothing specify that the person must implement an event.</p>
<p>P.S It&#8217;s also worth noting that there are many other benefits to using AS3-Signals, for example they provide <a title="AS3-Signals performance tests" href="http://alecmce.com/as3/events-and-signals-performance-tests" target="_blank">significant speed improvements</a> over using Events, not just the ability to define them in interfaces.</p>
]]></content:encoded>
			<wfw:commentRss>http://markstar.co.uk/blog/2010/flashplatform/why-robotlegs-benefits-from-as3-signals/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Twitter Search Demo using Robotlegs and Events</title>
		<link>http://markstar.co.uk/blog/2010/flashplatform/flex/twitter-search-demo-using-robotlegs/</link>
		<comments>http://markstar.co.uk/blog/2010/flashplatform/flex/twitter-search-demo-using-robotlegs/#comments</comments>
		<pubDate>Sun, 07 Mar 2010 15:13:42 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Flash Platform]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Robotlegs]]></category>
		<category><![CDATA[Demo]]></category>
		<category><![CDATA[Event Model]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://markstar.co.uk/blog/?p=261</guid>
		<description><![CDATA[I've had chance to play with Robotlegs this weekend and have really enjoyed it. This post shows a quick demo I've put together using Robotlegs and the Twitter Search API.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had chance to play with <a title="Robotlegs website" href="http://www.robotlegs.org/" target="_blank">Robotlegs</a> this weekend and have really enjoyed it. It&#8217;s really lightweight and you find that you spend more time coding rather than repeating the same tasks like you would do in other frameworks.</p>
<p>The first demo I put together was a simple <a title="TwitterSearch Demo" href="http://markstar.co.uk/flash/Robotlegs/TwitterSearch/TwitterSearch.html" target="_blank">Twitter Search application</a>, using the <a title="Twitter Search API documentation" href="http://apiwiki.twitter.com/Twitter-API-Documentation" target="_blank">Twitter Search API</a>. You can see the demo in all it&#8217;s glory by clicking the image below! View Source is enabled so you can download the source and have a play; you will need the Robotlegs SWC to compile though, you&#8217;ll find this on the <a title="Robotlegs website" href="http://www.robotlegs.org/" target="_blank">Robotlegs website</a>. If you have any feedback or questions please leave a comment below!<br />
<span id="more-261"></span></p>
<p style="text-align: center;"><a title="Click to view the Twitter Search demo" href="http://markstar.co.uk/flash/Robotlegs/TwitterSearch/TwitterSearch.html" target="_blank"><img class="size-full wp-image-264 aligncenter" title="Click to view the Twitter Search demo" src="http://markstar.co.uk/blog/wp-content/uploads/2010/03/TwitterSearchDemo.jpg" alt="Click to view the Twitter Search demo" width="300" height="400" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://markstar.co.uk/blog/2010/flashplatform/flex/twitter-search-demo-using-robotlegs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting Started with Robotlegs</title>
		<link>http://markstar.co.uk/blog/2010/flashplatform/actionscript/getting-started-with-robotlegs/</link>
		<comments>http://markstar.co.uk/blog/2010/flashplatform/actionscript/getting-started-with-robotlegs/#comments</comments>
		<pubDate>Sun, 07 Mar 2010 11:43:15 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash Platform]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Robotlegs]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[micro-architecture]]></category>

		<guid isPermaLink="false">http://markstar.co.uk/blog/?p=247</guid>
		<description><![CDATA[Robotlegs has been gaining a lot of ground over the last few months within the Flash community, and so I thought it was about time I gave it a shot. This post contains links to some useful resources to help you get started with Robotlegs.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.robotlegs.org/"><img class="size-full wp-image-251 alignleft" title="Robotlegs logo" src="http://markstar.co.uk/blog/wp-content/uploads/2010/03/RobotLegs1.jpg" alt="Robotlegs logo" width="150" height="130" /></a></p>
<p><a title="Robotlegs website" href="http://www.robotlegs.org/" target="_blank">Robotlegs</a> has been gaining a lot of ground over the last few months within the Flash community, and so I thought it was about time I gave it a shot. This post includes some of the resources I found really useful when getting started with the framework.<br />
<span id="more-247"></span></p>
<h3>What is Robotlegs?</h3>
<p>If you haven&#8217;t heard of <a title="Robotlegs website" href="http://www.robotlegs.org/" target="_blank">Robotlegs</a> before there&#8217;s a good explanation on their <a title="Robotlegs website" href="http://www.robotlegs.org/" target="_blank">website</a>:</p>
<blockquote><p><strong>Robotlegs</strong> is a <strong>pure AS3</strong> micro-architecture (framework) with a light footprint and limited scope. Simply put, Robotlegs is there to help you wire your objects together. It provides the <strong>glue</strong> that your application needs to easily function in a decoupled way. Through the use of automated metadata based dependency injection Robotlegs <strong>removes boilerplate</strong> code in an application. By promoting loose coupling and avoiding the use of Singletons and statics in the framework Robotlegs can help you write code that is highly <strong>testable</strong>.</p></blockquote>
<p><a title="Robotlegs website" href="http://www.robotlegs.org/" target="_blank">Robotlegs</a> was heavily influenced by <a title="PureMVC website" href="http://puremvc.org/" target="_blank">PureMVC</a>, another pure AS3 micro-architecture framework, therefore if you are familiar with the roles and architecture PureMVC has then you will find Robotlegs easy to pick up. You will also notice that there&#8217;s a helluva lot less boiler-plate code in Robotlegs!</p>
<h3>Where should I start?</h3>
<p>A lot of people recommend getting started with the Robotlegs best practices document and whilst this is a good place to start it can be really overwhelming, even for someone familiar with frameworks, so I&#8217;d recommend watching the following video tutorials first.</p>
<ul>
<li><a title="http://pv3d.org/2009/11/18/robotlegs-hello-world-video-tutorial/" href="http://pv3d.org/2009/11/18/robotlegs-hello-world-video-tutorial/" target="_blank">RobotLegs Hello World Video Tutorial</a> by <a title="John Lindquist on Twitter" href="http://twitter.com/johnlindquist" target="_blank">John Lindquist</a></li>
<li><a title="Robotlegs MVCS: Walkthrough of an AIR Twitter Client" href="http://joelhooks.com/2009/11/11/a-walkthrough-of-an-air-twitter-client-using-robotlegs-mvcs/" target="_blank">Robotlegs MVCS: Walkthrough of an AIR Twitter Client</a> by <a title="Joel Hooks on Twitter" href="http://twitter.com/jhooks" target="_blank">Joel Hooks</a></li>
</ul>
<p>Once you watched the videos you&#8217;ll have an rough understanding of each of the roles within Robotlegs; this is a great time to check out the <a title="Robotlegs Best Practices" href="http://wiki.github.com/robotlegs/robotlegs-framework/best-practices" target="_blank">best practices document</a> and build on that knowledge. If you then watch the video tutorials again you should really understand exactly what&#8217;s going on!</p>
<h3>What&#8217;s next?</h3>
<p>Start using it! You can download the latest release version from the <a title="Robotlegs website" href="http://www.robotlegs.org/" target="_blank">Robotlegs website</a> or, if you&#8217;re familiar with GitHub, you can <a title="Robotlegs on GitHub" href="http://github.com/robotlegs/robotlegs-framework" target="_blank">fork the repository</a>. There&#8217;s some really useful <a title="Robotlegs Demos on GitHub" href="http://github.com/robotlegs/robotlegs-demos-Bundle" target="_blank">demos available on GitHub</a> too, which include examples of using the framework with Flash, modular development and the integration of services such as Flickr and GoogleMaps.</p>
<p>Don&#8217;t forget, if you&#8217;re really stuck you can always <a title="Robotlegs knowledge base" href="http://knowledge.robotlegs.org/" target="_blank">ask for help</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://markstar.co.uk/blog/2010/flashplatform/actionscript/getting-started-with-robotlegs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HYPE ShapeLayout Experiment</title>
		<link>http://markstar.co.uk/blog/2010/flashplatform/actionscript/hype-shapelayout-experiment/</link>
		<comments>http://markstar.co.uk/blog/2010/flashplatform/actionscript/hype-shapelayout-experiment/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 22:59:13 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash Platform]]></category>
		<category><![CDATA[Experiment]]></category>
		<category><![CDATA[HYPE]]></category>

		<guid isPermaLink="false">http://markstar.co.uk/blog/?p=236</guid>
		<description><![CDATA[I couldn't resist sharing one of my recent experiments with the HYPE framework. It also uses the MinimalComps component set. The example makes use of the ObjectPool, ColorPool and ShapeLayout classes.]]></description>
			<content:encoded><![CDATA[<p>I couldn&#8217;t resist sharing one of my recent experiments with the <a title="HYPE Framework" href="http://hype.joshuadavis.com/" target="_blank">HYPE framework</a> (it also uses the <a title="MinimalComps" href="http://www.bit-101.com/minimalcomps/" target="_blank">MinimalComps</a> component set). The example makes use of the ObjectPool, ColorPool and ShapeLayout classes. It&#8217;s really cool that you can put stuff like this together in just a few hours. I will be adding the source to GitHub soon, which should hopefully make it more interesting!</p>
<p>Update: The source code is <a title="ShapeLayout Experiment source code" href="http://github.com/markstar/hype/tree/master/examples/markstar/HypeShapeLayoutTest/" target="_blank">now available</a>.<br />
<span id="more-236"></span></p>
<p style="text-align: center;">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_HypeShapeLayoutTest_1471492313"
			class="flashmovie"
			width="592"
			height="270">
	<param name="movie" value="http://markstar.co.uk/flash/hype/HypeShapeLayoutTest.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://markstar.co.uk/flash/hype/HypeShapeLayoutTest.swf"
			name="fm_HypeShapeLayoutTest_1471492313"
			width="592"
			height="270">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
]]></content:encoded>
			<wfw:commentRss>http://markstar.co.uk/blog/2010/flashplatform/actionscript/hype-shapelayout-experiment/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>FileReference woes on MACs</title>
		<link>http://markstar.co.uk/blog/2010/flashplatform/actionscript/filereference-woes-on-macs/</link>
		<comments>http://markstar.co.uk/blog/2010/flashplatform/actionscript/filereference-woes-on-macs/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 22:37:02 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[2038]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[FileReference]]></category>
		<category><![CDATA[MAC]]></category>

		<guid isPermaLink="false">http://markstar.co.uk/blog/?p=221</guid>
		<description><![CDATA[Today I found out (the hard way) that there are several issues that can occur when trying to upload files using the FileReference class on MACs. This post identifies those issues and their solutions.]]></description>
			<content:encoded><![CDATA[<p>Today I found out (the hard way) that there are several issues that can occur when trying to upload files using the FileReference class on MACs.</p>
<h3>FileReference.type always returns null</h3>
<p>It&#8217;s often that case that you want to restrict the file type the user can upload, or perform different processes depending on the type of file uploaded. However the type property of a FileReference object always returns null on MACs; to work around this you must get the file extension manually. To do this you can use the following code (it&#8217;s good practice to always convert the file extension to lower case before working with it).<br />
<span id="more-221"></span><script src="http://gist.github.com/308111.js"></script></p>
<h3>Server script must return data</h3>
<p>When uploading files using the FileReference class you may experience the upload getting stuck at 100% progress and never firing the Event.COMPLETE event. This will only happen on the MAC and it&#8217;s because Flash doesn&#8217;t realise that the file has finished uploading until it gets a response from the server. I don&#8217;t why this is implemented differently on the different operating systems, but to overcome this problem your server script must write something to the page (it can just be a space character!).</p>
<h3>Parameters must be added using URLVariables</h3>
<p>You may want to pass URL parameters to the server script when uploading a file, and in our case the parameters and the URL were passed as one string via Flash vars. MACs don&#8217;t like this. So instead we have to pass the parameters using the data property of the URLRequest; to do this you need to use the URLVariables class. The following code snippet shows you how.<br />
<script src="http://gist.github.com/309031.js"></script></p>
<h3>Feedback!</h3>
<p>Has anyone else come across any weird quirks or handy hints when working with the FileReference class? Please leave a comment if you have and I&#8217;ll add it to the post!</p>
]]></content:encoded>
			<wfw:commentRss>http://markstar.co.uk/blog/2010/flashplatform/actionscript/filereference-woes-on-macs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clipboard Management using the StatefulToolkit</title>
		<link>http://markstar.co.uk/blog/2010/flashplatform/actionscript/clipboard-management-using-the-statefultoolkit/</link>
		<comments>http://markstar.co.uk/blog/2010/flashplatform/actionscript/clipboard-management-using-the-statefultoolkit/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 09:00:10 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash Platform]]></category>
		<category><![CDATA[StatefulToolkit]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://markstar.co.uk/blog/?p=196</guid>
		<description><![CDATA[This tutorial will build upon the Introduction to using the StatefulToolkit example; it will add the ability to utilize the Clipboard in our example. The example will use the ClipboardUtil, which is a utility class included in the toolkit that allows the user to copy and paste objects using the clipboard. The example application will build upon the last one; it will allow the user to position four circles, to save and load the state of the circles (i.e. where the circles are positioned) and to copy and paste the circles.]]></description>
			<content:encoded><![CDATA[<h3>Tutorial Overview</h3>
<p>This tutorial will build upon the <a title="Introduction to using the StatefulToolkit" href="http://markstar.co.uk/blog/2010/statefultoolkit/introduction-to-using-statefultoolkit/" target="_blank">Introduction to using the StatefulToolkit</a> example; it will add the ability to utilize the Clipboard in our example. The example will use the ClipboardUtil, which is a utility class included in the toolkit that allows the user to copy and paste objects using the clipboard. The example application will build upon the last one; it will allow the user to position four circles, to save and load the state of the circles (i.e. where the circles are positioned) and to copy and paste the circles. The example can be <a title="View the compiled application" href="#compiledapplication">seen here</a> and <a title="Application Source Code" href="#sourcecode">source files are available</a>.</p>
<h3>Preparation</h3>
<p>Before you being implementing this tutorial make sure you have the latest version of the <a title="StatefulToolkit Downloads at GitHub" href="http://github.com/markstar/StatefulToolkit/downloads" target="_blank">StatefulToolkit SWC</a>, and that you’re project is set to target Flash Player 10 (if you want to target FP9, simple replace the Vector with an array in the circle container) . This tutorial also uses Keith Peter’s <a title="Minimal Comps at BIT-101" href="http://www.bit-101.com/minimalcomps/" target="_blank">Minimal Comps</a> component set to create the buttons in the application so you may want to grab the SWC for that too, but you can use your own buttons if you prefer. Both SWC files are included in the <a title="Application Source Code" href="#sourcecode">available flex project</a>.<br />
<span id="more-196"></span></p>
<h3>Creating the Statable Object</h3>
<p>The original circle class could be left as it is, however it would be helpful to know which circle we have selected, so we know which one we are adding to the clipboard. In order to do show this we will add two new methods to the Circle; select and deselect. Each method draws the circle in a different colour. The full contents of this class can be seen below.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> couk.markstar.examples.ui
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> couk.markstar.statefultoolkit.core.IStatable;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Circle extends <span style="color: #004993;">Sprite</span> implements IStatable
	<span style="color: #000000;">&#123;</span>
		<span style="color: #3f5fbf;">/**
		 * The constructor draws the circle with a grey outline
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Circle<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #004993;">drawCircle</span><span style="color: #000000;">&#40;</span> 0x999999 <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Change the display of the circle to show it's selected
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">select</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">drawCircle</span><span style="color: #000000;">&#40;</span> 0x990000 <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Change the display of the circle to the default
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> deselect<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">drawCircle</span><span style="color: #000000;">&#40;</span> 0x999999 <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Retrieve the state of the circle storing the x and y properties
		 *
		 * @return The current state of the circle as an XML string
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> retrieveState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> xml<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">'&lt;object&gt;'</span>;
			xml <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">'&lt;x&gt;'</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">'&lt;/x&gt;'</span>;
			xml <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">'&lt;y&gt;'</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">'&lt;/y&gt;'</span>;
			xml <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">'&lt;/object&gt;'</span>;
			<span style="color: #0033ff; font-weight: bold;">return</span> xml;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Set the state of the circle by getting it's x and y values from the xml
		 *
		 * @param state The new state of the circle
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> setState<span style="color: #000000;">&#40;</span> state<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">XML</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">x</span> = <span style="color: #004993;">Number</span><span style="color: #000000;">&#40;</span> state.<span style="color: #004993;">x</span> <span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">y</span> = <span style="color: #004993;">Number</span><span style="color: #000000;">&#40;</span> state.<span style="color: #004993;">y</span> <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Used internally for creating the circles' graphics
		 * 
		 * @param lineColor The color of the line around the circle
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">drawCircle</span><span style="color: #000000;">&#40;</span> lineColor<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">graphics</span>.<span style="color: #004993;">clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">graphics</span>.<span style="color: #004993;">lineStyle</span><span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">1</span>, lineColor <span style="color: #000000;">&#41;</span>
			<span style="color: #004993;">graphics</span>.<span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span> 0xFFFFFFF <span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">graphics</span>.<span style="color: #004993;">drawCircle</span><span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #000000; font-weight:bold;">10</span> <span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">graphics</span>.<span style="color: #004993;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<h3>Creating the Container</h3>
<p>Previously the circle container implemented the IStatable interface but it now implements the IStateContainer interface, because it needs to interact with the ClipboardUtil. The IStateContainer interface inherits functionality from the IStatable interface, so the circle container is still required to have the methods setState and retrieveState, but it is also required to have the methods addObjectByState, hasSelectedObject and retrieveSelectedObject.</p>
<p>The addObjectByState method was already implemented in the previous function, but was used internally, now it will be used by the ClipboardUtil when the user is pasting an object. In order to implement hasSelectedObject and retrieveSelectedObject we must add to the circleDownListener. After setting the _currentCircle we can call the select method of the circle to show that it has been selected. Then, before we set the _currentCircle to the one the user has mouse downed, we must deselect the old one by calling it&#8217;s deselect method. The full contents of this class can be seen below.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> couk.markstar.examples.ui
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> couk.markstar.statefultoolkit.core.IStatable;
	<span style="color: #0033ff; font-weight: bold;">import</span> couk.markstar.statefultoolkit.core.IStateContainer;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">MouseEvent</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span>.<span style="color: #004993;">Point</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> CircleContainer extends <span style="color: #004993;">Sprite</span> implements IStateContainer
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #6699cc; font-weight: bold;">var</span> _circles<span style="color: #000000; font-weight: bold;">:</span>Vector.<span style="color: #000000; font-weight: bold;">&lt;</span>Circle<span style="color: #000000; font-weight: bold;">&gt;</span>;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #6699cc; font-weight: bold;">var</span> _currentCircle<span style="color: #000000; font-weight: bold;">:</span>Circle;
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #6699cc; font-weight: bold;">var</span> _dragOffset<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Point</span>;
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * The constructor the vector containing the circles shown in the container
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> CircleContainer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			_circles = <span style="color: #0033ff; font-weight: bold;">new</span> Vector.<span style="color: #000000; font-weight: bold;">&lt;</span>Circle<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Retrieve the selected object
		 *
		 * @return The selected object
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> retrieveSelectedObject<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span>IStatable
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> _currentCircle;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Check whether the container has a selected object
		 *
		 * @return Boolean denoting if the container has a selected object
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> hasSelectedObject<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span><span style="color: #000000;">&#40;</span> _currentCircle <span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">?</span> <span style="color: #0033ff; font-weight: bold;">true</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">false</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Retrieve the state of the container and all contained circles
		 *
		 * @return The current state of the container, including the state's of all circles
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> retrieveState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> xml<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;&lt;container&gt;&quot;</span>;
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span> <span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">0</span>; i <span style="color: #000000; font-weight: bold;">&lt;</span> _circles.<span style="color: #004993;">length</span>; i<span style="color: #000000; font-weight: bold;">++</span> <span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				xml <span style="color: #000000; font-weight: bold;">+</span>= _circles<span style="color: #000000;">&#91;</span> i <span style="color: #000000;">&#93;</span>.retrieveState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #000000;">&#125;</span>
			xml <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;&lt;/container&gt;&quot;</span>;
			<span style="color: #0033ff; font-weight: bold;">return</span> xml;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Add an object to the container by it's state.
		 *
		 * @param state The state of the object to add, in this case the circle
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> addObjectByState<span style="color: #000000;">&#40;</span> state<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">XML</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> circle<span style="color: #000000; font-weight: bold;">:</span>Circle = <span style="color: #0033ff; font-weight: bold;">new</span> Circle<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			circle.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">MOUSE_DOWN</span>, circleDownListener <span style="color: #000000;">&#41;</span>;
			circle.setState<span style="color: #000000;">&#40;</span> state <span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span> circle <span style="color: #000000;">&#41;</span>;
			_circles<span style="color: #000000;">&#91;</span> _circles.<span style="color: #004993;">length</span> <span style="color: #000000;">&#93;</span> = circle;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Set the state of the container by adding all circles contained within the state. The container will be cleared first.
		 *
		 * @param state The new state of the container
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> setState<span style="color: #000000;">&#40;</span> state<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">XML</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			clearContainer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span> <span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">0</span>; i <span style="color: #000000; font-weight: bold;">&lt;</span> state.object.<span style="color: #004993;">length</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>; i<span style="color: #000000; font-weight: bold;">++</span> <span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				addObjectByState<span style="color: #000000;">&#40;</span> <span style="color: #004993;">XML</span><span style="color: #000000;">&#40;</span> state.object<span style="color: #000000;">&#91;</span> i <span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Clear the container of all circles
		 *
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> clearContainer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span> <span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">0</span>; i <span style="color: #000000; font-weight: bold;">&lt;</span> _circles.<span style="color: #004993;">length</span>; i<span style="color: #000000; font-weight: bold;">++</span> <span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span> _circles<span style="color: #000000;">&#91;</span> i <span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#41;</span>;
			<span style="color: #000000;">&#125;</span>
			_circles.<span style="color: #004993;">splice</span><span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">0</span>, _circles.<span style="color: #004993;">length</span> <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/*
		 * The following methods are all event listeners to enable the circles to be dragged
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> circleDownListener<span style="color: #000000;">&#40;</span> e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #009900;">// Deselect the current circle (if there is one)</span>
			<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> _currentCircle <span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				_currentCircle.deselect<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #000000;">&#125;</span>
&nbsp;
			_currentCircle = Circle<span style="color: #000000;">&#40;</span> e.<span style="color: #004993;">currentTarget</span> <span style="color: #000000;">&#41;</span>;
			_currentCircle.<span style="color: #004993;">select</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">MOUSE_MOVE</span>, circleMouseMoveListener <span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">MOUSE_UP</span>, circleMouseUpListener <span style="color: #000000;">&#41;</span>;
&nbsp;
			_dragOffset = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span> _currentCircle.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #004993;">mouseX</span>, _currentCircle.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #004993;">mouseY</span> <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> circleMouseMoveListener<span style="color: #000000;">&#40;</span> e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			_currentCircle.<span style="color: #004993;">x</span> = <span style="color: #004993;">mouseX</span> <span style="color: #000000; font-weight: bold;">+</span> _dragOffset.<span style="color: #004993;">x</span>;
			_currentCircle.<span style="color: #004993;">y</span> = <span style="color: #004993;">mouseY</span> <span style="color: #000000; font-weight: bold;">+</span> _dragOffset.<span style="color: #004993;">y</span>;
			e.<span style="color: #004993;">updateAfterEvent</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> circleMouseUpListener<span style="color: #000000;">&#40;</span> e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">MOUSE_MOVE</span>, circleMouseMoveListener <span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">MOUSE_UP</span>, circleMouseUpListener <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<h3>Creating the Document Class</h3>
<p>The document class for this application very similar to the previous one. It was already responsible for creating the save and load buttons, creating the circle container, registering the circle container with the FileUtil and initialising the container with a default state. The only thing we need to add is the registration of the circle container with the ClipboardUtil. The full contents of this class can be seen below.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com.bit101.components.PushButton;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> couk.markstar.examples.ui.CircleContainer;
	<span style="color: #0033ff; font-weight: bold;">import</span> couk.markstar.statefultoolkit.utils.ClipboardUtil;
	<span style="color: #0033ff; font-weight: bold;">import</span> couk.markstar.statefultoolkit.utils.FileUtil;
	<span style="color: #0033ff; font-weight: bold;">import</span> couk.markstar.statefultoolkit.utils.IClipboardUtil;
	<span style="color: #0033ff; font-weight: bold;">import</span> couk.markstar.statefultoolkit.utils.IFileUtil;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">MouseEvent</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span>.<span style="color: #004993;">TextField</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span>.<span style="color: #004993;">TextFieldType</span>;
&nbsp;
	<span style="color: #000000;">&#91;</span>SWF<span style="color: #000000;">&#40;</span> <span style="color: #004993;">backgroundColor</span>=<span style="color: #990000;">'#F3F3F3'</span>,<span style="color: #004993;">frameRate</span>=<span style="color: #990000;">'30'</span>,<span style="color: #004993;">width</span>=<span style="color: #990000;">'592'</span>,<span style="color: #004993;">height</span>=<span style="color: #990000;">'300'</span> <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> ClipboardExample extends <span style="color: #004993;">Sprite</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #6699cc; font-weight: bold;">var</span> _saveButton<span style="color: #000000; font-weight: bold;">:</span>PushButton;
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #6699cc; font-weight: bold;">var</span> _loadButton<span style="color: #000000; font-weight: bold;">:</span>PushButton;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #6699cc; font-weight: bold;">var</span> _circleContainer<span style="color: #000000; font-weight: bold;">:</span>CircleContainer;
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #6699cc; font-weight: bold;">var</span> _fileUtil<span style="color: #000000; font-weight: bold;">:</span>IFileUtil;
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #6699cc; font-weight: bold;">var</span> _clipboardUtil<span style="color: #000000; font-weight: bold;">:</span>IClipboardUtil;
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Create the save and load buttons to save and load the state. Then create the circle container and register it with the FileUtil.
		 * By registering the container with the FileUtil it means the FileUtil knows which statable object to retrieve and set the state on
		 * when save and load are executed.
		 * Register the container with the ClipboardUtil so it can capture keyboard shortcuts.
		 */</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> ClipboardExample<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #009900;">// PushButton( parent, x, y, label, MouseEvent.CLICK event listener )</span>
			_saveButton = <span style="color: #0033ff; font-weight: bold;">new</span> PushButton<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">this</span>, <span style="color: #000000; font-weight:bold;">196</span>, <span style="color: #000000; font-weight:bold;">275</span>, <span style="color: #990000;">&quot;Save&quot;</span>, saveClickListener <span style="color: #000000;">&#41;</span>;
			_loadButton = <span style="color: #0033ff; font-weight: bold;">new</span> PushButton<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">this</span>, <span style="color: #000000; font-weight:bold;">295</span>, <span style="color: #000000; font-weight:bold;">275</span>, <span style="color: #990000;">&quot;Load&quot;</span>, loadClickListener <span style="color: #000000;">&#41;</span>;
&nbsp;
			_circleContainer = <span style="color: #0033ff; font-weight: bold;">new</span> CircleContainer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			_fileUtil = <span style="color: #0033ff; font-weight: bold;">new</span> FileUtil<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			_fileUtil.registerObject<span style="color: #000000;">&#40;</span> _circleContainer <span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #009900;">// ClipboardUtil requires reference to the stage so it can manage the keyboard shortcuts</span>
			_clipboardUtil = <span style="color: #0033ff; font-weight: bold;">new</span> ClipboardUtil<span style="color: #000000;">&#40;</span> <span style="color: #004993;">stage</span> <span style="color: #000000;">&#41;</span>;
			_clipboardUtil.registerContainer<span style="color: #000000;">&#40;</span> _circleContainer <span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span> _circleContainer <span style="color: #000000;">&#41;</span>;
&nbsp;
			initDefaultState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> saveClickListener<span style="color: #000000;">&#40;</span> e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			_fileUtil.<span style="color: #004993;">save</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> loadClickListener<span style="color: #000000;">&#40;</span> e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			_fileUtil.<span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Initialise the circle container with four circles
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> initDefaultState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> defaultState<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">'&lt;container&gt;'</span>;
			defaultState <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">'&lt;object&gt;&lt;x&gt;196&lt;/x&gt;&lt;y&gt;100&lt;/y&gt;&lt;/object&gt;'</span>;
			defaultState <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">'&lt;object&gt;&lt;x&gt;196&lt;/x&gt;&lt;y&gt;200&lt;/y&gt;&lt;/object&gt;'</span>;
			defaultState <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">'&lt;object&gt;&lt;x&gt;396&lt;/x&gt;&lt;y&gt;100&lt;/y&gt;&lt;/object&gt;'</span>;
			defaultState <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">'&lt;object&gt;&lt;x&gt;396&lt;/x&gt;&lt;y&gt;200&lt;/y&gt;&lt;/object&gt;'</span>;
			defaultState <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">'&lt;/container&gt;'</span>;
&nbsp;
			_circleContainer.setState<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">XML</span><span style="color: #000000;">&#40;</span> defaultState <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<h3>Testing the application</h3>
<p>You will now be able to run the application and test that the state of the application can be saved and loaded and that you can copy and paste circles. The structure of the project can be seen below. If you do have any questions about the tutorial, or constructive criticism on the toolkit, don’t hesitate leave a comment below.</p>
<p style="text-align: center;"><a href="http://markstar.co.uk/blog/wp-content/uploads/2010/02/ProjectStructure.jpg"><img class="aligncenter size-full wp-image-199" title="ClipboardExampleProjectStructure" src="http://markstar.co.uk/blog/wp-content/uploads/2010/02/ProjectStructure.jpg" alt="ClipboardExample Project Structure" width="592" height="306" /></a></p>
<h3><a name="compiledapplication"></a>Compiled Application</h3>
<p>Once you have compiled the application, you should get the same output as below. Try copying and pasting the circles, you will also be able to save and load the state like before.</p>
<div class="post_flash">
<p style="text-align: center;">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_ClipboardExample_1602920274"
			class="flashmovie"
			width="592"
			height="300">
	<param name="movie" value="http://markstar.co.uk/flash/StatefulToolkit/ClipboardExample.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://markstar.co.uk/flash/StatefulToolkit/ClipboardExample.swf"
			name="fm_ClipboardExample_1602920274"
			width="592"
			height="300">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
</div>
<h3><a name="sourcecode"></a>Source Files</h3>
<p>Source files are available from <a title="StatefulToolkit Downloads at GitHub" href="http://github.com/markstar/StatefulToolkit/downloads" target="_blank">GitHub</a>, under the heading ClipboardExample.</p>
]]></content:encoded>
			<wfw:commentRss>http://markstar.co.uk/blog/2010/flashplatform/actionscript/clipboard-management-using-the-statefultoolkit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Year(ish), New Look</title>
		<link>http://markstar.co.uk/blog/2010/general/new-year-new-look/</link>
		<comments>http://markstar.co.uk/blog/2010/general/new-year-new-look/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 17:30:24 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[2010]]></category>
		<category><![CDATA[WordPress Theme]]></category>

		<guid isPermaLink="false">http://markstar.co.uk/blog/?p=206</guid>
		<description><![CDATA[I've always wanted to create my own WordPress theme for my site, but haven't had the time (or patience!) before. I was hoping to have it complete by the new year but it took a back seat whilst I worked on the StatefulToolkit. Over the past week I've had chance to implement the design, and here it is! I hope you like it. Now to get back to the StatefulToolkit...]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve always wanted to create my own WordPress theme for my site, but haven&#8217;t had the time (or patience!) before. I was hoping to have it complete by the new year but it took a back seat whilst I worked on the <a title="StatefulToolkit posts" href="http://markstar.co.uk/blog/?s=stateful+toolkit" target="_blank">StatefulToolkit</a>. Over the past week I&#8217;ve had chance to implement the design, and here it is! I hope you like it.</p>
<p>Now to get back to the StatefulToolkit&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://markstar.co.uk/blog/2010/general/new-year-new-look/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction to using the StatefulToolkit</title>
		<link>http://markstar.co.uk/blog/2010/statefultoolkit/introduction-to-using-statefultoolkit/</link>
		<comments>http://markstar.co.uk/blog/2010/statefultoolkit/introduction-to-using-statefultoolkit/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 15:18:26 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[StatefulToolkit]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://markstar.co.uk/blog/?p=135</guid>
		<description><![CDATA[In this tutorial I’ll take you through the basic premise behind the StatefulToolkit and demonstrate how it can be used in a project. The example will also demonstrate use of the FileUtil, which is a utility class included in the toolkit that allows the user to load and save states.]]></description>
			<content:encoded><![CDATA[<h3>Tutorial Overview</h3>
<p>In this tutorial I’ll take you through the basic premise behind the StatefulToolkit and demonstrate how it can be used in a project. If you haven’t heard of StatefulToolkit before then be sure to <a title="StatefulToolkit for AS3 (Beta)" href="http://markstar.co.uk/blog/?p=134" target="_blank">read up on it</a>. This example will also demonstrate use of the FileUtil, which is a utility class included in the toolkit that allows the user to load and save states. The application is very basic and will allow the user to position four circles and to save and load the state of the circles (i.e. where the circles are positioned). The example can be <a title="View the compiled application" href="#compiledapplication" target="_self">seen here</a> and <a title="Application Source Code" href="#sourcecode" target="_self">source files are available</a>.</p>
<h3>Preparation</h3>
<p>Before you being implementing this tutorial make sure you have the latest version of the <a title="StatefulToolkit Downloads at GitHub" href="http://github.com/markstar/StatefulToolkit/downloads" target="_blank">StatefulToolkit SWC</a>, and that you&#8217;re project is set to target Flash Player 10 (if you want to target FP9, simple replace the Vector with an array in the circle container) . This tutorial also uses Keith Peter’s <a title="Minimal Comps at BIT-101" href="http://www.bit-101.com/minimalcomps/" target="_blank">Minimal Comps</a> component set to create the buttons in the application so you may want to grab the SWC for that too, but you can use your own buttons if you prefer.<br />
<span id="more-135"></span></p>
<h3>Creating the Statable Object</h3>
<p>We’re going to start by creating the circles that the user can move. In order for the position of the circles to be saved the class must implement the IStatable interface. The class itself is very simple; the constructor creates the graphics of the circle, the retrieveState method returns the position of the circle as a String, and the setState method sets the position of the Circle based on the new state. The retrieveState and setState methods are both required by the IStatable interface. Note that I’ve put the class in the couk.markstar.examples.ui package, but you don’t have to. The full contents of this class can be seen below.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> couk.markstar.examples.ui
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> couk.markstar.statefultoolkit.core.IStatable;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Circle extends <span style="color: #004993;">Sprite</span> implements IStatable
	<span style="color: #000000;">&#123;</span>
		<span style="color: #3f5fbf;">/**
		 * The constructor draws the circle with a grey outline
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Circle<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #004993;">drawCircle</span><span style="color: #000000;">&#40;</span> 0x999999 <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Change the display of the circle to show it's selected
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">select</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">drawCircle</span><span style="color: #000000;">&#40;</span> 0x990000 <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Change the display of the circle to the default
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> deselect<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">drawCircle</span><span style="color: #000000;">&#40;</span> 0x999999 <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Retrieve the state of the circle storing the x and y properties
		 *
		 * @return The current state of the circle as an XML string
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> retrieveState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> xml<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">'&lt;object&gt;'</span>;
			xml <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">'&lt;x&gt;'</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">'&lt;/x&gt;'</span>;
			xml <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">'&lt;y&gt;'</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">'&lt;/y&gt;'</span>;
			xml <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">'&lt;/object&gt;'</span>;
			<span style="color: #0033ff; font-weight: bold;">return</span> xml;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Set the state of the circle by getting it's x and y values from the xml
		 *
		 * @param state The new state of the circle
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> setState<span style="color: #000000;">&#40;</span> state<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">XML</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">x</span> = <span style="color: #004993;">Number</span><span style="color: #000000;">&#40;</span> state.<span style="color: #004993;">x</span> <span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">y</span> = <span style="color: #004993;">Number</span><span style="color: #000000;">&#40;</span> state.<span style="color: #004993;">y</span> <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Used internally for creating the circles' graphics
		 *
		 * @param lineColor The color of the line around the circle
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">drawCircle</span><span style="color: #000000;">&#40;</span> lineColor<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">graphics</span>.<span style="color: #004993;">clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">graphics</span>.<span style="color: #004993;">lineStyle</span><span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">1</span>, lineColor <span style="color: #000000;">&#41;</span>
			<span style="color: #004993;">graphics</span>.<span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span> 0xFFFFFFF <span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">graphics</span>.<span style="color: #004993;">drawCircle</span><span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #000000; font-weight:bold;">10</span> <span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">graphics</span>.<span style="color: #004993;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<h3>Creating the Container</h3>
<p>In this example the container is responsible for managing the circles. This includes creating and deleting circles, setting and retrieving the state of the circles and adding behaviours to the circles so the user can position them.</p>
<p>The circle container must also implement the IStatable interface ,so it can be used with the FileUtil. The container is set up to assume that an unknown amount of circles could be stored in the state, therefore there’s some additional code in the class to create and remove circles. Firstly, there’s the addObjectByState method, which takes the state of a circle as it’s parameter and creates a circle based on the state, and there’s the clearContainer method that loops through all of the circles and removes them from the stage.</p>
<p>The retrieveState and setState methods are also slightly different to the ones found in the Circle class. The retrieveState method loops through all circles and adding their states to the string to be returned, and the setState method clears any circles currently there and loops through the new state creating new circles as necessary. The last three methods of the class are event listeners that are there to enable the positioning of circles. The full contents of this class can be seen below.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> couk.markstar.examples.ui
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> couk.markstar.statefultoolkit.core.IStatable;
	<span style="color: #0033ff; font-weight: bold;">import</span> couk.markstar.statefultoolkit.core.IStateSelectContainer;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">MouseEvent</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span>.<span style="color: #004993;">Point</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> CircleContainer extends <span style="color: #004993;">Sprite</span> implements IStateSelectContainer
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #6699cc; font-weight: bold;">var</span> _circles<span style="color: #000000; font-weight: bold;">:</span>Vector.<span style="color: #000000; font-weight: bold;">&lt;</span>Circle<span style="color: #000000; font-weight: bold;">&gt;</span>;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #6699cc; font-weight: bold;">var</span> _currentCircle<span style="color: #000000; font-weight: bold;">:</span>Circle;
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #6699cc; font-weight: bold;">var</span> _dragOffset<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Point</span>;
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * The constructor the vector containing the circles shown in the container
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> CircleContainer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			_circles = <span style="color: #0033ff; font-weight: bold;">new</span> Vector.<span style="color: #000000; font-weight: bold;">&lt;</span>Circle<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Retrieve the selected object
		 *
		 * @return The selected object
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> retrieveSelectedObject<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span>IStatable
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> _currentCircle;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Check whether the container has a selected object
		 *
		 * @return Boolean denoting if the container has a selected object
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> hasSelectedObject<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span><span style="color: #000000;">&#40;</span> _currentCircle <span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">?</span> <span style="color: #0033ff; font-weight: bold;">true</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">false</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Retrieve the state of the container and all contained circles
		 *
		 * @return The current state of the container, including the state's of all circles
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> retrieveState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> xml<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;&lt;container&gt;&quot;</span>;
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span> <span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">0</span>; i <span style="color: #000000; font-weight: bold;">&lt;</span> _circles.<span style="color: #004993;">length</span>; i<span style="color: #000000; font-weight: bold;">++</span> <span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				xml <span style="color: #000000; font-weight: bold;">+</span>= _circles<span style="color: #000000;">&#91;</span> i <span style="color: #000000;">&#93;</span>.retrieveState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #000000;">&#125;</span>
			xml <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;&lt;/container&gt;&quot;</span>;
			<span style="color: #0033ff; font-weight: bold;">return</span> xml;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Add an object to the container by it's state.
		 *
		 * @param state The state of the object to add, in this case the circle
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> addObjectByState<span style="color: #000000;">&#40;</span> state<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">XML</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> circle<span style="color: #000000; font-weight: bold;">:</span>Circle = <span style="color: #0033ff; font-weight: bold;">new</span> Circle<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			circle.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">MOUSE_DOWN</span>, circleDownListener <span style="color: #000000;">&#41;</span>;
			circle.setState<span style="color: #000000;">&#40;</span> state <span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span> circle <span style="color: #000000;">&#41;</span>;
			_circles<span style="color: #000000;">&#91;</span> _circles.<span style="color: #004993;">length</span> <span style="color: #000000;">&#93;</span> = circle;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Set the state of the container by adding all circles contained within the state. The container will be cleared first.
		 *
		 * @param state The new state of the container
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> setState<span style="color: #000000;">&#40;</span> state<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">XML</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			clearContainer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span> <span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">0</span>; i <span style="color: #000000; font-weight: bold;">&lt;</span> state.object.<span style="color: #004993;">length</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>; i<span style="color: #000000; font-weight: bold;">++</span> <span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				addObjectByState<span style="color: #000000;">&#40;</span> <span style="color: #004993;">XML</span><span style="color: #000000;">&#40;</span> state.object<span style="color: #000000;">&#91;</span> i <span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Clear the container of all circles
		 *
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> clearContainer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span> <span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">0</span>; i <span style="color: #000000; font-weight: bold;">&lt;</span> _circles.<span style="color: #004993;">length</span>; i<span style="color: #000000; font-weight: bold;">++</span> <span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span> _circles<span style="color: #000000;">&#91;</span> i <span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#41;</span>;
			<span style="color: #000000;">&#125;</span>
			_circles.<span style="color: #004993;">splice</span><span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">0</span>, _circles.<span style="color: #004993;">length</span> <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/*
		 * The following methods are all event listeners to enable the circles to be dragged
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> circleDownListener<span style="color: #000000;">&#40;</span> e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #009900;">// Deselect the current circle (if there is one)</span>
			<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> _currentCircle <span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				_currentCircle.deselect<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #000000;">&#125;</span>
&nbsp;
			_currentCircle = Circle<span style="color: #000000;">&#40;</span> e.<span style="color: #004993;">currentTarget</span> <span style="color: #000000;">&#41;</span>;
			_currentCircle.<span style="color: #004993;">select</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">MOUSE_MOVE</span>, circleMouseMoveListener <span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">MOUSE_UP</span>, circleMouseUpListener <span style="color: #000000;">&#41;</span>;
&nbsp;
			_dragOffset = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span> _currentCircle.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #004993;">mouseX</span>, _currentCircle.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #004993;">mouseY</span> <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> circleMouseMoveListener<span style="color: #000000;">&#40;</span> e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			_currentCircle.<span style="color: #004993;">x</span> = <span style="color: #004993;">mouseX</span> <span style="color: #000000; font-weight: bold;">+</span> _dragOffset.<span style="color: #004993;">x</span>;
			_currentCircle.<span style="color: #004993;">y</span> = <span style="color: #004993;">mouseY</span> <span style="color: #000000; font-weight: bold;">+</span> _dragOffset.<span style="color: #004993;">y</span>;
			e.<span style="color: #004993;">updateAfterEvent</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> circleMouseUpListener<span style="color: #000000;">&#40;</span> e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">MOUSE_MOVE</span>, circleMouseMoveListener <span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">MOUSE_UP</span>, circleMouseUpListener <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<h3>Creating the Document Class</h3>
<p>The document class for this application is pretty simple. It’s responsible for creating the save and load buttons, creating the circle container, registering the circle container with the FileUtil and initialising the container with a default state. The save and load buttons are created using the <a title="Minimal Comps at BIT-101" href="http://www.bit-101.com/minimalcomps/" target="_blank">Minimal Comps</a> component set, you can replace these with buttons of your own if you choose not to use them. The full contents of this class can be seen below.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com.bit101.components.PushButton;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> couk.markstar.examples.ui.CircleContainer;
	<span style="color: #0033ff; font-weight: bold;">import</span> couk.markstar.statefultoolkit.utils.FileUtil;
	<span style="color: #0033ff; font-weight: bold;">import</span> couk.markstar.statefultoolkit.utils.IFileUtil;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">MouseEvent</span>;
&nbsp;
	<span style="color: #000000;">&#91;</span>SWF<span style="color: #000000;">&#40;</span> <span style="color: #004993;">backgroundColor</span>=<span style="color: #990000;">'#F3F3F3'</span>,<span style="color: #004993;">frameRate</span>=<span style="color: #990000;">'30'</span>,<span style="color: #004993;">width</span>=<span style="color: #990000;">'592'</span>,<span style="color: #004993;">height</span>=<span style="color: #990000;">'300'</span> <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> SaveLoadExample extends <span style="color: #004993;">Sprite</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #6699cc; font-weight: bold;">var</span> _saveButton<span style="color: #000000; font-weight: bold;">:</span>PushButton;
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #6699cc; font-weight: bold;">var</span> _loadButton<span style="color: #000000; font-weight: bold;">:</span>PushButton;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #6699cc; font-weight: bold;">var</span> _circleContainer<span style="color: #000000; font-weight: bold;">:</span>CircleContainer;
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #6699cc; font-weight: bold;">var</span> _fileUtil<span style="color: #000000; font-weight: bold;">:</span>IFileUtil;
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Create the save and load buttons to save and load the state. Then create the circle container and register it with the FileUtil,
		 * by registering the container with the FileUtil it means the FileUtil knows which statable object to retrieve and set the state on
		 * when save and load are executed.
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> SaveLoadExample<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #009900;">// PushButton( parent, x, y, label, MouseEvent.CLICK event listener )</span>
			_saveButton = <span style="color: #0033ff; font-weight: bold;">new</span> PushButton<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">this</span>, <span style="color: #000000; font-weight:bold;">196</span>, <span style="color: #000000; font-weight:bold;">275</span>, <span style="color: #990000;">&quot;Save&quot;</span>, saveClickListener <span style="color: #000000;">&#41;</span>;
			_loadButton = <span style="color: #0033ff; font-weight: bold;">new</span> PushButton<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">this</span>, <span style="color: #000000; font-weight:bold;">295</span>, <span style="color: #000000; font-weight:bold;">275</span>, <span style="color: #990000;">&quot;Load&quot;</span>, loadClickListener <span style="color: #000000;">&#41;</span>;
&nbsp;
			_circleContainer = <span style="color: #0033ff; font-weight: bold;">new</span> CircleContainer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			_fileUtil = <span style="color: #0033ff; font-weight: bold;">new</span> FileUtil<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			_fileUtil.registerObject<span style="color: #000000;">&#40;</span> _circleContainer <span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span> _circleContainer <span style="color: #000000;">&#41;</span>;
&nbsp;
			initDefaultState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> saveClickListener<span style="color: #000000;">&#40;</span> e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			_fileUtil.<span style="color: #004993;">save</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> loadClickListener<span style="color: #000000;">&#40;</span> e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			_fileUtil.<span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Initialise the circle container with four circles
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> initDefaultState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> defaultState<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">'&lt;container&gt;'</span>;
			defaultState <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">'&lt;object&gt;&lt;x&gt;196&lt;/x&gt;&lt;y&gt;100&lt;/y&gt;&lt;/object&gt;'</span>;
			defaultState <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">'&lt;object&gt;&lt;x&gt;196&lt;/x&gt;&lt;y&gt;200&lt;/y&gt;&lt;/object&gt;'</span>;
			defaultState <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">'&lt;object&gt;&lt;x&gt;396&lt;/x&gt;&lt;y&gt;100&lt;/y&gt;&lt;/object&gt;'</span>;
			defaultState <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">'&lt;object&gt;&lt;x&gt;396&lt;/x&gt;&lt;y&gt;200&lt;/y&gt;&lt;/object&gt;'</span>;
			defaultState <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">'&lt;/container&gt;'</span>;
&nbsp;
			_circleContainer.setState<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">XML</span><span style="color: #000000;">&#40;</span> defaultState <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<h3>Testing the application</h3>
<p>You will now be able to run the application and test that the state of the application can be saved and loaded. The structure of the project can be seen below. If you do have any questions about the tutorial, or constructive criticism on the toolkit, don&#8217;t hesitate leave a comment below.</p>
<p style="text-align: center;"><a href="http://markstar.co.uk/blog/wp-content/uploads/2010/01/SaveLoadExampleProjectStructure.jpg"><img class="size-full wp-image-149 aligncenter" title="SaveLoadExampleProjectStructure" src="http://markstar.co.uk/blog/wp-content/uploads/2010/01/SaveLoadExampleProjectStructure.jpg" alt="SaveLoadExample Project Structure" width="592" height="288" /></a></p>
<h3><a name="compiledapplication"></a>Compiled Application</h3>
<p>Once you have compiled the application, you should get the same output as below. Try moving the circles, saving the state then moving the circles again and loading the state. Notice that the circles go back to the saved state when it&#8217;s loaded.</p>
<div class="post_flash">
<p style="text-align: center;">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_SaveLoadExample_187404297"
			class="flashmovie"
			width="592"
			height="300">
	<param name="movie" value="http://markstar.co.uk/flash/StatefulToolkit/SaveLoadExample.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://markstar.co.uk/flash/StatefulToolkit/SaveLoadExample.swf"
			name="fm_SaveLoadExample_187404297"
			width="592"
			height="300">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
</div>
<h3><a name="sourcecode"></a>Source Files</h3>
<p>Source files are available from <a title="StatefulToolkit Downloads at GitHub" href="http://github.com/markstar/StatefulToolkit/downloads" target="_blank">GitHub</a>, under the heading SaveLoadExample.</p>
]]></content:encoded>
			<wfw:commentRss>http://markstar.co.uk/blog/2010/statefultoolkit/introduction-to-using-statefultoolkit/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>StatefulToolkit for AS3 (Beta)</title>
		<link>http://markstar.co.uk/blog/2010/statefultoolkit/statefultoolkit-for-as3-beta/</link>
		<comments>http://markstar.co.uk/blog/2010/statefultoolkit/statefultoolkit-for-as3-beta/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 14:45:28 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[StatefulToolkit]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://markstar.co.uk/blog/?p=134</guid>
		<description><![CDATA[Update: Don&#8217;t forget to take a look at the Introduction to using StatefulToolkit.
What is it?
The StatefulToolkit was developed to enable the simple management of states in AS3. At the heart of the toolkit is one interface called IStatable. Any object that requires the retrieval or setting of its state must implement this interface. The toolkit [...]]]></description>
			<content:encoded><![CDATA[<p>Update: Don&#8217;t forget to take a look at the <a title="Introduction to using StatefulToolkit" href="http://markstar.co.uk/blog/?p=135" target="_blank">Introduction to using StatefulToolkit</a>.</p>
<h3>What is it?</h3>
<p>The StatefulToolkit was developed to enable the simple management of states in AS3. At the heart of the toolkit is one interface called IStatable. Any object that requires the retrieval or setting of its state must implement this interface. The toolkit comes with utility classes to help carry out some of the basic tasks associated with state management.</p>
<h3>What’s included in the beta?</h3>
<p>The initial 0.1 beta release includes the interfaces to implement and two utility classes, one to aid in saving and loading states and another to enable clipboard management, so you can copy and paste objects.</p>
<p>The utility classes are both currently optimized for the Flash Player &#8211; that’s not to say they can’t be used in the AIR runtime (they’d work perfectly fine) but they take into account the security sandbox restrictions that are found in the Flash Player. For example, the FileUtil allows you to save and load states, but does this using the FileReference class whereas in an AIR application you may want this to be done silently (without the browse box appearing), which would use the File class.</p>
<p><span id="more-134"></span></p>
<h3>Why is it in beta?</h3>
<p>The main reason is that it&#8217;s still in early stages of development; I haven’t implemented all of the features yet and the code hasn&#8217;t been optimized, that being said it is stable in its current release. I’d also like to get some community feedback on the project before making a 1.0 release.</p>
<h3>Where can I get it?</h3>
<p>The <a title="StatefulToolkit at GitHub" href="http://github.com/markstar/StatefulToolkit" target="_blank">source code is available</a> at <a title="GitHub" href="http://github.com/" target="_blank">GitHub</a>, alternatively you can download the SWC on the <a title="StatefulToolkit Downloads at GitHub" href="http://github.com/markstar/StatefulToolkit/downloads" target="_blank">downloads page</a> of the project.</p>
<h3>Where can I find examples?</h3>
<p>I&#8217;ll be posting tutorials for some example projects on this blog and you can find all example projects on the <a title="StatefulToolkit Downloads at GitHub" href="http://github.com/markstar/StatefulToolkit/downloads" target="_blank">downloads page</a> of the project in GitHub. This will evolve as the toolkit expands.</p>
<h3>Where would I use it?</h3>
<p>Essentially it can be used for any application that needs it’s state saving. However, I think it would be useful in the following type of applications:</p>
<ul>
<li>Wireframing applications, such as <a title="Balsamiq Mockups" href="http://www.balsamiq.com/products/mockups" target="_blank">Balsamiq Mockups</a> and <a title="LovelyCharts" href="http://www.lovelycharts.com/" target="_blank">LovelyCharts</a></li>
<li>Game level editors</li>
<li>Drawing tools</li>
<li>General applications (for things like panel states, window positions,  settings panels, etc)</li>
</ul>
<h3>What have you got planned for the future?</h3>
<p>More utility classes! In the near future there will be a utility class to allow history management (undo and redo). Following this I want to create AIR versions of the utility classes and provide some form of automation for the setting and retrieval of states, so you don’t have to construct and parse the XML manually.</p>
<h3>How can I help?</h3>
<p>Feedback! Whether its feature requests, bugs, constructive criticism or just general questions about the toolkit, I want to hear it. You can either post comments on this blog, or <a title="StatefulToolkit issues at GitHub" href="http://github.com/markstar/StatefulToolkit/issues" target="_blank">file issues</a> for the project at GitHub.</p>
]]></content:encoded>
			<wfw:commentRss>http://markstar.co.uk/blog/2010/statefultoolkit/statefultoolkit-for-as3-beta/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>