Friday, November 2, 2012

Creating EasyTooltip class: Part 1

Today we'll begin creating a new library called EasyTooltip. It will be used for quick and easy implementation of tooltips (hints that pop up and follow the mouse as you roll over things) into your AS3/Flex/AIR games and applications.

Today we'll set up the project directory and create some base files. Create a directory somewhere, inside of it add a main.as file. This file is where we will test our examples.

If you use Flash IDE, you can set this class as the document class of your Flash proejct, so that you can also test how tooltips work if you add objects to stage using Flash.

In the same directory, add a new folder "com". Inside of it - "kircode". Then "EasyTooltip". In the last directory add a new file called EasyTooltip.as.

Here is the hierarchy so far:



Add some basic functionality in EasyTooltip.as:

package com.kircode.EasyTooltip 
{
/**
 * Utility for creation of tooltips.
 * @author Kirill Poletaev
 */
public class EasyTooltip 
{

public function EasyTooltip() 
{
trace("Tooltip manager created!");
}

}

}

In main.as, you can import this class and create an instance of it:

package  
{
import com.kircode.EasyTooltip.EasyTooltip;
import flash.display.MovieClip;
import flash.events.Event;
/**
 * Example of EasyTooltip library usage.
 * @author Kirill Poletaev
 */
public class main extends MovieClip
{
var tooltip:EasyTooltip;

public function main() 
{
addEventListener(Event.ADDED_TO_STAGE, init);
}

private function init(evt:Event):void {
tooltip = new EasyTooltip();
}

}

}

That's all for today. Next time we'll begin actually coding the class.

Thanks for reading!

No comments:

Post a Comment