Welcome to my actionscript snippet library!

Actionscript Snips is a small repository of actionscript code that aims to save developers and designers time when developing a website.  
Showing posts with label Objects. Show all posts
Showing posts with label Objects. Show all posts

Right-Click Context Menu


var menu:ContextMenu = new ContextMenu();
menu.hideBuiltInItems();
var menuItem:ContextMenuItem = new ContextMenuItem("Go to google");
menuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, goToContextMenu);
menu.customItems.push(menuItem);
this.contextMenu = menu;

function goToContextMenu(event:ContextMenuEvent):void {
var link:URLRequest = new URLRequest("http://www.google.com");
navigateToURL(link,"_blank");
}

Center A Display Object


centerObject(obj); //Centers a display object

function centerObject(obj:DisplayObject):void {
obj.x = stage.stageWidth / 2 - obj.width / 2;
obj.y = stage.stageHeight / 2 - obj.height / 2;
}