Posts Tagged ‘cursor’

CustomCursor advanced

Wednesday, April 15th, 2009

OK, let’s begin talking about Design Patterns.

The best thing of OOP, is the capability to create something in way to reuse it in another situation by defining some patterns to follow. Basicly this is Design Patterns. There are several kinds of Patterns and one of them is the Singleton Pattern. It consists in create only one instance of a class and control it by global functions and properties. Unless you are using a multi-touch device, a good example of usage is a CustomCursor class. There is no need to create more than one instance of a custom cursor, because you can point to only one thing at time. However you can change your cursor behavior from anywhere in your application.

The Basics

Let’s create our Singleton class

package {
	import flash.display.Sprite;
 
	public class CustomCursor extends Sprite {
 
		private static var _instance:CustomCursor;
		public function CustomCursor(singleton:SingletonEnforcer):void{
		}
		public static function getInstance():CustomCursor{
			if(CustomCursor._instance == null){
				CustomCursor._instance = new CustomCursor(new SingletonEnforcer());
			}
 
			return CustomCursor._instance;
		}
	}
}
class SingletonEnforcer {
	public function SingletonEnforcer():void{
	}
}

(more…)