/* * ContextMenuSetup class by Wade Walker. * wadedwalker.com/ * wadedwalker@gmail.com * * Copyright (c) 2006 - 2010 Wade Walker * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ package com.wadedwalker{ //--------------------------------------------------------------------------------------------------------------------------------------\\ import flash.display.*; import flash.events.*; import flash.net.*; import flash.ui.*; public class ContextMenuSetup { //--------------------------------------------------------------------------------------------------------------------------------------\\ private var cMenu:ContextMenu; private var titleName:String; private var email:String; private var copyright:String; private var linkObjectList:Array; private var linkValueList:Array; private var emailObjectList:Array; private var emailValueList:Array; private var mainTimeLine:InteractiveObject; //--------------------------------------------------------------------------------------------------------------------------------------\\ public function ContextMenuSetup() { linkObjectList = new Array(); linkValueList = new Array(); emailObjectList = new Array(); emailValueList = new Array(); } //--------------------------------------------------------------------------------------------------------------------------------------\\ public function initialize(mtl:InteractiveObject):void { cMenu = new ContextMenu(); cMenu.hideBuiltInItems(); mainTimeLine = mtl; mainTimeLine.contextMenu = cMenu; } //--------------------------------------------------------------------------------------------------------------------------------------\\ public function addMenuItem( caption:String, separatorBefore:Boolean = false, clickable:Boolean = true, linkType:String = "link", linkAddress:String = "http://wadedwalker.com"):void { if (mainTimeLine) { var contextMenuItem:ContextMenuItem = new ContextMenuItem(caption,separatorBefore,clickable,true); cMenu.customItems.push(contextMenuItem); if (linkType == "link") { linkObjectList.push(contextMenuItem); linkValueList.push(linkAddress); contextMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onLinkClick) } else if (linkType == "email") { emailObjectList.push(contextMenuItem); emailValueList.push(linkAddress); contextMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onEmailClick) } } else { trace("INITIALIZE FIRST!"); } } //--------------------------------------------------------------------------------------------------------------------------------------\\ private function onLinkClick(e:ContextMenuEvent) { navigateToURL(new URLRequest(linkValueList[linkObjectList.indexOf(e.currentTarget)]), "_blank"); } //--------------------------------------------------------------------------------------------------------------------------------------\\ private function onEmailClick(e:ContextMenuEvent) { navigateToURL(new URLRequest("mailto:" + emailValueList[emailObjectList.indexOf(e.currentTarget)])); } } }