Archive for the 'Reyco1 Framework' Category

Managing Context Menus in AS3 with the Reyco1 AS3 Tools

Reynaldo February 3rd, 2008

Hi all:

A context menu is a menu for a display object that pops up when right-clicking on it; also called a short-cut menu.

Using the Reyco1 Framework makes managing context menus really easy and very fast. First we need to import the necessary files:

1
2
import com.reyco1.manager.ContextMenuManager;
import com.reyco1.events.ContextMenuManagerEvent;

Now we create two instances of the ContextMenuManager class. One for the stage and one for a box movieclip on the stage.

3
4
var stageCM:ContextMenuManager = new ContextMenuManager(this);
var boxCM:ContextMenuManager = new ContextMenuManager(mcBox);

Now, using the addMenuItem method, we add a few menu items to each instances of the ContextMenuManager we just created. The addMenuItem method accepts 3 arguments: a string to represent the menu label, a boolean specifying if there should be separator before the menu item or not and another boolean specifying if the menu item is enabled.

5
6
7
8
9
stageCM.addMenuItem("Hello World!");
stageCM.addMenuItem("Hello Moon!");
stageCM.addMenuItem("Hello Star!", true);
 
boxCM.addMenuItem("Move to 0,0")

We then have each of the ContexMenuManager instances listen to the ContextMenuManagerEvent.MENU_SELECTED event which is fired each time a context menu item is selected.

10
11
stageCM.addEventListener(ContextMenuManagerEvent.MENU_SELECTED, handleMenuSelection);
boxCM.addEventListener(ContextMenuManagerEvent.MENU_SELECTED, handleBoxMenuSelection);

Finally, we create the event handler functions. Every ContextMenuManagerEvent event carries along with it a params object. This object contains two values “label” and “target”.

12
13
14
15
16
17
18
19
20
21
22
23
24
function handleMenuSelection($event:ContextMenuManagerEvent):void
{
	output.text = "the selected menu is: "+$event.params.label
}
 
function handleBoxMenuSelection($event:ContextMenuManagerEvent):void
{
	if($event.params.label == "Move to 0,0"){
		output.text = "moving "+$event.params.target.name+" to 0,0.";
		$event.params.target.x = 0;
		$event.params.target.y = 0;
	}
}

That’s it! There are other properties and methods that you can use, but basically these are all you need to get started. The sample fla can be found in the samples folder of the Reyco1 Framework.

Reyco1 AS3 Tools, Release 1

Reynaldo February 2nd, 2008

Hi All:

I added a few classes to the framework and decided that it was time to let it loose out into the wild. As I stated before, the classes in the framework are a compilation of classes I had written in AS2 and had ported over to AS3 along with others.

Out of the whole framework, my favorite classes are:

ContextMenuManager
Found in the “manager” package.
This class allows you to easily add and manage Right Click context menu’s to any display object, including the stage.

PayPalCart
Found in the “tool” package.
The PaypalCart is a class which allows you to build and customize your very own flash PayPal shopping cart.

QueryUtil
Found in the “util” package.
Using the new Dictionary class in AS3 along with the ExternalInterface class, this class allows you to grab any and all parameters in the url of the html page holding your swf.

FullBrowserExtension
Found in the “extension” package.
Any document class that extends the FullBrowserExtension is full browser ready and all you need to do is just have a bitmap tile in the library with “Tile” as the class name (linkage id).

These are just a few of the classes in the ever growing framework as I will be adding more and more in the near future. Some of the classes in the pipeline for the following weeks are a “FormValidator” which will use regular expressions to make sure the entries in a field are valid, a “LayoutManager which will be responsible the visual organization of your sites/application and a “VideoController” for easily controlling flv files.

You can see the documentation at http://www.reynaldocolumna.com/Reyco1FrameworkDocumentation and you can grab the files using subversion from http://reyco1.googlecode.com/svn/trunk.

There are examples for all the major classes in the “samples” folder. I would start there and crack open the fla’s and document files to see how to get started.

ENJOY!

Tags: , ,

« Prev

  • Friends

  • Props

  • Donations

  • website counter
  • Archives

  • Feedburner