AS3 Habbo Dicemaster Part 1


Well-Known Member
Rating - 100%
49   0   0
Basic information:
  • It will have the exact same open/close double-click points as the Dicemasters seen on Habbo Hotel.
  • It will be made using sliced up images of the different parts of the Dicemasters seen on Habbo Hotel.
  • To make this we will create the classes Dicemaster, Head, and Base. They all extend the Sprite class.
  • Dicemaster is a parent of both the Base and Head classes.
  • AS3 colour syntax has been used in accordance to the default FlashDevelop AS3 colour syntax scheme.
  • All files will be provided as they are introduced - including the full project file at the end.
Welcome to Part 1! Create a new file named - this is what we're going to be working on :).
Define the package the class is under;
Imported the Sprite class (because Dicemaster extends Sprite) and the MouseEvent class (for double clicking, of course);
	import flash.display.Sprite;
We are now ready to define the Dicemaster class. Remember that it extends the Sprite class, therefore inherits the properties, functions, methods, and variables of the Sprite class. Sprite is now known as the "Superclass" of Dicemaster;
	public class Dicemaster extends Sprite
(File: shadow) I embedded the shadow here, since I knew it wasn't going to be of any use afterward. I also created the references to a new Base object and a new Head object, named 'base' and 'head' respectively;
		[Embed(source = "../lib/dicemaster/shadow.png")]
		private var shadowClass:Class;
		private var shadow:Bitmap = new shadowClass();

		private var base:Base = new Base();
		public var head:Head = new Head();
Now for the primary class function. First I defined the positions of "shadow" (this is done in respect to the dimensions and positions of the other objects, so should be left at 'x = 11' and 'y = 57' as the rest will fit together with it). After that the shadow, base, and head are all added to the stage using the addChild() method - which is why Dicemaster extends Sprite. They also have their doubleClickEnabled properties set to "true" - so that they will dispatch an event whenever they are double clicked. After this, I then told the class to listen for the "head" and "base" to dispatch the event MouseEvent.DOUBLE_CLICK (which is just a String value, really).
		public function Dicemaster() 
			shadow.x = 11;
			shadow.y = 57;

			head.doubleClickEnabled = true;
			base.doubleClickEnabled = true;
			addEventListener(MouseEvent.DOUBLE_CLICK, onClick);
After the event is triggered (it will only trigger if the doubleClickEnabled property of "head" and "base" is set to true), it will trigger the onClick() function. Firstly it will ask "head" to check if it has been clicked (you'll find out why after), then the same with "base" if it hadn't. If "head" AND "base" hadn't been clicked, it wont do anything. If only "base" had been clicked, it will check if "head" is open and close it, or open it respectively.
		private function onClick(e:MouseEvent)
			if (head.checkClickPosition(e) == false)
				if (base.checkClickPosition(e) == true)
					if (head.state == true)
						head.state = false;
						head.state = true;
We're done with the Dicemaster class. Let's end it :).
This will not yet work, as it's referencing two classes that do not exist and will result in compiler errors if you try to test it.

Part 2 will be working on the and classes.
Part 3 will add numbers to the dices.
Part 4 will be simply adding the final product on to the stage using the class, and clearing anything up.