<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7469465561312546205</id><updated>2011-07-08T07:44:19.218-07:00</updated><title type='text'>Flash Cookbook</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://flashcookbook.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7469465561312546205/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://flashcookbook.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>mitchell</name><uri>http://www.blogger.com/profile/04639648390267025512</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>9</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7469465561312546205.post-3669841600985241886</id><published>2009-11-05T13:35:00.001-08:00</published><updated>2010-02-18T07:59:07.220-08:00</updated><title type='text'>Model View Controller</title><content type='html'>&lt;b&gt;Model View Controller&lt;/b&gt;&lt;br&gt; The Model View Controller pattern is based on three elements named, you guessed it! Model, View and Controller. Also known as MVC, the Model View Controller pattern is a perfect fit for programming graphical interfaces. Which is a big part of Flash. &lt;br&gt;&lt;br&gt;MVC strives to separate data from the interface that manipulates it. In this way it uncomplicates your process of programming many types of projects. The MVC pattern may seem to be complex at first. In reality it unravels the spaghetti mess of code that you often find yourself in when programming complex user interfaces. &lt;br&gt;&lt;br&gt;This is a pattern that&amp;#39;s built of other patterns. In particular, it relies heavily on the Observer pattern. If you haven&amp;#39;t heard of the Observer pattern before don&amp;#39;t worry, since it&amp;#39;s built into AS3, as the Event Listener system. If you&amp;#39;ve added listeners and set up event handler (functions called by a listener), then you&amp;#39;ve already got EventDispatcher under your belt. &lt;br&gt;&lt;b&gt;&lt;br&gt;MVC Overview&lt;/b&gt;&lt;br&gt;The MVC pattern, as I mentioned earlier, is made up of three elements: Model, View and Controller. How these elements interact is the key to MVC pattern. &lt;br&gt;&lt;br&gt;The Model only contains data. This can be as little as one value. The Model is not concerned with displaying anything, the View will handle this. The Model should never have a reference to the View or the Controller.&lt;br&gt;&lt;br&gt;The View is the visual portion of the system. The goal of designing the View is making a class that will display data stored in the Model. Any system using MVC might have any number of Views working with a single Model. &lt;br&gt;&lt;br&gt;The Controller passes information to the Model. Often Controllers are also Views. &lt;br&gt;&lt;br&gt;The key to relationship between Model, View and Controller, is the View and Controller store a reference to the Model that they are working with. The Model should never have a reference to the View or Controller. The Model is only concerned with storing, processing and making data available to the View and Controller. &lt;br&gt;&lt;br&gt;The glue that holds the Model, View and Controller together is the Event Listener system. The basic arrangement is that the View and Controller will register to receive CHANGE events from the Model. When the data in the Model changes the Model dispatches a CHANGE event. Model makes it&amp;#39;s data available to the outside world via public methods.&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Simple MVC Example&lt;/b&gt;&lt;br&gt; The following example illustrates the Model View Controller. The example creates a Model which stores an int as it&amp;#39;s data. The View displays the Model&amp;#39;s data in a TextField on the stage. The Controller creates two Buttons which increment and decrement the Model&amp;#39;s data.&lt;br&gt;&lt;br&gt;&lt;b&gt;The Model&lt;/b&gt;&lt;br&gt; The Model will not be a display class but it will dispatch event messages. So we&amp;#39;ll need to import the EventDispatcher class and extend EventDispatcher. Below is the basic class.&lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;package {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;font color="#0000ff"&gt;import flash.events.*;&lt;/font&gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public class Model extends &lt;font color="#ff0000"&gt;EventDispatcher&lt;/font&gt; {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public function Model() {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;}&lt;/font&gt;&lt;br&gt;&lt;br&gt; The Model for this example stores only one simple piece of information. We&amp;#39;ll use a private variable called _data for this:&lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;private var _data:int;&lt;/font&gt;&lt;br&gt;&lt;br&gt; Assign _data an initial starting value of 0 in the constructor of the class:&lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;_data = 0;&lt;/font&gt;&lt;br&gt;&lt;br&gt; Our goal is to allow the Controller to change the value of _data by increment and decrementing by one. To make this easy we&amp;#39;ll make two public functions. Each of these functions will dispatch a CHANGE event to notify listeners that _data has been changed.&lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;&lt;font color="#38761d"&gt;public&lt;/font&gt; function add_one():void {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;font color="#ff0000"&gt;_data ++;&lt;/font&gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;font color="#0000ff"&gt;dispatchEvent( new Event( Event.CHANGE ) );&lt;/font&gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&lt;font color="#38761d"&gt;public&lt;/font&gt; function subtract_one():void {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;font color="#ff0000"&gt;_data --;&lt;/font&gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;font color="#0000ff"&gt;dispatchEvent( new Event( Event.CHANGE ) );&lt;/font&gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;}&lt;/font&gt;&lt;br&gt;&lt;br&gt; Any controller or View class will need a way to access the _data inside of the Model. Since _data is a private var, in accordance with good OOP procedure, we can&amp;#39;t access it directly. We&amp;#39;ll set up a public function to make this available. This is an area where your Models may vary depending on the data they store. You could make many different functions that allow access to data in many different ways. For this example we&amp;#39;ll have a simple function that returns an int.&lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;public function get_data():int {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return _data;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;}&lt;/font&gt;&lt;br&gt;&lt;br&gt; Here&amp;#39;s the entire Model class for this example:&lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;package {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;import flash.events.*;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public class Model extends EventDispatcher {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;private var _data:int;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public function Model() {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_data = 0;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public function add_one():void {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_data ++;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;dispatchEvent( new Event( Event.CHANGE ) );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public function subtract_one():void {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_data --;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;dispatchEvent( new Event( Event.CHANGE ) );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public function get_data():int {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;return _data;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;}&lt;/font&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;The View&lt;/b&gt;&lt;br&gt; The View class has the job of displaying information stored in the model. The View doesn&amp;#39;t have to display the information literally it could display it in any form you care to invent. You can also create and each could display data from the model in a different way.&lt;br&gt;&lt;br&gt; All of the Views will share some features in common. They will all probably extend one of the display classes like MovieClip or Sprite. They will all receive a reference to the Model as an argument of the Constructor function. They will all register for CHANGE events with the model.&lt;br&gt;&lt;br&gt; Here&amp;#39;s the basics of the class:&lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;package {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;import flash.display.*;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;import flash.events.*;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public class View extends Sprite {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;font color="#ff0000"&gt;private var _model:Model;&lt;/font&gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public function View( &lt;font color="#ff0000"&gt;model:Model&lt;/font&gt; ) {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;font color="#ff0000"&gt;_model = model;&lt;/font&gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;font color="#0000ff"&gt;_model.addEventListener( Event.CHANGE, on_change );&lt;/font&gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;font color="#0000ff"&gt;private function on_change( e:Event ):void {&lt;/font&gt;&lt;/font&gt;&lt;br style="color:#0000ff;font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br style="color:#0000ff;font-family:Courier New"&gt;&lt;font face="courier new"&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;}&lt;/font&gt;&lt;br&gt;&lt;br&gt; When you create an instance of the View it has a reference to the Model passed to it in the argument model. The View Class stores this in _model. The class then adds an event listener to _model listening for the CHANGE event. I created a handler for this listener named on_change. Since the Model will dispatch a CHANGE event whenever it&amp;#39;s data changes our View will now be notified and can update itself.&lt;br&gt;&lt;br&gt; To complete the View we&amp;#39;ll add a TextField and we&amp;#39;ll add a line of code to the on_change handler that sets the text of the TextField to display the value stored in the Model.&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;package {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;import flash.display.*;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;import flash.events.*;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;font color="#ff0000"&gt;import flash.text.*;&lt;/font&gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public class View extends Sprite {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;private var _model:Model;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;font color="#ff0000"&gt;private var _txt:TextField;&lt;/font&gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public function View( model:Model ) {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_model = model;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_model.addEventListener( Event.CHANGE, on_change );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;font color="#ff0000"&gt;_txt = new TextField();&lt;/font&gt;&lt;/font&gt;&lt;br style="color:#ff0000;font-family:Courier New"&gt;&lt;font face="courier new"&gt;&lt;font color="#ff0000"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;addChild( _txt );&lt;/font&gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;private function on_change( e:Event ):void {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;font color="#ff0000"&gt;_txt.text = String( &lt;font color="#0000ff"&gt;_model.get_data()&lt;/font&gt; );&lt;/font&gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;}&lt;/font&gt;&lt;br&gt;&lt;br&gt; Here&amp;#39;s a quick rundown of the new elements.&lt;br&gt;&lt;br&gt; First I imported the flash.text.* package. We need this since our class will work with the TextField.&lt;br&gt;&lt;br&gt; Next I created a new private variable _txt to hold the TextField that we will create. In the constructor I created a new TextField and added it tothe display list.&lt;br&gt;&lt;br&gt; Last I added a line to the on_change function that sets the text of _txt to the value of data stored in Model. We&amp;#39;re calling the model&amp;#39;s get_data method, and the Model is returning the int stored in Model&amp;#39;s _data property. Since the text property of the TextField expects a String. I&amp;#39;m casting the value as String.&lt;br&gt;&lt;br&gt; In this example I created the TextField via AS. This is not a requirement. You could also have used a clip from the library or referenced a clip on the stage. I used AS to create everything since that keeps all of the elements in code above.&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;The Controller&lt;/b&gt;&lt;br&gt; The controller will create two buttons that call the add_one and subtract_one&amp;nbsp; methods of the Model class. The controller can have many different manifestations. Often in Flash projects I find the controller is part of the View or part of the my main class.&lt;br&gt;&lt;br&gt; In this example we&amp;#39;ll make it a separate class. The class will extend Sprite, so that it will be a display object that appears on the stage.&lt;br&gt;&lt;br&gt; As with the Model the Controller will take a reference to the Model as an argument of it&amp;#39;s constructor function. This is the same as the View.&lt;br&gt;&lt;br&gt; The Controller can also register with the Model to receive CHANGE events. This may or may not be needed it depends on what the does.&lt;br&gt;&lt;br&gt; Here&amp;#39;s the basic class for the view.&lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;package {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;import flash.display.*;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;import flash.events.*;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public class Controller extends Sprite {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;private var _model:Model;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public function Controller( model:Model ) {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_model = model;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;}&lt;/font&gt;&lt;br&gt;&lt;br&gt; For this example I will create two buttons with AS and add them to the stage. I&amp;#39;m creating the buttons via AS so that the example code here will contain all of the elements. You could easily use clips from your library instead if that fit your project better.&lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;package {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;import flash.display.*;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;import flash.events.*;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public class Controller extends Sprite {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;private var _model:Model;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#ff0000"&gt;&amp;nbsp;private var _up:Sprite;&lt;/font&gt;&lt;/font&gt;&lt;br style="color:#ff0000;font-family:Courier New"&gt;&lt;font face="courier new"&gt;&lt;font color="#ff0000"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;private var _down:Sprite;&lt;/font&gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public function Controller( model:Model ) {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_model = model;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;font color="#ff0000"&gt;_up = new Sprite();&lt;/font&gt;&lt;/font&gt;&lt;br style="color:#ff0000;font-family:Courier New"&gt;&lt;font face="courier new"&gt;&lt;font color="#ff0000"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_up.graphics.beginFill( 0x000000 );&lt;/font&gt;&lt;/font&gt;&lt;br style="color:#ff0000;font-family:Courier New"&gt;&lt;font face="courier new"&gt;&lt;font color="#ff0000"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_up.graphics.drawRect( 0, 0, 22, 22 );&lt;/font&gt;&lt;/font&gt;&lt;br style="color:#ff0000;font-family:Courier New"&gt;&lt;font face="courier new"&gt;&lt;font color="#ff0000"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_up.graphics.endFill();&lt;/font&gt;&lt;/font&gt;&lt;br style="color:#ff0000;font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="color:#ff0000;font-family:Courier New"&gt;&lt;font face="courier new"&gt;&lt;font color="#ff0000"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_down = new Sprite();&lt;/font&gt;&lt;/font&gt;&lt;br style="color:#ff0000;font-family:Courier New"&gt;&lt;font face="courier new"&gt;&lt;font color="#ff0000"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_down.graphics.beginFill( 0x000000 );&lt;/font&gt;&lt;/font&gt;&lt;br style="color:#ff0000;font-family:Courier New"&gt;&lt;font face="courier new"&gt;&lt;font color="#ff0000"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_down.graphics.drawRect( 0, 0, 22, 22 );&lt;/font&gt;&lt;/font&gt;&lt;br style="color:#ff0000;font-family:Courier New"&gt;&lt;font face="courier new"&gt;&lt;font color="#ff0000"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_down.graphics.endFill();&lt;/font&gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;font color="#ff0000"&gt;addChild( _up );&lt;/font&gt;&lt;/font&gt;&lt;br style="color:#ff0000;font-family:Courier New"&gt;&lt;font face="courier new"&gt;&lt;font color="#ff0000"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;addChild( _down );&lt;/font&gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;font color="#ff0000"&gt;_up.x = _down.x + _down.width + 4;&lt;/font&gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;font color="#ff0000"&gt;_up.addEventListener( MouseEvent.CLICK, click_up );&lt;/font&gt;&lt;/font&gt;&lt;br style="color:#ff0000;font-family:Courier New"&gt;&lt;font face="courier new"&gt;&lt;font color="#ff0000"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_down.addEventListener( MouseEvent.CLICK, click_down );&lt;/font&gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#ff0000"&gt;&amp;nbsp;private function click_up( e:MouseEvent ):void {&lt;/font&gt;&lt;/font&gt;&lt;br style="color:#ff0000;font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;font color="#0000ff"&gt;_model.add_one();&lt;/font&gt;&lt;/font&gt;&lt;br style="color:#ff0000;font-family:Courier New"&gt;&lt;font face="courier new"&gt;&lt;font color="#ff0000"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;/font&gt;&lt;br style="color:#ff0000;font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="color:#ff0000;font-family:Courier New"&gt;&lt;font face="courier new"&gt;&lt;font color="#ff0000"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;private function click_down( e:MouseEvent ):void {&lt;/font&gt;&lt;/font&gt;&lt;br style="color:#ff0000;font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;font color="#0000ff"&gt;_model.subtract_one();&lt;/font&gt;&lt;/font&gt;&lt;br style="color:#ff0000;font-family:Courier New"&gt;&lt;font face="courier new"&gt;&lt;font color="#ff0000"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;}&lt;/font&gt;&lt;br&gt;&lt;br&gt; The code added above does the following.&lt;br&gt;&lt;br&gt; It first defines two private variables _up and _down. These will hold a reference to the two Sprites I will use as buttons.&lt;br&gt;&lt;br&gt; Next it creates the _up Sprite, then draws a small rectangle 22px by 22px inside _up. Then it creates the _down Sprite and draw another box. Then I added both boxes to the display list. Next I position _up 4 pixels to the right of _down.&lt;br&gt;&lt;br&gt; Last I added an event listener to each _up and _down. These call the two handlers, click_up and click_down, which are defined below.&lt;br&gt;&lt;br&gt; Notice the two handlers, click_up and click_down, each use the reference _model to call on the Model&amp;#39;s public methods.&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Putting all together&lt;/b&gt;&lt;br&gt; Now that we have the classes written how do you put it all together? In a nutshell, make an instance of Model, then make an instance of View and Controller passing your model instance along. Since View and Controller are both display Objects you&amp;#39;ll need to add them to the display list and position them.&lt;br&gt;&lt;br&gt; Try it for yourself. Make a new Flash file. Save it into the folder containing the Model.as, View.as and Controller.as files. Then create a new AS file, we&amp;#39;ll use this as the Document class for the example, save the file as Main.as, it must go in the same folder as the Fla.&lt;br&gt;&lt;br&gt; Next add the following code to Main.as.&lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;package {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;import flash.display.*;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;import flash.events.*;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public class Main extends MovieClip {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public function Main() {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;font color="#ff0000"&gt;var model:Model = new Model();&lt;/font&gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;&amp;nbsp;var view:View = new View( &lt;font color="#ff0000"&gt;model&lt;/font&gt; );&lt;/font&gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;font color="#38761d"&gt;var controller:Controller = new Controller( model );&lt;/font&gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;addChild( &lt;font color="#0000ff"&gt;view&lt;/font&gt; );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;addChild( &lt;font color="#38761d"&gt;controller&lt;/font&gt; );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;font color="#0000ff"&gt;view&lt;/font&gt;.x = 100;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;font color="#0000ff"&gt;view&lt;/font&gt;.y = 100;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;font color="#38761d"&gt;controller&lt;/font&gt;.x = 100;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;font color="#38761d"&gt;controller&lt;/font&gt;.y = &lt;font color="#0000ff"&gt;view&lt;/font&gt;.y + &lt;font color="#ff0000"&gt;view&lt;/font&gt;.height + 4;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;}&lt;/font&gt;&lt;br&gt;&lt;br&gt; I colored the Model in red, the View in blue and the Controller in green.&lt;br&gt;&lt;br&gt; Test the Movie and you should see two small black squares on the stage. Clicking one should make the View display the value stored in Model and increase the value by 1. Clicking the other should decrease the value stored in Model by 1 and cause the View to display the updated value.&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;How does it all work?&lt;/b&gt;&lt;br&gt; The Model is set up to dispatch change events whenever the data it stores changes. Model provides some methods to allow the data to be changed. In this case add_one and subtract_one add or subtract one and dispatch a change event.&lt;br&gt;&lt;br&gt; The View is passed a reference to Model and registers to listener for change events. If something changes in the Model, View is notified and then gets the information it wants from Model using Model&amp;#39;s get_data method.&lt;br&gt;&lt;br&gt; The Controller is passed a reference to Model. Through this reference it calls Model&amp;#39;s methods that change the data it stores. In this it&amp;#39;s the add_one and subtract_one methods.&lt;br&gt;&lt;br&gt;&lt;b&gt;Why use this Design Pattern&lt;/b&gt;&lt;br&gt; Using the design pattern separates the basic elements that we are working with into distinct classes that each manage one aspect of the system. This provides several advantages.&lt;br&gt;&lt;br&gt; It makes editing easier. Since functions of the system are contained in separate classes, making a change is easier since we can edit the class responsible for that system. Rather than untangling code mixed with other systems.&lt;br&gt;&lt;br&gt; It makes expanding the system much easier. To add another controller or View element to the system becomes as easy as writing a new class. Each new View or Controller will follow the same arrangement also. They will receive a reference to Model. View&amp;#39;s will also register for change events.&lt;br&gt;&lt;br&gt; The Model can also be more easily expanded for the same reasons.&amp;nbsp;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;MVC Gallery&lt;/b&gt;&lt;br&gt; The MVC pattern makes a great choice for a Flash image gallery. Imagine a gallery that displays a large image, a set of smaller thumbnail images, some buttons to advance to the next or previous image, and a text field to display a description of the image. &lt;br&gt;&lt;br&gt;The MVC pattern might break these elements into classes. &lt;br&gt;&lt;br&gt;&lt;ul&gt;&lt;li&gt;Gallery - This class will act as the Model for our system. It will store a list of all of the images, their descriptions and the thumbnail image. &lt;br&gt;&lt;/li&gt;&lt;li&gt;GalleryViewImage - This class will act as a View. It will load and display the large image. &lt;br&gt;&lt;/li&gt;&lt;li&gt;GalleryViewDetails - This class will act as a View. It will display the text description for the current image. &lt;br&gt;&lt;/li&gt;&lt;li&gt;GalleryNextPrev - This class will act as a Controller. It will generate two buttons. Click one button will advance to the next image, clicking the other go back to the previous image.&amp;nbsp;&lt;/li&gt;&lt;li&gt;GalleryViewIcons - This will act as both a View and a Controller. The class will display a list of thumbnail images. Clicking any of these images will display the large version of that image. &lt;br&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br&gt;These are main classes use in our system. There will be a couple other classes used but these are the classes that relate to MVC pattern. &lt;br&gt;&lt;br&gt;&lt;b&gt;Using XML with the Gallery&lt;/b&gt;&lt;br&gt;The gallery will use XML to describe the url of the images, their descriptions and the urls to their thumbnail images. If you are not familiar with XML please see the chapter on XML. &lt;br&gt;&lt;br&gt;XML makes a great system to hold and organize all of the information that describes the gallery. It also makes our gallery flexible, since the XML file can be easily updated to change the images displayed in the gallery. It makes the entire project flexible in that you can reuse the swf with a different set of images and a different XML file in another site with out having create a new project. &lt;br&gt;&lt;br&gt;This project will make use the XMLLoader class to load XML. Please see the chapter on this class if you are familiar with it and need more info. &lt;br&gt;&lt;br&gt;&lt;b&gt;The Gallery XML&lt;/b&gt;&lt;br&gt;The XML file we&amp;#39;ll use for this project will be fairly simple. We&amp;#39;ll use &amp;lt;gallery&amp;gt; as the top level tag. Inside which will be a series of &amp;lt;image&amp;gt; tags. One for each image in the Gallery. For example:&lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;&amp;lt;gallery&amp;gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;div style="font-family:Courier New;margin-left:40px"&gt;&amp;lt;image&amp;gt;&amp;lt;/image&amp;gt;&lt;br&gt;&amp;lt;image&amp;gt;&amp;lt;/image&amp;gt;&lt;br&gt;...&lt;br&gt;&lt;/div&gt;&lt;font face="courier new"&gt;&amp;lt;/gallery&amp;gt;&lt;/font&gt;&lt;br&gt;&lt;br&gt;We&amp;#39;ll have as many &amp;lt;image&amp;gt; tags as there are images in our gallery. &lt;br&gt;&lt;br&gt;Each &amp;lt;image&amp;gt; tag will hold tags that describe each image. For each image we&amp;#39;ll need a URL to the image, a URL to the thumnail image, and a text description of the image. For these we&amp;#39;ll use the following tags:&lt;br&gt;&lt;br&gt;&lt;ul&gt;&lt;li&gt;&amp;lt;url&amp;gt; - URL to the image&lt;br&gt;&lt;/li&gt;&lt;li&gt;&amp;lt;icon&amp;gt; - URL to the thumbnail image&lt;br&gt;&lt;/li&gt;&lt;li&gt;&amp;lt;desc&amp;gt; - Text Description of the image&lt;br&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br&gt;The finished XML file might look something like this:&lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;&amp;lt;gallery&amp;gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;image&amp;gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;url&amp;gt;images/IMG_0089.jpg&amp;lt;/url&amp;gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;icon&amp;gt;images/IMG_0089_icon.jpg&amp;lt;/icon&amp;gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;desc&amp;gt;A picture of the SF skyline.&amp;lt;/desc&amp;gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;/image&amp;gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;image&amp;gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;url&amp;gt;images/IMG_0115.jpg&amp;lt;/url&amp;gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;icon&amp;gt;images/IMG_0115_icon.jpg&amp;lt;/icon&amp;gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;desc&amp;gt;Another picture&amp;lt;/desc&amp;gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;/image&amp;gt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;lt;/gallery&amp;gt;&lt;/font&gt;&lt;br&gt;&lt;br&gt;You can repeat each &amp;lt;image&amp;gt; tag and it&amp;#39;s nested tags once for each image in your gallery. &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Loading Images&lt;/b&gt;&lt;br&gt;This project will use the ImageLoader Class to load both the large image and the thumbnail images. Be sure to read the chapter on these classes if you are not familiar with them. &lt;br&gt;&lt;br&gt;By using a class to cover this functionality we save time. It makes our job easier and our projects better. &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;The Gallery class&lt;/b&gt;&lt;br&gt;The Gallery class will act as the Model for our system. It will store a list of the images, really it will store the URL to each image as a string, we&amp;#39;ll rely on a View to actually load and display the image. Gallery will also store the description for each image and the URL to each thumbnail image. &lt;br&gt;&lt;br&gt;The Gallery will need to provide public functions to accommodate it&amp;#39;s views. Since the GalleryViewImage will display the current image, we&amp;#39;ll include an index property that keeps track of the current image on display. This will also work with the GalleryViewDesc. The controller will set increment the index to display the next image. Or decrement the index to show the previous image. &lt;br&gt;&lt;br&gt;The Gallery class also needs a method to provide a list of the URLs of the thumbnail images. This will be needed by the GalleryViewThumbnails class. &lt;br&gt;&lt;br&gt;The Gallery class will extend EventDispatcher since will need to dispatch event messages. The Gallery will dispatch two types of events. It will the CHANGE event in the same way that the Simple MVC example used it. Since it will load the XML file it will also dispatch a COMPLETE event to notify us when the XML file has been loaded. &lt;br&gt;&lt;br&gt;Here&amp;#39;s the basic Gallery class:&lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;package {&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;import flash.events.*;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;import com.webdevils.net.XMLLoader;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;import com.webdevils.utils.BasicIterator;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public class Gallery extends EventDispatcher {&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;private var _gallery_xml:XMLList;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;private var _index:uint;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public function Gallery( url:String ) {&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;load( url );&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;// ******* Private Functions *******&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;private function on_complete( e:Event ):void {&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_gallery_xml = new XML( e.target.data ).image;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_index = 0;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;dispatchEvent( new Event( Event.COMPLETE ) );&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;dispatchEvent( new Event( Event.CHANGE ) );&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;// ******* Public Functions ********&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public function load( url:String ):void {&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;var xml:XMLLoader = new XMLLoader( url );&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;xml.addEventListener( Event.COMPLETE, on_complete );&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public function next():void {&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if ( _index &amp;lt; _gallery_xml.length() - 1 ) {&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_index ++;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;dispatchEvent( new Event( Event.CHANGE ) );&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public function prev():void {&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if ( _index &amp;gt; 0 ) {&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_index --;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;dispatchEvent( new Event( Event.CHANGE ) );&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public function hasNext():Boolean {&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;return Boolean( _index &amp;lt; _gallery_xml.length() - 1 );&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public function hasPrev():Boolean {&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;return Boolean( _index &amp;gt; 0 );&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public function iterate_icons():BasicIterator {&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;var icons_array:Array = new Array();&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;var it:XMLIterator = new XMLIterator( _gallery_xml );&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;while( it.hasNext() ) {&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;icons_array.push( it.next().icon.toString() );&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;return new BasicIterator( icons_array );&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;// Getter Setters&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public function get index():uint {&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;return _index;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public function get length():uint {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;return _gallery_xml.length();&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public function set index( n:uint ):void {&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_index = n;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;dispatchEvent( new Event( Event.CHANGE ) );&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public function get image():String {&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;return _gallery_xml[ _index ].url.toString();&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public function get desc():String {&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;return _gallery_xml[ _index ].desc.toString();&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br&gt;}&lt;/font&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Gallery properties&lt;/b&gt;&lt;br&gt;The Gallery class has two private properties _gallery_xml and _index. The _gallery_xml property will hold an XML object that describes the gallery. The _index property holds the index of the current image on display in the Gallery. &lt;br&gt;&lt;br&gt;&lt;b&gt;Gallery methods&lt;/b&gt;&lt;br&gt;The Gallery class provides a few methods. They are all pretty short. Most of the methods are public and have as their goal providing information for the various Views and allowing the Controller to make changes to the Gallery. &lt;br&gt;&lt;br&gt;The &lt;b&gt;Constructor&lt;/b&gt; takes a single parameter, the URL to the gallery XML file to load. This is a String. The Constructor just passes this item on to the load method which actually starts the loading process.&lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;public function Gallery( url:String ) {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;load( url );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;}&lt;/font&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;The &lt;b&gt;load&lt;/b&gt; method takes a single parameter, the URL of the file XML file to load. This method creates a new instance of the XMLLoader class and passes the url. &lt;br&gt;&lt;br&gt;Then we add an EventListener to our XMLLoader instance. This listener listens for the COMPLETE event which is handled by the on_complete method. &lt;br&gt;&lt;br&gt;Making this method public makes the class a little more flexible.&lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;public function load( url:String ):void {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;var xml:XMLLoader = new XMLLoader( url );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;xml.addEventListener( Event.COMPLETE, on_complete );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;}&lt;/font&gt;&lt;br&gt;&lt;br&gt;The &lt;b&gt;on_complete&lt;/b&gt; method is where store the XML file we just loaded and notify any listeners that we have completed the loading process. This method is private since it makes no sense for any other class to have access to it. &lt;br&gt;&lt;br&gt;We&amp;#39;ll also set _index to 0 here. After loading our XML file the Gallery should be viewing the first image. &lt;br&gt;&lt;br&gt;We also dispatch a CHANGE event to any of our listeners. So all the listeners will update and draw themselves based on the new data loaded. &lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;private function on_complete( e:Event ):void {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;_gallery_xml = new XML( e.target.data ).image;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;_index = 0;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;dispatchEvent( new Event( Event.COMPLETE ) );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;dispatchEvent( new Event( Event.CHANGE ) );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;}&lt;/font&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;To enable the Next and Previous buttons the Gallery class provides the &lt;b&gt;next&lt;/b&gt; and &lt;b&gt;prev&lt;/b&gt; methods. These are very similar. They increment or decrement the _index by 1. They also check the current value of of _index to make sure that it doesn&amp;#39;t get out of range. Last of all they dispatch a CHANGE event. &lt;br&gt;&lt;br&gt;To make sure _index does not reference an index beyond the last image we check the length of the XMLList, _gallery_xml. Note the of the XMLList tells the number of items in the list, items in he list are indexed starting on 0. So we need to subtract 1 from length to get the number of the last index. &lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;public function next():void {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if ( _index &amp;lt; _gallery_xml.length() - 1 ) {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_index ++;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;dispatchEvent( new Event( Event.CHANGE ) );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;public function prev():void {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if ( _index &amp;gt; 0 ) {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_index --;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;dispatchEvent( new Event( Event.CHANGE ) );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;}&lt;/font&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;We will want the next and previous buttons to know when there are images available. And, when there are no images available we&amp;#39;ll want the next button to disable itself. The same goes for the previous button when we&amp;#39;re on the first image.&amp;nbsp; For that we&amp;#39;ll use the &lt;b&gt;hasNext &lt;/b&gt;and &lt;b&gt;hasPrev&lt;/b&gt; methods. &lt;br&gt;&lt;br&gt;These two methods return a Boolean (true or false). The first, &lt;b&gt;hasNext&lt;/b&gt;, checks that the _index is less than the length of the XMLList -1. If this is true, there is a next image to view. &lt;br&gt;&lt;br&gt;The second method, &lt;b&gt;hasPrev&lt;/b&gt;, checks that _index is greater than 0. If it is there is a previous image available.&amp;nbsp; &lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;public function hasNext():Boolean {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return Boolean( _index &amp;lt; _gallery_xml.length() - 1 );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;public function hasPrev():Boolean {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return Boolean( _index &amp;gt; 0 );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;}&lt;/font&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;The &lt;b&gt;iterate_icons&lt;/b&gt; method is used to list all of the URLs to the thumbnail images. This function makes use of the Iterator Patern be sure to read the section on Iterator. &lt;br&gt;&lt;br&gt;The first step is to make an a new empty Array. Then create an XMLIterator to iterate through the _gallery_xml XMLList. We get the URLs of the thumbnails from the icon element and add them to the icons_array. Last, return an Iterator for the icon_array. &lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;public function iterate_icons():BasicIterator {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;var icons_array:Array = new Array();&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;var it:XMLIterator = new XMLIterator( _gallery_xml );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;while( it.hasNext() ) {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;icons_array.push( it.next().icon.toString() );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return new BasicIterator( icons_array );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;}&lt;/font&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;The last four functions are getter setter functions, see the chapter on functions for more info on these. These allows us us to get and set properties of the Gallery class. This is a great example of getters and setters at work. &lt;br&gt;&lt;br&gt;The &lt;b&gt;set index&lt;/b&gt; function allows us to set the value of _index. In the same way that we would set the value of any property for any other object. Why using a setter function is so important here is that changing the value of _index means that the View and Controller need to be notified. If we had used a public property, you could change the value from outside of the class and Gallery would have no idea that the value you had changed. using a setter here allows our class to run the function when the value changes. &lt;br&gt;&lt;br&gt;Notice the setter function dispatches a CHANGE event after the value of _index is set to a new value. I included the getter for index since a View or Controller for Gallery might need to know what the current index was. &lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;public function get &lt;font color="#ff0000"&gt;index&lt;/font&gt;():uint {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return _index;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;public function set &lt;font color="#ff0000"&gt;index&lt;/font&gt;( n:uint ):void {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;_index = n;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;dispatchEvent( new Event( Event.CHANGE ) );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;}&lt;/font&gt;&lt;br&gt;&lt;br&gt;Notice that I used the name &lt;b&gt;index&lt;/b&gt; for the name of each function. Accessing these two getter and setter functions from outside the class we&amp;#39;ll use the name &lt;b&gt;index&lt;/b&gt; as the property name. For example:&lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;_gallery.index = 5; // Sets _index&lt;/font&gt;&lt;br&gt;&lt;br&gt;or &lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;trace( _gallery.index ); // Gets _index&lt;/font&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;Our main view will need to know what the URL for image at the current index is. For this I used a simple getter function called &lt;b&gt;image&lt;/b&gt;. This makes it easy for a View to get the URL from the &lt;b&gt;image&lt;/b&gt; property. &lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;public function get &lt;/font&gt;&lt;font face="courier new"&gt;&lt;font color="#ff0000"&gt;image&lt;/font&gt;&lt;/font&gt;&lt;font face="courier new"&gt;():String {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return _gallery_xml[ _index ].url.toString();&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;}&lt;/font&gt;&lt;br&gt;&lt;br&gt;For example any class with a reference to a Gallery instance could get the image at the current index with:&lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;_gallery.index&lt;/font&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;The last getter returns the description for the current image. Again I used a simple getter named &lt;b&gt;desc&lt;/b&gt;. &lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;public function get &lt;font color="#ff0000"&gt;desc&lt;/font&gt;():String {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return _gallery_xml[ _index ].desc.toString();&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;}&lt;/font&gt;&lt;br&gt;&lt;br&gt;Any View that needs the description for the current image can use the following:&lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;_gallery.desc&lt;/font&gt;&lt;br&gt;&lt;br&gt;A class might need to know how many images are in the Gallery. We can use the length() method of the XMLList class to find out how many images nodes there are.&lt;br&gt;&amp;nbsp;&lt;br&gt;&lt;font face="courier new"&gt;public function get length():uint {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return _gallery_xml.length();&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;}&lt;/font&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Testing the Gallery class&lt;/b&gt;&lt;br&gt;To get a better understanding of the Gallery class test it out. Taking a good look at the Gallery itself is a good idea and will give you a better idea of it&amp;#39;s role in the MVC pattern. &lt;br&gt;&lt;br&gt;For this test we&amp;#39;ll use the trace statement. If you&amp;#39;re not familiar with this or need more information see the chapter on trace. &lt;br&gt;&lt;br&gt;Create a new Fla file in the same folder as the Gallery.as file. In this case we&amp;#39;ll add the script to the timeline on frame 1. This will be convenient for the test. &lt;br&gt;&lt;br&gt;Make a new instance of the Gallery class:&lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;var gallery:Gallery = new Gallery( &amp;quot;slideshow.xml&amp;quot; );&lt;/font&gt;&lt;br&gt;&lt;br&gt;Next, set add a COMPLETE event to the gallery. The gallery needs to load it&amp;#39;s XML before it has any data to work with. Add the following:&lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;gallery.addEventListener( Event.COMPLETE, on_complete );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;function on_complete( e:Event ):void {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // test code here&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;}&lt;/font&gt;&lt;br&gt;&lt;br&gt;From here we can test all of the Gallery classes methods and properties. Each of the followoing lines will test a property or method of the Gallery class. each line needs to be added to the on_complete handler. &lt;br&gt;&lt;br&gt;Find the current index (add the following line to the on_complete handler):&lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;trace( &amp;quot;The current index is:&amp;quot; + gallery.index );&lt;/font&gt;&lt;br&gt;&lt;br&gt;Test your Movie. The Output window should open and show:&lt;br&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;The current index is:0&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;br&gt;It shows 0 because the first index, that is the position of the first image is 0. &lt;br&gt;&lt;br&gt;Try another. Test the length. &lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;trace( &amp;quot;Length:&amp;quot; + gallery.length );&lt;/font&gt;&lt;br&gt;&lt;br&gt;Next get the URL to the current image:&lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;trace( gallery.image );&lt;/font&gt;&lt;br&gt;&lt;br&gt;Now advance to the next image and then test the image property again:&lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;gallery.next();&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;trace( gallery.image );&lt;/font&gt;&lt;br&gt;&lt;br&gt;You can see the Gallery contains and organizes all of the information/data needed to run the gallery. It doesn&amp;#39;t display images or make things happen on it&amp;#39;s own. Instead it makes these features available via it&amp;#39;s properties and methods. This is the goal of the Model in MVC. &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;GalleryViewImage&lt;/b&gt;&lt;br&gt;The GalleryViewImage class will be used to display the current image. This is the image set by _index within the Gallery class. The gallery class will supply the URL to the GalleryViewImage will load and display the Image. &lt;br&gt;&lt;br&gt;To make things easy for ourselves we&amp;#39;ll use an instance of the ImageLoader class. If you are not familiar with this class be sure to read it&amp;#39;s chapter. Basically this class encapsulates the Loader class and adds a few features. You could build your own View around the Loader class or another class instead of ImageLoader also. &lt;br&gt;&lt;br&gt;This class extends Sprite so we can add it to the stage. Since it is a View, it takes a Gallery instance as an argument in it&amp;#39;s constructor and registers with the Gallery instance for CHANGE events. &lt;br&gt;&lt;br&gt;I&amp;#39;ve also added arguments for width and height. Since the ImageLoader class requires these, I can easily pass them along when making an instance of GalleryViewImage. This will allow us to easily set up the class to work with different sized images when using the class with different projects. &lt;br&gt;&lt;br&gt;The only other function here is on_change. In this View on_change gets the image value, vie Gallery&amp;#39;s image getter. This returns the URL to current, so we pass it along to out ImageLoader instance&amp;#39;s load_image method, and ImageLoader loads the new image. &lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;package {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;import flash.display.*;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;import flash.events.*;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;import com.webdevils.display.ImageLoader;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public class GalleryViewImage extends Sprite {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;private var _gallery:Gallery;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;private var _image:ImageLoader;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public function GalleryViewImage( gallery:Gallery, w:Number, h:Number ) {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_gallery = gallery;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_gallery.addEventListener( Event.CHANGE, on_change );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_image = new ImageLoader( &amp;quot;&amp;quot;, w, h );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;addChild( _image );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;private function on_change( e:Event ):void {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_image.load_image( _gallery.image );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;}&lt;/font&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;GalleryViewDetails&lt;/b&gt;&lt;br&gt;This is another View that displays the description for the current image. It is very similar to the GalleryViewImage class. With the difference being it contains a TextField in place of the ImageLoader. &lt;br&gt;&lt;br&gt;Again this class follows the pattern for Views. It takes a reference to the Model, in our case a Gallery instance in the constructor. It saves a reference to the Model, and registers with the Model for CHANGE events. &lt;br&gt;&lt;br&gt;The on_change handler gets the description for the current image through Gallery&amp;#39;s desc getter. &lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;package { &lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;import flash.display.*;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;import flash.events.*;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;import flash.text.*;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public class GalleryViewDetails extends Sprite {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;private var _gallery:Gallery;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;private var _txt:TextField;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public function GalleryViewDetails( gallery:Gallery,w:Number,h:Number ) {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_gallery = gallery;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_gallery.addEventListener( Event.CHANGE, on_change );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;var fmt:TextFormat = new TextFormat();&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;fmt.font = &amp;quot;Verdana&amp;quot;;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;fmt.size = 16;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_txt = new TextField();&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_txt.defaultTextFormat = fmt;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;addChild( _txt );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_txt.width = w;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_txt.height = h;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;private function on_change( e:Event ):void {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_txt.text = _gallery.desc;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;}&lt;/font&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;GalleryPrevNext&lt;/b&gt;&lt;br&gt;This class acts as a Controller. It displays two buttons. In this example I have created the buttons via AS to keep the example contained in the text of the class. You could easily have used MoveClips from your library instead. &lt;br&gt;&lt;br&gt;The two buttons when click call on the next and prev methods of the Gallery class. Which either advances Gallery to the next image sends it to the previous image. Gallery then, of course, in good MVC style, dispatches a CHANGE event, to notify it&amp;#39;s Views, which then update their display. &lt;br&gt;&lt;br&gt;This class also registers for CHANGE events. The on_change handler in GalleryPrevNext, is used to enable and disable the next button when there is not next image, or disable the previous button when there is not previous image. In this way this class acts as a View also. &lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;package {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;import flash.display.*;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;import flash.events.*;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public class GalleryPrevNext extends Sprite {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;private var _gallery:Gallery;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;private var _next:Sprite;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;private var _prev:Sprite;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public function GalleryPrevNext( gallery:Gallery ) {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_gallery = gallery;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_gallery.addEventListener( Event.CHANGE, on_change );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;make_buttons();&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;private function make_buttons():void {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_next = new Sprite();&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_next.graphics.beginFill( 0x999999 );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_next.graphics.drawRect( 0, 0, 32, 32 );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_next.graphics.endFill();&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;addChild( _next );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_prev = new Sprite();&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_prev.graphics.beginFill( 0x999999 );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_prev.graphics.drawRect( 0, 0, 32, 32 );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_prev.graphics.endFill();&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;addChild( _prev );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_next.x = _prev.width + 6;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_next.addEventListener( MouseEvent.CLICK, click_next );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_prev.addEventListener( MouseEvent.CLICK, click_prev );&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;private function click_next( e:MouseEvent ):void {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_gallery.next();&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;private function click_prev( e:MouseEvent ):void {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_gallery.prev();&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;private function on_change( e:Event ):void {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if ( _gallery.hasNext() ) {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_next.alpha = 1;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_next.mouseEnabled = true;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;} else {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_next.alpha = .5;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_next.mouseEnabled = false;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if ( _gallery.hasPrev() ) {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_prev.alpha = 1;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_prev.mouseEnabled = true;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;} else {&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_prev.alpha = .5;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_prev.mouseEnabled = false;&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;}&lt;/font&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;GalleryViewIcons&lt;/b&gt;&lt;br&gt;The GalleryViewIcons Class is probably the most difficult class of the bunch. This class needs to display the icons and allow a click to load the image associated with the icon. &lt;br&gt;&lt;br&gt;Since there may be more icons than might fit in the area you&amp;#39;ve designated for the icons, GalleryViewIcons will need to scroll or paginate the icons. &lt;br&gt;&lt;br&gt;There may be even more features associated with this class. The GalleryViewIcons class could be a Model View Controller system all to itself. In the example here we won&amp;#39;t go that far. A class this complex definitely needs to be broken down into several smaller classes. &lt;br&gt;&lt;br&gt;The icons will need to load the icon image, display an over and selected state and remember the index of the image they are associated with. &lt;br&gt;&lt;br&gt;The icons will need a container. The container will need to arrange and display the icons. It will need to define an area where they appear and mask off this area. The container may also need to move or paginate the icons to show icons that may not be visible under the mask. &lt;br&gt;&lt;br&gt;There may be other or alternative features needed or alternate approaches to what I have described here. We&amp;#39;ll just work with this feature set for the examples. &lt;br&gt;&lt;br&gt;&lt;b&gt;The GalleryIcon class&lt;/b&gt;&lt;br&gt;This class will load the icon image and act as&amp;nbsp; a button. As a button the icon will need to show an up, over, down and disabled face.&lt;br&gt;&lt;br&gt;Several approaches could be taken for this class. The example will create use a border for the selected state and modify the color of the image for the rollover and down states. &lt;br&gt;&lt;br&gt;Create a new class file. Save it as GalleryIcon&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Create a slide show presentation using Gallery&lt;/b&gt;&lt;br&gt;This Gallery makes a great base for a lot of applications. Using just the GalleryPrevNext class as the Controller you could create a linear slideshow/presentation. With a new Controller, that used the keyboard to display the next and previous image the application becomes very practical to use. &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7469465561312546205-3669841600985241886?l=flashcookbook.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://flashcookbook.blogspot.com/feeds/3669841600985241886/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://flashcookbook.blogspot.com/2009/11/model-view-controller.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7469465561312546205/posts/default/3669841600985241886'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7469465561312546205/posts/default/3669841600985241886'/><link rel='alternate' type='text/html' href='http://flashcookbook.blogspot.com/2009/11/model-view-controller.html' title='Model View Controller'/><author><name>mitchell</name><uri>http://www.blogger.com/profile/04639648390267025512</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7469465561312546205.post-6688892584263717798</id><published>2009-11-04T13:36:00.001-08:00</published><updated>2009-11-04T13:36:51.678-08:00</updated><title type='text'>Date and Time</title><content type='html'>&lt;b&gt;Date and Time&lt;br&gt;&lt;/b&gt;Flash provides the Date Class to handle the date and time. Creating a new instance of the Date Class generates an object with properties that contain the Year, Month, Date, and Time. This information is taken from the client operating system, so if the time or date is wrong on the system Flash is not responsible. &lt;br&gt;&lt;br&gt;The Date class can also take parameters naming a year, month, date and time to generate a Date object for any date and time. This is useful when creating a calendar, since a calendar might display all of the days a in a month. &lt;br&gt;&lt;br&gt;Using the Date Class in this way takes care of all of the troubles with calculating days in the month or leap years. &lt;br&gt;&lt;br&gt;&lt;b&gt;&lt;br&gt;Get the day and time&lt;/b&gt;&lt;br&gt;To get the day and time make a new instance of the Date class with no parameters. The following lines of code:&lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;var now:Date = new Date();&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;trace( now );&lt;/span&gt;&lt;br&gt;&lt;br&gt;Should generate something like this in the output window. &lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;Sat Oct 31 15:18:22 GMT-0700 2009&lt;/span&gt;&lt;br&gt;&lt;br&gt;To get the individual elements like year, month, date, day and time, you can access the properties of the date instance you have created. For example:&lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;var now:Date = new Date();&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;trace( now.month, now.date, now.fullYear );&lt;/span&gt;&lt;br&gt;&lt;br&gt;This displays something like:&lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;9 31 2009&lt;/span&gt;&lt;br&gt;&lt;br&gt;Note: month is displayed as a number. Looking at the first example you can see it's Halloween when I wrote this, so the month should 10. Flash numbers the Months 0 to 11. Rather than 1 to 12. So you'll need to add one if you want to display the digit and expect everyone to understand it. &lt;br&gt;&lt;br&gt;The same is true for the Date.day property. This property returns an integer between 0 and 6. where 0 is Mon and 1 is Tue etc. &lt;br&gt;&lt;br&gt;To get a simple easy to read day month and year you can use Date.toLocaleDateString(). For example:&lt;br&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;var now:Date = new Date();&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;trace( now.toLocaleDateString() );&lt;/span&gt;&lt;br&gt;&lt;br&gt;This outputs something like:&lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;Sat Oct 31 2009&lt;/span&gt;&lt;br&gt;&lt;br&gt;Which is very readable. Here's a sampling of a few of the functions supplied by the Date class to produce the date and time in different formats:&lt;br&gt;&lt;br&gt;&lt;ul&gt;&lt;li&gt;Date.toLocaleDateString() - &lt;span style="font-family: Courier New;"&gt;Sat Oct 31 2009&lt;/span&gt;&lt;/li&gt;&lt;li&gt;Date.toLocaleString() - &lt;span style="font-family: Courier New;"&gt;Sat Oct 31 2009 03:34:36 PM&lt;/span&gt;&lt;/li&gt;&lt;li&gt;Date.toLocaleTimeString() - &lt;span style="font-family: Courier New;"&gt;03:34:36 PM&lt;/span&gt;&lt;/li&gt;&lt;li&gt;Date.toString() - &lt;span style="font-family: Courier New;"&gt;Sat Oct 31 15:34:36 GMT-0700 2009&lt;/span&gt;&lt;/li&gt;&lt;li&gt;Date.toTimeString() - &lt;span style="font-family: Courier New;"&gt;15:34:36 GMT-0700&lt;/span&gt;&lt;/li&gt;&lt;li&gt;Date.toUTCString() - &lt;span style="font-family: Courier New;"&gt;Sat Oct 31 22:34:36 2009 UTC&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br&gt;Very interesting.&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Making a clock&lt;br&gt;&lt;/b&gt;To make clock with the Date class you'll need to create a new instance of the Date Class each time period that you want to update your clock. &lt;br&gt;&lt;br&gt;For example if you want your clock to update once a minute, you would need to make a new instance of the Date class each minute. &lt;br&gt;&lt;br&gt;if you want to make a clock that includes seconds, you'll need to make a new Date instance every second. &lt;br&gt;&lt;br&gt;Use the Timer class to set up a timer event that occurs at your time period. For example the following creates a TextField that displays the time and updates every second. For more info on the Timer class see Timer Recipes.&lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;var time_txt:TextField = new TextField();&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;time_txt.width = 200;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;addChild( time_txt );&lt;br&gt;&lt;br style="font-family: Courier New;"&gt;&lt;/span&gt;&lt;span style="font-family: Courier New;"&gt;var timer:Timer = new Timer( 1000 );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;timer.addEventListener( TimerEvent.TIMER, on_timer );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;timer.start();&lt;br&gt;&lt;br style="font-family: Courier New;"&gt;&lt;/span&gt;&lt;span style="font-family: Courier New;"&gt;function on_timer( e:TimerEvent ):void {&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;time_txt.text = new Date().toLocaleString();&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;}&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Getting all the days of the current month&lt;/b&gt;&lt;br&gt;This would be the first step to building a calendar application. It could also be used in many other ways. The basic idea is to get the current month and year then make Date Objects using that month and year each with a different day.&lt;br&gt;&lt;br&gt;If you make a Date Object with a day that is greater than the number of days in the current month the month will rollover to the next month. For example, imagine you make a Date Object for Feb 19 (and the year is not a leap year). In this case the Date object created will actually show the date as March 1. &lt;br&gt;&lt;br&gt;The same happens with the year. Making a Date Object with a date of Dec 32 2009, the date of the Object would actually show as Jan 1 2010. &lt;br&gt;&lt;br&gt;This recipe requires a loop to generate all of the days of the month. Be sure to read the recipes on loops. The following traces each day of the current month. &lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;var now:Date = new Date();&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;var current_year:int = now.fullYear;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;var current_month:int = now.month;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;for ( var d:uint = 1; d &amp;lt; 32; d++ ) {&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;var date:Date = new Date( current_year, current_month, d );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if ( date.month == current_month ) {&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;trace( date );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;}&lt;/span&gt;&lt;br&gt;&lt;br&gt;The code above can be broken down into three parts. &lt;br&gt;&lt;br&gt;The first, lines 1, 2 and 3, make a new Date object with the current date. Then we get the year and month and store them in the variables &lt;i&gt;current_year&lt;/i&gt; and &lt;i&gt;current_month&lt;/i&gt; for ease of use. &lt;br&gt;&lt;br /&gt;&lt;br&gt;Second, we set up a for loop that will count from 1 to 31, using the variable &lt;i&gt;d&lt;/i&gt; to hold the number of the count. &lt;br&gt;&lt;br&gt;Last, with each loop we make a new Date object from the current_year and current_month, using d as the date. The idea is to make Date objects with the current years and month for the dates 1 to 31. Since not all months have 31 days, we check the month of each new Date to see if the month is different. For example November has only 30 days, so creating a Date Object with month 11 and day 31, will return a Date with Month 12 and date 1. &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7469465561312546205-6688892584263717798?l=flashcookbook.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://flashcookbook.blogspot.com/feeds/6688892584263717798/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://flashcookbook.blogspot.com/2009/11/date-and-time.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7469465561312546205/posts/default/6688892584263717798'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7469465561312546205/posts/default/6688892584263717798'/><link rel='alternate' type='text/html' href='http://flashcookbook.blogspot.com/2009/11/date-and-time.html' title='Date and Time'/><author><name>mitchell</name><uri>http://www.blogger.com/profile/04639648390267025512</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7469465561312546205.post-4800495060867733562</id><published>2009-11-02T13:56:00.007-08:00</published><updated>2009-11-02T13:56:43.128-08:00</updated><title type='text'>Popup footer/Sidebar</title><content type='html'>&lt;b&gt;Popup footer/Sidebar&lt;/b&gt;&lt;br&gt;&lt;br&gt;This recipe creates a movieclip that slides on from one of the edges of the stage as cursor gets within a certain distance of that edge. The immediate example shows a movieclip sliding up from the below the bottom edge of the stage. &lt;br&gt;&lt;br&gt;The example is built from 2 movieclips one nested within the other. The first movieclip hit_mc has been assigned listeners, listening for the ROLL_OVER and ROLL_OUT events. While the inner, footer_mc, clip is animated. Here's the arrangement:&lt;br&gt;&lt;br&gt;hit_mc&lt;br&gt;&lt;div style="margin-left: 40px;"&gt;footer_mc&lt;br&gt;&lt;/div&gt;&lt;br&gt;At first thought you might think to place both clips on the stage, rather than nesting one within the other. This the problem of causing the clip in front to block mouse events for the clip that is behind. By nesting the clips both can still receive mouse events. &lt;br&gt;&lt;br&gt;The problem with two clips two separate clips, as opposed to the nested clips. Is that rolling over the first clip would start the second moving up. When the second clip interposed itself between the mouse and the first clip, the first clip would get a roll out message. &lt;br&gt;&lt;br&gt;To create the motion for this example I used tweener. See the Tweener recipes for more information on using Tweener.&lt;br&gt;&lt;br&gt;The registration point for footer_mc was set to the bottom left corner for this example. The position of registration point will determine the y values that you will assign to the Tweener tweens to hide and show the footer. &lt;br&gt;&lt;br&gt;Here's the code that I used for the example fla. &lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;import caurina.transitions.Tweener;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;hit_mc.addEventListener( MouseEvent.MOUSE_OVER, show_footer );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;hit_mc.addEventListener( MouseEvent.MOUSE_OUT, hide_footer );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;function show_footer( e:MouseEvent ):void {&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Tweener.addTween( hit_mc.footer_mc, { y:0, time:1 } );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;}&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;function hide_footer( e:MouseEvent ):void {&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Tweener.addTween( hit_mc.footer_mc, { y:hit_mc.footer_mc.height, time:1 } );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;}&lt;br&gt;&lt;br style="font-family: Arial;"&gt;&lt;font face="Verdana"&gt;Note, since footer_mc is nested within hit_mc I refer to it in the code above with &lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;hit_mc.footer_mc&lt;/span&gt;&lt;br&gt;&lt;br&gt;Also note, in the exmaple movie I used a rectangular shape on the lowest layer of hit_mc (its below footer_mc). I gave this shape a fill with a 10% transparency. This could be 0% transparent to make it completely invisible. This must be a filled shape. &lt;br&gt;&lt;br&gt;I used a 10% transparent fill to show where the hit area was for the example. &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Popup Footer/Sidebar 2&lt;/b&gt;&lt;br&gt;An obvious extension of this recipe is to add interactive elements to the popup. This is easily one by adding those elements nested within the footer_mc. For example imagine you have a movieclip named button_mc. Using the previous example as a starting point, this clip would be placed within footer_mc. The arrangement could be described like this:&lt;br&gt;&lt;br&gt;hit_mc&lt;br&gt;&lt;/font&gt;&lt;/span&gt;&lt;div style="margin-left: 40px;"&gt;&lt;span style="font-family: Courier New;"&gt;&lt;font face="Verdana"&gt;footer_mc&lt;br&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-left: 40px;"&gt;&lt;div style="margin-left: 40px;"&gt;&lt;span style="font-family: Courier New;"&gt;&lt;font face="Verdana"&gt;button_mc&lt;br&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;span style="font-family: Courier New;"&gt;&lt;br&gt;&lt;font face="Verdana"&gt;Form here the interactive elements can be treated the same as they are treated in any other recipe keeping in mind that the clips must be targeted as:&lt;br&gt;&lt;br&gt;hit_mc.footer_mc.button_mc&lt;br&gt;&lt;br&gt;Where button_mc could be the name of any clip nested within the footer. &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;/span&gt;&lt;div&gt;&lt;div style="margin-left: 40px;"&gt;&lt;/div&gt;&lt;div style="margin-left: 40px;"&gt;&lt;div style="margin-left: 40px;"&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="margin-left: 40px;"&gt;&lt;/div&gt;&lt;br&gt;&lt;/div&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7469465561312546205-4800495060867733562?l=flashcookbook.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://flashcookbook.blogspot.com/feeds/4800495060867733562/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://flashcookbook.blogspot.com/2009/11/popup-footersidebar.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7469465561312546205/posts/default/4800495060867733562'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7469465561312546205/posts/default/4800495060867733562'/><link rel='alternate' type='text/html' href='http://flashcookbook.blogspot.com/2009/11/popup-footersidebar.html' title='Popup footer/Sidebar'/><author><name>mitchell</name><uri>http://www.blogger.com/profile/04639648390267025512</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7469465561312546205.post-810326036228757023</id><published>2009-11-02T13:56:00.005-08:00</published><updated>2009-11-02T13:56:27.662-08:00</updated><title type='text'>Sticky Footer</title><content type='html'>&lt;b&gt;Sticky Footer&lt;/b&gt;&lt;br&gt;&lt;br&gt;The sticky footer is an element that sticks to the bottom of your Flash page. Imagine a MovieClip that always stays at the bottom of the stage even when the stage is resized. &lt;br&gt;&lt;br&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;Note this recipe makes use of the Full Browser Flash recipe. &lt;/span&gt;&lt;br&gt;&lt;br&gt;The basic ingredients for this recipe are the Event.RESIZE event and stage.stageHeight and stage.stageWidth properties. &lt;br&gt;&lt;br&gt;The Event.RESIZE event is dispatched when ever the stage changes size. Adding a listener for this event you can have the handler for the event look at the new size of the stage and reposition elements on the stage. &lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;stage.addEventListener( Event.RESIZE, resize_handler );&lt;/span&gt;&lt;br&gt;&lt;br&gt;Setting up the art. If you have a movieClip that will position itself at the bottom of the stage, placing the registration point of this clip at the bottom of the clip makes the process easier. Since setting the y of the clip to the height of the stage align the clip at the bottom edge of the stage. &lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;footer_mc.y = stage.stageHeight;&lt;/span&gt;&lt;br&gt;&lt;br&gt;If the registration point is at the top of the clip you can position the clip at stage.stageHeight - clip.height. &lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;footer_mc.y = stage.stageHeight - footer_mc.height;&lt;/span&gt;&lt;br&gt;&lt;br&gt;In order for Flash to place elements correctly the stage.align and stage.scaleMode properties need to be set so that Flash is keeping the registration point of the stage fixed in the upper left corner and is not scaling the contents of the stage as the stage is scaled.&lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;stage.align = StageAlign.TOP_LEFT;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;stage.scaleMode = StageScaleMode.NO_SCALE;&lt;/span&gt;&lt;br&gt;&lt;br&gt;The whole recipe might look like this. Assume that you have a MovieClip on the stage with the registration point aligned at the bottom of the artwork. This MovieClip is named footer_mc. &lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;stage.align = StageAlign.TOP_LEFT;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;stage.scaleMode = StageScaleMode.NO_SCALE;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;stage.addEventListener( Event.RESIZE, on_resize );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;function on_resize( e:Event ):void {&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;footer_mc.y = stage.stageHeight;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;}&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Testing the recipe:&lt;/b&gt;&lt;br&gt;Testing the movie in flash. Try resizing the stage. You should see the MovieClip footer_mc move to align itself with the bottom of the stage as the stage is resized. &lt;br&gt;&lt;br&gt;&lt;b&gt;Anomalies:&lt;/b&gt;&lt;br&gt;You may notice that the motion is a little jerky when testing in Flash. Don't worry, the repositioning of the clip will be much smoother in a browser or in the Flash Player.&lt;br&gt;&lt;br&gt;&lt;b&gt;Details:&lt;br&gt;&lt;/b&gt;To position the footer at the bottom of the stage when the movie begins, you can either place the clip on the stage at the correct position on the stage. If this not possible and or you need to preposition the clip with AS, you can do that with:&lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;footer_mc.y = stage.stageHeight;&lt;/span&gt;&lt;br&gt;&lt;br&gt;You'll need execute this line outside of the resize handler. Since the resize handler will only be called after the stage changes size. Placing the line above on the timeline or in the Constructor of a Class will probably accomplish this. You may need to place it in handler for the ADDED_TO_STAGE event in some cases. &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Sticky Footer 2: Adjustable width&lt;/b&gt;&lt;br&gt;The sticky footer is useful in the first configuration. But, often the stage will not only change height, it will also change in width. In many cases you will want your footer to expand to fill the width of the stage. &lt;br&gt;&lt;br&gt;Scaling footer_mc is not acceptable as everything inside the footer_mc will scale with it. To keep a consistent background in the footer that can cover the width of the stage requires an extra movie clip nested within footer_mc. Imagine this arrangement:&lt;br&gt;&lt;br&gt;footer_mc&lt;br&gt;&lt;div style="margin-left: 40px;"&gt;back_mc&lt;br&gt;&lt;/div&gt;&lt;br&gt;The script below sets the width of back_mc to the width of the stage whenever the stage is resized. This is the same as the code above with the addition line of code in red and the extra movieclip nested inside of footer_mc. &lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;stage.align = StageAlign.TOP_LEFT;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;stage.scaleMode = StageScaleMode.NO_SCALE;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;stage.addEventListener( Event.RESIZE, on_resize );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;function on_resize( e:Event ):void {&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;footer_mc.y = stage.stageHeight;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;span style="color: rgb(255, 0, 0);"&gt;footer_mc.back_mc.width = stage.stageWidth;&lt;/span&gt;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;}&lt;/span&gt;&lt;br&gt;&lt;div&gt;&lt;div style="margin-left: 40px;"&gt;&lt;/div&gt;&lt;br&gt;&lt;b&gt;&lt;br&gt;Sticky Footer 3: Add buttons to the footer&lt;/b&gt;&lt;br&gt;You may want to add interactive elements to the footer. This easily accomplished by adding these elements nested within the footer_mc. &lt;br&gt;&lt;br&gt;In this case all buttons are added inside of footer_mc. From the main timeline or document class these buttons would accessed as: &lt;br&gt;&lt;br&gt;footer_mc.button_mc&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Sticky Footer Popup&lt;/b&gt;&lt;br&gt;The Sticky Footer recipe can be combined with the Popup footer sidebar recipe. Here the footer_mc sticks to the bottom of the stage even after it has been resized. &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;/div&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7469465561312546205-810326036228757023?l=flashcookbook.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://flashcookbook.blogspot.com/feeds/810326036228757023/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://flashcookbook.blogspot.com/2009/11/sticky-footer_02.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7469465561312546205/posts/default/810326036228757023'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7469465561312546205/posts/default/810326036228757023'/><link rel='alternate' type='text/html' href='http://flashcookbook.blogspot.com/2009/11/sticky-footer_02.html' title='Sticky Footer'/><author><name>mitchell</name><uri>http://www.blogger.com/profile/04639648390267025512</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7469465561312546205.post-6260030538646466595</id><published>2009-11-02T13:56:00.003-08:00</published><updated>2009-11-02T13:56:26.369-08:00</updated><title type='text'>Sticky Footer</title><content type='html'>&lt;b&gt;Sticky Footer&lt;/b&gt;&lt;br&gt;&lt;br&gt;The sticky footer is an element that sticks to the bottom of your Flash page. Imagine a MovieClip that always stays at the bottom of the stage even when the stage is resized. &lt;br&gt;&lt;br&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;Note this recipe makes use of the Full Browser Flash recipe. &lt;/span&gt;&lt;br&gt;&lt;br&gt;The basic ingredients for this recipe are the Event.RESIZE event and stage.stageHeight and stage.stageWidth properties. &lt;br&gt;&lt;br&gt;The Event.RESIZE event is dispatched when ever the stage changes size. Adding a listener for this event you can have the handler for the event look at the new size of the stage and reposition elements on the stage. &lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;stage.addEventListener( Event.RESIZE, resize_handler );&lt;/span&gt;&lt;br&gt;&lt;br&gt;Setting up the art. If you have a movieClip that will position itself at the bottom of the stage, placing the registration point of this clip at the bottom of the clip makes the process easier. Since setting the y of the clip to the height of the stage align the clip at the bottom edge of the stage. &lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;footer_mc.y = stage.stageHeight;&lt;/span&gt;&lt;br&gt;&lt;br&gt;If the registration point is at the top of the clip you can position the clip at stage.stageHeight - clip.height. &lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;footer_mc.y = stage.stageHeight - footer_mc.height;&lt;/span&gt;&lt;br&gt;&lt;br&gt;In order for Flash to place elements correctly the stage.align and stage.scaleMode properties need to be set so that Flash is keeping the registration point of the stage fixed in the upper left corner and is not scaling the contents of the stage as the stage is scaled.&lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;stage.align = StageAlign.TOP_LEFT;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;stage.scaleMode = StageScaleMode.NO_SCALE;&lt;/span&gt;&lt;br&gt;&lt;br&gt;The whole recipe might look like this. Assume that you have a MovieClip on the stage with the registration point aligned at the bottom of the artwork. This MovieClip is named footer_mc. &lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;stage.align = StageAlign.TOP_LEFT;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;stage.scaleMode = StageScaleMode.NO_SCALE;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;stage.addEventListener( Event.RESIZE, on_resize );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;function on_resize( e:Event ):void {&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;footer_mc.y = stage.stageHeight;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;}&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Testing the recipe:&lt;/b&gt;&lt;br&gt;Testing the movie in flash. Try resizing the stage. You should see the MovieClip footer_mc move to align itself with the bottom of the stage as the stage is resized. &lt;br&gt;&lt;br&gt;&lt;b&gt;Anomalies:&lt;/b&gt;&lt;br&gt;You may notice that the motion is a little jerky when testing in Flash. Don't worry, the repositioning of the clip will be much smoother in a browser or in the Flash Player.&lt;br&gt;&lt;br&gt;&lt;b&gt;Details:&lt;br&gt;&lt;/b&gt;To position the footer at the bottom of the stage when the movie begins, you can either place the clip on the stage at the correct position on the stage. If this not possible and or you need to preposition the clip with AS, you can do that with:&lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;footer_mc.y = stage.stageHeight;&lt;/span&gt;&lt;br&gt;&lt;br&gt;You'll need execute this line outside of the resize handler. Since the resize handler will only be called after the stage changes size. Placing the line above on the timeline or in the Constructor of a Class will probably accomplish this. You may need to place it in handler for the ADDED_TO_STAGE event in some cases. &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Sticky Footer 2: Adjustable width&lt;/b&gt;&lt;br&gt;The sticky footer is useful in the first configuration. But, often the stage will not only change height, it will also change in width. In many cases you will want your footer to expand to fill the width of the stage. &lt;br&gt;&lt;br&gt;Scaling footer_mc is not acceptable as everything inside the footer_mc will scale with it. To keep a consistent background in the footer that can cover the width of the stage requires an extra movie clip nested within footer_mc. Imagine this arrangement:&lt;br&gt;&lt;br&gt;footer_mc&lt;br&gt;&lt;div style="margin-left: 40px;"&gt;back_mc&lt;br&gt;&lt;/div&gt;&lt;br&gt;The script below sets the width of back_mc to the width of the stage whenever the stage is resized. This is the same as the code above with the addition line of code in red and the extra movieclip nested inside of footer_mc. &lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;stage.align = StageAlign.TOP_LEFT;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;stage.scaleMode = StageScaleMode.NO_SCALE;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;stage.addEventListener( Event.RESIZE, on_resize );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;function on_resize( e:Event ):void {&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;footer_mc.y = stage.stageHeight;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;span style="color: rgb(255, 0, 0);"&gt;footer_mc.back_mc.width = stage.stageWidth;&lt;/span&gt;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;}&lt;/span&gt;&lt;br&gt;&lt;div&gt;&lt;div style="margin-left: 40px;"&gt;&lt;/div&gt;&lt;br&gt;&lt;b&gt;&lt;br&gt;Sticky Footer 3: Add buttons to the footer&lt;/b&gt;&lt;br&gt;You may want to add interactive elements to the footer. This easily accomplished by adding these elements nested within the footer_mc. &lt;br&gt;&lt;br&gt;In this case all buttons are added inside of footer_mc. From the main timeline or document class these buttons would accessed as: &lt;br&gt;&lt;br&gt;footer_mc.button_mc&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Sticky Footer Popup&lt;/b&gt;&lt;br&gt;The Sticky Footer recipe can be combined with the Popup footer sidebar recipe. Here the footer_mc sticks to the bottom of the stage even after it has been resized. &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;/div&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7469465561312546205-6260030538646466595?l=flashcookbook.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://flashcookbook.blogspot.com/feeds/6260030538646466595/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://flashcookbook.blogspot.com/2009/11/sticky-footer.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7469465561312546205/posts/default/6260030538646466595'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7469465561312546205/posts/default/6260030538646466595'/><link rel='alternate' type='text/html' href='http://flashcookbook.blogspot.com/2009/11/sticky-footer.html' title='Sticky Footer'/><author><name>mitchell</name><uri>http://www.blogger.com/profile/04639648390267025512</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7469465561312546205.post-7981349172255077940</id><published>2009-11-02T13:56:00.001-08:00</published><updated>2009-11-02T13:56:05.624-08:00</updated><title type='text'>Tweener Recipes</title><content type='html'>&lt;b&gt;Tweener Recipes&lt;br&gt;&lt;/b&gt;&lt;br&gt;&lt;b&gt;Introduction&lt;br&gt;&lt;/b&gt;Tweener is a set of Actionscript classes that animate the properties of objects in Flash. In it's most common useage Tweener is used to animate MovieClips on the stage. Tweener is not limited to animating MovieClips, it can be used to animate just about any property of any Object in Flash. This includes animating the Volume or Pan of a Sound. The text in a Text Field and more. &lt;br&gt;&lt;br&gt;When it comes to MovieClips Tweener can animate all of the standard MovieClip properties, like x, y, rotation and scaleX and scaleY. Tweener can also apply filters to Objects, and animate the properties of the filters. &lt;br&gt;&lt;br&gt;Tweener is flexible and easy to work with. &lt;br&gt;&lt;br&gt;Tweener requires only that copy the class library into the folder with your project and import the class in any script that will use it. &lt;br&gt;&lt;br&gt;&lt;b&gt;Downloading Tweener&lt;/b&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Working with the Tweener class library&lt;/b&gt;&lt;br&gt;The Tweener class library is contained with the folder &lt;i&gt;caurina&lt;/i&gt;. In order for any project to use Tweener you must place the &lt;i&gt;caurina&lt;/i&gt; folder in the same folder with your fla. &lt;br&gt;&lt;br&gt;For more information about working with class files and class libraries see the &lt;i&gt;Working with Classes recipe&lt;/i&gt;. &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Some recipes using Tweener&lt;br&gt;&lt;/b&gt;&lt;br&gt;&lt;b&gt;Basic Tweener recipes: Making things move&lt;br&gt;&lt;/b&gt;The following recipe makes things move with Tweener. Many of students, after learning Tweener, have said they find it easier to work with than using the timeline to create motion. &lt;br&gt;&lt;br&gt;You must place the caurina folder in the same folder as the fla for this example. &lt;br&gt;&lt;br&gt;The basic recipe for Tweener motion is first import the class with the following line. &lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;import caurina.transitions.Tweener;&lt;/span&gt;&lt;br&gt;&lt;br&gt;From here create a Tween by calling Tweener's static addTween function and passing two parameters, the target clip and an object describing the tween or motion that wish to create. &lt;br&gt;&lt;br&gt;For example imagine you wanted to make an object move to the center of the stage, you might use the following:&lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;Tweener.addTween( target, {x:275, time:1} );&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Animate multiple properties at the same time&lt;/b&gt;&lt;br&gt;To animate more than one property with Tweener just add them to the tween object. For example imagine you wanted to animate both scaleX and scaleY at the same time. You could use the following:&lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;Tweener.addTween( target, {&lt;span style="color: rgb(255, 0, 0);"&gt;scaleX:2, scaleY:2,&lt;/span&gt; time:1} );&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Setting the ease type&lt;/b&gt;&lt;br&gt;The type of easing applied with Tweener is set via the transition property of the Tween object. The transitions properties are listed as part of the documentation.&lt;br&gt;&lt;br&gt;Here's an example of an elastic ease out:&lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;Tweener.addTween( target, {x:275, time:1, &lt;span style="color: rgb(255, 0, 0);"&gt;transition:"elasticEaseOut"&lt;/span&gt; } );&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Animating Filter Properties&lt;/b&gt;&lt;br&gt;You can animate any of the filter properties with Tweener. You must first import the FilterShortcuts class and initialize the class with the following two lines:&lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;import caurina.transitions.properties.FilterShortcuts;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;FilterShortcuts.init();&lt;/span&gt;&lt;br&gt;&lt;br&gt;To animate a filter you'll need to consult the Tweener documentation to check the property's name. The following line animates the _Blur_blurX property. &lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;Tweener.addTween( target, {_Blur_blurX:40, time:2} );&lt;/span&gt;&lt;br&gt;&lt;br&gt;Bonus: You can apply a Filter to a clip with Tweener without having to animate the Filter. If you have already used Tweener in a project it's easier to apply a Filter this way. Just use addTween() without the time parameter. The following applies a drop shadow the target with a 12 pixel blur on the x and y axis:&lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;Tweener.addTween( astronaut_mc, { _DropShadow_blurX:12, _DropShadow_blurY:12 } );&lt;/span&gt;&lt;br&gt;&lt;br&gt;Exluding the time property from the tween object causes the properties listed in the tween object to be applied immediately. &lt;br&gt;&lt;br&gt;Note: Some filters may not become visible until certain properties are set. &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7469465561312546205-7981349172255077940?l=flashcookbook.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://flashcookbook.blogspot.com/feeds/7981349172255077940/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://flashcookbook.blogspot.com/2009/11/tweener-recipes.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7469465561312546205/posts/default/7981349172255077940'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7469465561312546205/posts/default/7981349172255077940'/><link rel='alternate' type='text/html' href='http://flashcookbook.blogspot.com/2009/11/tweener-recipes.html' title='Tweener Recipes'/><author><name>mitchell</name><uri>http://www.blogger.com/profile/04639648390267025512</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7469465561312546205.post-4738558579675680877</id><published>2009-11-02T13:55:00.003-08:00</published><updated>2009-11-02T13:55:30.325-08:00</updated><title type='text'>Buttons</title><content type='html'>&lt;div&gt;&lt;b&gt;Buttons&lt;/b&gt;&lt;br&gt;Buttons could be considered the core interactive element in any Flash project you might create. Buttons can take so many different forms that for this discussion we'll consider just about anything you can click on a Button. &lt;br&gt;&lt;br&gt;There's a lot that can be done with buttons. We'll divide this into two categories. What the button does itself when you interact with it, and what actions the button invokes in your application when you interact with it. &lt;br&gt;&lt;br&gt;For example, a button might glow, scale up and reflection might play across it's surface when you move the cursor over the button. These things happen tothe button. When you click the button your application might load an image. This is an action that your button is invoking in your application. &lt;br&gt;&lt;br&gt;Flash provides several different ways to create buttons. The two most common options are the Button Symbol and the MovieClip Symbol. Each has it's own options. For most situations the MovieClip provides more options. &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;The Button Symbol&lt;br&gt;&lt;/b&gt;The Button symbol can be used to create a Button in flash. The Button Symbol is similar the MovieClip Symbol but only has 4 frames. These frames are labeled Up, Over, Down and Hit. The Button Symbol automatically jumps to these frames as the cursor interacts with the Symbol. &lt;br&gt;&lt;br&gt;&lt;ul&gt;&lt;li&gt;Up - Frame is shown when the cursor is not over the clip&lt;/li&gt;&lt;li&gt;Over - Frame is shown when the cursor is over the clip but not pressed&lt;/li&gt;&lt;li&gt;Down - Frame is shown when the mouse is pressed over the clip&lt;/li&gt;&lt;li&gt;Hit - Frame is never displayed, it sets the clickable area for the clip&lt;/li&gt;&lt;/ul&gt;&lt;br&gt;Create a new Button by choosing Modify &amp;gt; Convert to Symbol or Insert &amp;gt; New Symbol. And then choosing Button from the Type menu. At this point you can draw your artwork on the various frames. &lt;br&gt;&lt;br&gt;Note: Be sure to set the Hit frame. Best to use a filled rectangle. Do not use an odd shape or text for the Hit frame. This will make your button difficult to interact with. &lt;br&gt;&lt;br&gt;Note: Buttons can use layers just like MovieClips. Feel free to use as many layers as you like to create the art that you envision. &lt;br&gt;&lt;br&gt;Note: You can nest animated MovieClip Symbols at the Over and Down frames within a a Button and those clips will play when the button reaches their frame. But, this is not a good method to create buttons with animated states. Better to use one of the MovieClip buttons described later. &lt;br&gt;&lt;br&gt;Note: Button clips only support a limited amount of Actionscript. &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;MovieClip Buttons&lt;/b&gt;&lt;br&gt;The MovieClip is the King of symbols n Flash it can do everything. It can also mimic all of the functionality of the Button symbol and more. &lt;br&gt;&lt;br&gt;To create a basic Button with Up, Over and Down frames, create a new MovieClip Symbol with Insert &amp;gt; New Symbol or Modify &amp;gt; Convert to Symbol and set the Type to MovieClip. Inside the new Symbol add three key frames and set the Frame Label at each of these frames to _up, _over and _down. These names must be spelled exactly as they appear here. &lt;br&gt;&lt;br&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;_up&lt;/li&gt;&lt;li&gt;_over&lt;/li&gt;&lt;li&gt;_down&lt;/li&gt;&lt;/ul&gt;&lt;br&gt;These combined with the MovieClip's buttonMode property allows the MovieClip to jump these key frames as the cursor interacts with the clip, much in the same way the Button Symbol works. &lt;br&gt;&lt;br&gt;Note: The MovieClip will automatically play unless you stop it with a stop() action. This can be done by targeting the clip or it can be placed on the first frame of the clip. &lt;br&gt;&lt;br&gt;The MovieClip doesn't provide a Hit frame. But you can easily simulate this by adding a layer containing a filled shape with a transparent color. Make sure this layer is below the other layers and extends across all of the frames you are using. &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;div&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;/div&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7469465561312546205-4738558579675680877?l=flashcookbook.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://flashcookbook.blogspot.com/feeds/4738558579675680877/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://flashcookbook.blogspot.com/2009/11/buttons_02.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7469465561312546205/posts/default/4738558579675680877'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7469465561312546205/posts/default/4738558579675680877'/><link rel='alternate' type='text/html' href='http://flashcookbook.blogspot.com/2009/11/buttons_02.html' title='Buttons'/><author><name>mitchell</name><uri>http://www.blogger.com/profile/04639648390267025512</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7469465561312546205.post-4680997211220401051</id><published>2009-11-02T13:55:00.001-08:00</published><updated>2009-11-02T13:55:28.976-08:00</updated><title type='text'>Buttons</title><content type='html'>&lt;div&gt;&lt;b&gt;Buttons&lt;/b&gt;&lt;br&gt;Buttons could be considered the core interactive element in any Flash project you might create. Buttons can take so many different forms that for this discussion we'll consider just about anything you can click on a Button. &lt;br&gt;&lt;br&gt;There's a lot that can be done with buttons. We'll divide this into two categories. What the button does itself when you interact with it, and what actions the button invokes in your application when you interact with it. &lt;br&gt;&lt;br&gt;For example, a button might glow, scale up and reflection might play across it's surface when you move the cursor over the button. These things happen tothe button. When you click the button your application might load an image. This is an action that your button is invoking in your application. &lt;br&gt;&lt;br&gt;Flash provides several different ways to create buttons. The two most common options are the Button Symbol and the MovieClip Symbol. Each has it's own options. For most situations the MovieClip provides more options. &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;The Button Symbol&lt;br&gt;&lt;/b&gt;The Button symbol can be used to create a Button in flash. The Button Symbol is similar the MovieClip Symbol but only has 4 frames. These frames are labeled Up, Over, Down and Hit. The Button Symbol automatically jumps to these frames as the cursor interacts with the Symbol. &lt;br&gt;&lt;br&gt;&lt;ul&gt;&lt;li&gt;Up - Frame is shown when the cursor is not over the clip&lt;/li&gt;&lt;li&gt;Over - Frame is shown when the cursor is over the clip but not pressed&lt;/li&gt;&lt;li&gt;Down - Frame is shown when the mouse is pressed over the clip&lt;/li&gt;&lt;li&gt;Hit - Frame is never displayed, it sets the clickable area for the clip&lt;/li&gt;&lt;/ul&gt;&lt;br&gt;Create a new Button by choosing Modify &amp;gt; Convert to Symbol or Insert &amp;gt; New Symbol. And then choosing Button from the Type menu. At this point you can draw your artwork on the various frames. &lt;br&gt;&lt;br&gt;Note: Be sure to set the Hit frame. Best to use a filled rectangle. Do not use an odd shape or text for the Hit frame. This will make your button difficult to interact with. &lt;br&gt;&lt;br&gt;Note: Buttons can use layers just like MovieClips. Feel free to use as many layers as you like to create the art that you envision. &lt;br&gt;&lt;br&gt;Note: You can nest animated MovieClip Symbols at the Over and Down frames within a a Button and those clips will play when the button reaches their frame. But, this is not a good method to create buttons with animated states. Better to use one of the MovieClip buttons described later. &lt;br&gt;&lt;br&gt;Note: Button clips only support a limited amount of Actionscript. &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;MovieClip Buttons&lt;/b&gt;&lt;br&gt;The MovieClip is the King of symbols n Flash it can do everything. It can also mimic all of the functionality of the Button symbol and more. &lt;br&gt;&lt;br&gt;To create a basic Button with Up, Over and Down frames, create a new MovieClip Symbol with Insert &amp;gt; New Symbol or Modify &amp;gt; Convert to Symbol and set the Type to MovieClip. Inside the new Symbol add three key frames and set the Frame Label at each of these frames to _up, _over and _down. These names must be spelled exactly as they appear here. &lt;br&gt;&lt;br&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;_up&lt;/li&gt;&lt;li&gt;_over&lt;/li&gt;&lt;li&gt;_down&lt;/li&gt;&lt;/ul&gt;&lt;br&gt;These combined with the MovieClip's buttonMode property allows the MovieClip to jump these key frames as the cursor interacts with the clip, much in the same way the Button Symbol works. &lt;br&gt;&lt;br&gt;Note: The MovieClip will automatically play unless you stop it with a stop() action. This can be done by targeting the clip or it can be placed on the first frame of the clip. &lt;br&gt;&lt;br&gt;The MovieClip doesn't provide a Hit frame. But you can easily simulate this by adding a layer containing a filled shape with a transparent color. Make sure this layer is below the other layers and extends across all of the frames you are using. &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;div&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;/div&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7469465561312546205-4680997211220401051?l=flashcookbook.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://flashcookbook.blogspot.com/feeds/4680997211220401051/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://flashcookbook.blogspot.com/2009/11/buttons.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7469465561312546205/posts/default/4680997211220401051'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7469465561312546205/posts/default/4680997211220401051'/><link rel='alternate' type='text/html' href='http://flashcookbook.blogspot.com/2009/11/buttons.html' title='Buttons'/><author><name>mitchell</name><uri>http://www.blogger.com/profile/04639648390267025512</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7469465561312546205.post-4634975440047749517</id><published>2009-11-02T13:54:00.001-08:00</published><updated>2009-11-23T15:26:33.244-08:00</updated><title type='text'>Drag and Drop</title><content type='html'>&lt;b&gt;Drag and Drop&lt;br&gt;&lt;/b&gt;&lt;br&gt;Dragging clips on the stage is easy to do. This recipe is built on a few simple ideas. &lt;br&gt;&lt;br&gt;First to get an object to follow the mouse around all Sprite and MovieClip classes share the startDrag() and stopDrag() methods. These methods do exactly what their names imply. The startDrag() method starts dragging a clip, while stopDrag() ends the drag. &lt;br&gt;&lt;br&gt;&lt;b&gt;Making a click and drag&lt;/b&gt;&lt;br&gt;This type of interactivity centers two events MOUSE_DOWN and MOUSE_UP. A drag always begins with a MOSUE_DOWN event and ends with a MOUSE_UP. &lt;br&gt;&lt;br&gt;The key to making a reliable click and drag is to be sure to capture a MOUSE_UP event when the cursor is NOT over the target clip. Do this by also adding a MOUSE_UP event to the stage&lt;br&gt;&lt;br&gt;Often as you drag a clip the cursor will end up outside the area of a clip. This can happen if you move the cursor beyond the boundaries of drag or if you move the cursor very fast, or drag the cursor outside the area of the stage and then release. &lt;br&gt;&lt;br&gt;&lt;b&gt;Setting up a simple drag&lt;/b&gt;&lt;br&gt;To create a simple drag, create a clip on the stage and assign it an instance name. For this example assume the name of the clip is drag_mc. &lt;br&gt;&lt;br&gt;The code block below allows the clip drag_mc to be dragged all over the stage without limit. &lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;drag_mc.addEventListener( MouseEvent.MOUSE_DOWN, on_press );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;function on_press( e:MouseEvent ):void {&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;drag_mc.startDrag();&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;drag_mc.addEventListener( MouseEvent.MOUSE_UP, on_release );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;stage.addEventListener( MouseEvent.MOUSE_UP, on_release );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;}&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;function on_release( e:MouseEvent ):void {&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;drag_mc.stopDrag();&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;drag_mc.removeEventListener( MouseEvent.MOUSE_UP, on_release );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;stage.removeEventListener( MouseEvent.MOUSE_UP, on_release );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;}&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Explanation&lt;/b&gt;&lt;br&gt;The code block above works by adding an a MOUSE_DOWN event to the target clip. This event begins the dragging action. &lt;br&gt;&lt;br&gt;The handler for this event, on_press, starts dragging the clip by calling startDrag(). Here we also add two more event listeners, listening for the MOUSE_UP event. One of these events is added to the target clip, drag_mc in this example. The other is added to the stage. By adding the MOSUE_UP event to the stage we can catch the MOUSE_UP event in the case where the mouse is released outside the area of the target clip. Note both of these listeners are handled with the same functions on_release.&lt;br&gt;&lt;br&gt;The last part of the example is the on_release function. Here the dragging action is ended by calling stopDrag() on the target clip. Then we remove both of the MOUSE_UP event listeners. &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Details&lt;br&gt;&lt;/b&gt;Note, when a clip is being dragged via the&lt;br /&gt;startDrag() method Flash always rounds the x and y position of the clip&lt;br /&gt;to the nearest whole number. This is usually not a problem. In cases&lt;br /&gt;where a clip constrained to a vertical or horizontal line a clip may&lt;br /&gt;shift a pixel to one side as it is being dragged. If this happens be&lt;br /&gt;sure to check the x and y position of the clip and set the number to a&lt;br /&gt;whole number.&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Dragging from the center or dragging from an edge&lt;/b&gt;&lt;br&gt;The startDrag() method provides the option of dragging from the center or dragging from the point relative to the mouse when the drag was initiated. &lt;br&gt;&lt;br&gt;Dragging from the center is a drag where the clip aligns it's registration point with the cursor when the drag begins. &lt;br&gt;&lt;br&gt;Dragging from a relative point keeps the clip in the same relative position to the mouse as it is dragged. &lt;br&gt;&lt;br&gt;Why use one method or the other? Center drag is good for games and situations where the position of the clip, as you drag it needs to aligned to the mouse in some way. Dragging relative is best for situations where you don't want the object to move when it is initially clicked. This is good for scroll bars and things like dragging images around on a light table. &lt;br&gt;&lt;br&gt;This option is called lockCenter. Passing a true as the first parameter when calling startDrag() will force the clip to align at the registration point. Passing a false will cause the clip to move relative. Note false is the default value, so passing nothing defaults to a drag relative. The previous examples were working in this mode. Try out lockCenter with:&lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;drag_mc.startDrag(&lt;span style="color: rgb(255, 0, 0);"&gt; true &lt;/span&gt;);&lt;/span&gt;&lt;br&gt;&lt;br&gt;You should see the clip align it's registration point with the cursor. &lt;br&gt;&lt;br&gt;Note: If the registration point is not in the center the clip will not align with the center. For example if the registration point is set in the upper left corner of the clip then the clip will appear to drag from the upper left corner. See registration point notes.&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Limiting the area of a drag&lt;/b&gt;&lt;br&gt;Besides the lockCenter parameter startDrag() also takes an optional bounds parameter. This bounds parameter sets the boundaries for the drag action. The bounds defines a rectangle and during the drag the clip may only move within the rectangle. &lt;br&gt;&lt;br&gt;The bounds parameter must be an instance of the Rectangle Class. The Rectangle Object object describes a rectangle using four properties, x, y, width and height. The x and y place the upper left corner of the rectangle. From that corner the width and height extend to define the area of the rectangle. &lt;br&gt;&lt;br&gt;Try it out for yourself. Using the last example define a rectangle for the drag action. Below I have defined a Rectangle 300 by 200 pixels starting at x 100 and y 100. Notice that I set lockCenter to false for this example. &lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;drag_mc.addEventListener( MouseEvent.MOUSE_DOWN, on_press );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;function on_press( e:MouseEvent ):void {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: rgb(255, 0, 0);"&gt;var bounds:Rectangle = new Rectangle( 100, 100, 300, 200 );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;/span&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;drag_mc.startDrag( &lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt;, &lt;/span&gt;&lt;span style="font-family: Courier New; color: rgb(255, 0, 0);"&gt;bounds&lt;/span&gt;&lt;span style="font-family: Courier New;"&gt; );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;drag_mc.addEventListener( MouseEvent.MOUSE_UP, on_release );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;stage.addEventListener( MouseEvent.MOUSE_UP, on_release );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;}&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;function on_release( e:MouseEvent ):void {&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;drag_mc.stopDrag();&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;drag_mc.removeEventListener( MouseEvent.MOUSE_UP, on_release );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;stage.removeEventListener( MouseEvent.MOUSE_UP, on_release );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;}&lt;/span&gt;&lt;br&gt;&lt;br&gt;Note: To limit the drag to a horizontal line set the height of the bounds Rectangle to 0. To limit the drag to a vertical line set the width of the bounds to 0. For example, the following limits the drag to a horizontal line in the center of the stage, that stops 100 pixels from either side of the stage. &lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New; color: rgb(0, 0, 0);"&gt;var bounds:Rectangle = new Rectangle( &lt;span style="color: rgb(255, 0, 0);"&gt;100, 200, 350, 0&lt;/span&gt; );&lt;/span&gt;&lt;br&gt;&lt;br&gt;I came up with the numbers above by taking the left limit of 100 and setting that as the x. Then I vertical position and set that as y. Using the default stage size of 550 by 400, y of 200 is half the height 400. I wanted the right limit to stop 100 pixels from the right edge. Since the stage 550 width and I'm stopping 100 pixels from the left and right, I subtract 200 from the width for 350. Last, I don't want to move vertically so I set the height to 0. &lt;br&gt;&lt;br&gt;You may have noticed testing these examples, that the the clip, if it starts outside the area of the drag, it is forced into the are when you start moving it. Often you will want to create a drag that works from the current position of the clip. The line below modifies the example so that the clip drags all the way across the stage at it's current y position. &lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New; color: rgb(0, 0, 0);"&gt;var bounds:Rectangle = new Rectangle( &lt;span style="color: rgb(255, 0, 0);"&gt;0, &lt;span style="color: rgb(0, 0, 255);"&gt;drag_mc&lt;/span&gt;.y, 550, 0&lt;/span&gt; );&lt;br&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;drag_mc&lt;/span&gt;.startDrag( false, bounds );&lt;/span&gt;&lt;br&gt;&lt;br&gt;Note that I used drag_mc.y to set the y position for the bounds rectangle. This way the clip uses it's current position to set the drag. &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Getting the Bounds of an Object&lt;/b&gt;&lt;br&gt;It is very convenient to use an object on the stage, such as another MovieClip, to define the rectangle used as bounds. This can be accomplished with the getRect() or getBounds() methods. These methods return a Rectangle that defines the are of the clip. &lt;br&gt;&lt;br&gt;The getRect() and getBounds() methods are same with the difference that the rectangle returned by getRect() does not include any strokes, while getBounds() does include any strokes on the object in the area of the rectangle returned. &lt;br&gt;&lt;br&gt;Both getRect() and getBounds() take a single parameter that sets the coordinate space. This should usually be set to the parent clip. In the example below I use the keyword this, since the script is written on the main timeline and both clips are contained on the main timeline. &lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New; color: rgb(255, 0, 0);"&gt;var rect:Rectangle = bounds_mc.getRect( &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt; );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;drag_mc.startDrag( false, &lt;span style="color: rgb(255, 0, 0);"&gt;rect&lt;/span&gt; ); &lt;/span&gt;&lt;br&gt;&lt;br&gt;Note: getRect() and getBounds() return rectangles. If the object is not a rectangle the either function returns a rectangle that surrounds the Object, getBounds() would include any strokes, getRect() would ignore them. &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Dragable Class&lt;/b&gt;&lt;br&gt;To make the drag scrip more portable you could create a class that could be added to any MovieClip to make that clip dragable. The code above could be added to a class that extends MovieClip (or Sprite). &lt;br&gt;&lt;br&gt;This first example creates a Dragable class using inheritance.&lt;br&gt;&lt;br&gt;The script below should be saved in an Actionscript file named Dragable.as. The Dragable class can then be assign as the Base Class of any MovieClip in your library to make it Dragable. &lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;package {&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;import flash.display.*;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;import flash.events.*;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public class Dragable extends MovieClip {&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public function Dragable() {&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;super();&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;addEventListener( MouseEvent.MOUSE_DOWN, on_press );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;private function on_press( e:MouseEvent ):void {&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;addEventListener( MouseEvent.MOUSE_UP, on_release );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;stage.addEventListener( MouseEvent.MOUSE_UP, on_release );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;startDrag();&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;private function on_release( e:MouseEvent ):void {&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;removeEventListener( MouseEvent.MOUSE_UP, on_release );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;stage.removeEventListener( MouseEvent.MOUSE_UP, on_release );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;stopDrag();&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;}&lt;/span&gt;&lt;br&gt;&lt;br&gt;You can also make instances of this class using the new keyword. In this case you'd need to add artwork to the Dragable instance and add it to the display to make it visible. For example the following creates a new instance of Dragable and draws a black ellipse inside it and adds it to the display list. &lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;var dragable_mc:Dragable = new Dragable();&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;dragable_mc.graphics.beginFill( 0x000000 );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;dragable_mc.graphics.drawEllipse( 0, 0, 32, 48 );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;dragable_mc.graphics.endFill();&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;addChild( dragable_mc );&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Dargable using Composition&lt;/b&gt;&lt;br&gt;MakeDragable has the same effect as the script above but accomplishes the effect via Composition. &lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;package {&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;import flash.display.*;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;import flash.events.*;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public class MakeDragable {&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;private var _target:MovieClip;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public function MakeDragable( target:MovieClip ) {&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_target = target;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_target.addEventListener( MouseEvent.MOUSE_DOWN, on_press );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;private function on_press( e:MouseEvent ):void {&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_target.addEventListener( MouseEvent.MOUSE_UP, on_release );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_target.stage.addEventListener( MouseEvent.MOUSE_UP, on_release );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_target.startDrag();&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;private function on_release( e:MouseEvent ):void {&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_target.removeEventListener( MouseEvent.MOUSE_UP, on_release );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_target.stage.removeEventListener( MouseEvent.MOUSE_UP, on_release );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;_target.stopDrag();&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;}&lt;/span&gt; &lt;br&gt;&lt;br&gt;Use the class in this way. Create a new instance and pass instance name of the MovieClip that will be dragable. For example the follow would make drag_mc dragable, assume that drag_mc is on the stage and has been assigned the instance name drag_mc. &lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;new MakeDragable( drag_mc );&lt;/span&gt;&lt;br&gt;&lt;br&gt;Note: In the MakeDragable class we need to reference the stage from the _target property. Since the class doesn't extend MovieClip or other DisplayObject, it doesn't have a reference to the stage. &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Making a Scrollbar&lt;/b&gt;&lt;br&gt;A great application for dragging is a scrollbar. A scrollbar can be used for many different uses, scrolling text, or volume control or in place you need to allow users to present variable range for input. &lt;br&gt;&lt;br&gt;The basic idea is to create an object drags along the horizontal or vertical axis within a limited range. &lt;br&gt;&lt;br&gt;Key feature of the scroll bar is controlling the range of of the motion. The range of motion can be controlled in two ways. Set via a parameter, pass a value like 150 to set the range of motion. Your code would use this number to limit the range to 150 pixels. Or, reference an Object on the stage and use the size of that object to set the range. Here you would use the width or height of another object to set the range of motion. &lt;br&gt;&lt;br&gt;The first method is easiest, but can takes some guess work to gauge the right distance. The second method is more flexibly but requires a little more coding and an extra object on the stage. &lt;br&gt;&lt;br&gt;&lt;b&gt;Drag by setting the distance&lt;/b&gt;&lt;br&gt;The example below assumes that you have a MovieClip with the instance name drag_mc on the stage. This example assumes the clip is at it's topmost position and will be able to drag up to 200 pixels below that point. &lt;br&gt;&lt;br&gt;We'll create a Rectangle to set the bounds for the drag action and save it in a variable to use whenever we drag the clip. We'll also use the initial x and y value of the clip to generate the Rectangle. The rectangle is located at the x and y of drag_mc, has a width of 0 and a height of 200. &lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;var drag_rect:Rectangle = new Rectangle(drag_mc.x, drag_mc.y, 0, 200);&lt;/span&gt;&lt;br&gt;drag_mc.addEventListener( MouseEvent.MOUSE_DOWN, on_press );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;function on_press( e:MouseEvent ):void {&lt;br style="font-family: Courier New;"&gt;&lt;/span&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;drag_mc.startDrag( &lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt;, &lt;/span&gt;&lt;span style="font-family: Courier New; color: rgb(255, 0, 0);"&gt;drag_rect&lt;/span&gt;&lt;span style="font-family: Courier New;"&gt; );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;drag_mc.addEventListener( MouseEvent.MOUSE_UP, on_release );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;stage.addEventListener( MouseEvent.MOUSE_UP, on_release );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;}&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;function on_release( e:MouseEvent ):void {&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;drag_mc.stopDrag();&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;drag_mc.removeEventListener( MouseEvent.MOUSE_UP, on_release );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;stage.removeEventListener( MouseEvent.MOUSE_UP, on_release );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;}&lt;/span&gt;&lt;br&gt;&lt;br&gt;Note: You could set the numbers for the bounds Rectangle by typing all of the numbers. But, using the x and y of drag_mc make is convenient, since moving drag_mc will reposition the bounds without you having to change the script. &lt;br&gt;&lt;br&gt;&lt;b&gt;Drag by using another clip to define the distance&lt;/b&gt;&lt;br&gt;Let's try that again with a an object used to set the range. This example requires two MovieClips on the stage. Be sure to place the registration point for each clip in the upper left corner! This is important to make the clips drag correctly. &lt;br&gt;&lt;br&gt;The first should be a tall narrow rectangle. This will set the range. Name this clip track_mc.&lt;br&gt;&lt;br&gt;The second a smaller box. This will be the dragging clip. Name this clip drag_mc. &lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;var range:Number = &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Courier New;"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;track_mc.x + track_mc.height;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;var drag_rect:Rectangle = new Rectangle(track_mc.x, track_mc.y, 0, range );&lt;/span&gt;&lt;br&gt;drag_mc.addEventListener( MouseEvent.MOUSE_DOWN, on_press );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;function on_press( e:MouseEvent ):void {&lt;br style="font-family: Courier New;"&gt;&lt;/span&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;drag_mc.startDrag( &lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt;, &lt;/span&gt;&lt;span style="font-family: Courier New; color: rgb(255, 0, 0);"&gt;drag_rect&lt;/span&gt;&lt;span style="font-family: Courier New;"&gt; );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;drag_mc.addEventListener( MouseEvent.MOUSE_UP, on_release );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;stage.addEventListener( MouseEvent.MOUSE_UP, on_release );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;}&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;function on_release( e:MouseEvent ):void {&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;drag_mc.stopDrag();&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;drag_mc.removeEventListener( MouseEvent.MOUSE_UP, on_release );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;stage.removeEventListener( MouseEvent.MOUSE_UP, on_release );&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;}&lt;/span&gt;&lt;br&gt;&lt;br&gt;If the clips do not align on the stage, they should jump into alignment when you begin dragging. &lt;br&gt;&lt;br&gt;If the clips are offset and to the left, right, top or bottom check the registration points on both clips. Be sure they are both in the upper left corner. &lt;br&gt;&lt;br&gt;This example will allow the dragging clip to drag the entire height of the track. This will allow the dragging clip to move past the bottom of the track so that it stops when it's top edge reaches the bottom of the track. To keep the drag clip within the area of the track we need to make the range shorter than the track by the height of the dragger. &lt;br&gt;&lt;br&gt;Try this, modify the first line of the last example as follows: &lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;var range:Number = &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Courier New;"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;track_mc.x + track_mc.height - drag_mc.height;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;Now the range is the difference between the height of the track and the height of the dragger.&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Making a Scrollbar Class&lt;/b&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7469465561312546205-4634975440047749517?l=flashcookbook.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://flashcookbook.blogspot.com/feeds/4634975440047749517/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://flashcookbook.blogspot.com/2009/11/drag-and-drop.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7469465561312546205/posts/default/4634975440047749517'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7469465561312546205/posts/default/4634975440047749517'/><link rel='alternate' type='text/html' href='http://flashcookbook.blogspot.com/2009/11/drag-and-drop.html' title='Drag and Drop'/><author><name>mitchell</name><uri>http://www.blogger.com/profile/04639648390267025512</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
