1. Dear Guest, if you are not receiving a forgot pw email then use the contact form at the bottom of the page. Bare in mind this is not monitored 24/7. Join our discord for help with account issues/queries. Join our discord: by clicking HERE.
    Dismiss Notice
  2. Dismiss Notice
  3. Dear Guest, some forum sections are hidden for you. Register for FREE for unlimited access.
    Dismiss Notice

AS3 Habbo Dicemaster Part 1

Discussion in 'Tutorials' started by JfN, Jul 4, 2015.

Share This Page

  1. JfN

    JfN Well-Known Member

    Joined:
    Jan 18, 2012
    Messages:
    4,849
    Likes Received:
    28
    Trophy Points:
    48
    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.
    [hr]
    Welcome to Part 1! Create a new file named Dicemaster.as - this is what we're going to be working on :).

    Dicemaster.as
    Define the package the class is under;
    Code:
    package
    {
    Imported the Sprite class (because Dicemaster extends Sprite) and the MouseEvent class (for double clicking, of course);
    Code:
    	import flash.display.Sprite;
    	import flash.events.MouseEvent;
    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;
    Code:
    	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;
    Code:
    		[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).
    Code:
    		public function Dicemaster() 
    		{
    			shadow.x = 11;
    			shadow.y = 57;
    			addChild(shadow);
    			addChild(base);
    			addChild(head);
    
    			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.
    Code:
    		private function onClick(e:MouseEvent)
    		{
    			if (head.checkClickPosition(e) == false)
    			{
    				if (base.checkClickPosition(e) == true)
    				{
    					if (head.state == true)
    					{
    						head.removeChild(head.open);
    						head.addChild(head.closed);
    						head.state = false;
    					}
    					else
    					{
    						head.removeChild(head.closed);
    						head.addChild(head.open);
    						head.state = true;
    					}
    				}
    			}
    		}
    We're done with the Dicemaster class. Let's end it :).
    Code:
    	}
    }
    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 Head.as and Base.as classes.
    Part 3 will add numbers to the dices.
    Part 4 will be simply adding the final product on to the stage using the Main.as class, and clearing anything up.
     
  2. Lana

    Lana Forum Owner -

    Joined:
    Feb 24, 2012
    Messages:
    12,750
    Likes Received:
    333
    Trophy Points:
    83
    Nice tutorial @Jfn hopefully it helps someone out :D
     
  3. JfN

    JfN Well-Known Member

    Joined:
    Jan 18, 2012
    Messages:
    4,849
    Likes Received:
    28
    Trophy Points:
    48
    @Hobbs thanks buddy!
     
  4. Katie

    Katie Real Slim Klatie M.D. Banned

    Joined:
    Dec 21, 2010
    Messages:
    9,425
    Likes Received:
    9
    Trophy Points:
    38
    Nice work lad, sure will come in handy :)
     
  5. JfN

    JfN Well-Known Member

    Joined:
    Jan 18, 2012
    Messages:
    4,849
    Likes Received:
    28
    Trophy Points:
    48
    @Katie thanks lass, might do.
     

Top