PDA

View Full Version : Customized context menu help please!!!!



lambros
July 31st, 2007, 05:08 AM
hey guys i am trying to make my own right click menu for my site but it seems that i can't figure it out in AS3 !!! i even looked livedocs but i don't find any error...

can anyone please help finding what's going on wrong with my code and the right click menu doesn't work ?? it just stays the default one and not mine as it should!!!

this is my package i am using...


package {

import flash.net.URLRequest;
import flash.ui.ContextMenu;
import flash.ui.ContextMenuBuiltInItems;
import flash.ui.ContextMenuItem;

class myRightClick extends ContextMenu

public function myRightClick()
{
public var myMenu:ContextMenu = new ContextMenu();
myMenu.hideBuiltInItems();

var copyrightNotice:ContextMenuItem = new ContextMenuItem("@ V-Men 2007");
var mySiteLink:ContextMenuItem = new ContextMenuItem("VolleyMen Homepage");
copyrightNotice.separatorBefore = true;

myMenu.customItems.push(mySiteLink, copyrightNotice);

private function deadClick() {
}

private function gotoMySite() {
var mySite:URLRequest = new URLRequest("http://www.webng.com/volleyman/");
navigateToURL(mySite);
}

}
}

thatguythatsme
July 31st, 2007, 07:41 AM
Here's a quick example of one...



package {
import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;
import flash.ui.ContextMenuBuiltInItems;
import flash.events.ContextMenuEvent;
import flash.display.Sprite;
import flash.display.Shape;

public class RightClickMenu extends Sprite {
private var _contextMenu:ContextMenu;
private var _menuTitle:Array = ["My Menu Item", "My Second Menu Item ", "My Third Menu Item"];

public function RightClickMenu() {
_contextMenu = new ContextMenu();
removeDefaultItems();
addCustomMenuItems();
contextMenu = _contextMenu;
}

private function removeDefaultItems():void {
_contextMenu.hideBuiltInItems();
}

private function addCustomMenuItems():void {
for (var i:uint = 0; i<_menuTitle.length; i++) {
var menuTitle:ContextMenuItem = new ContextMenuItem(_menuTitle[i]);
_contextMenu.customItems.push(menuTitle);
menuTitle.addEventListener(ContextMenuEvent.MENU_I TEM_SELECT, launchMenuTitleClick);
}
}

private function launchMenuTitleClick(event:ContextMenuEvent):void {
trace("You clicked a context item")
}
}
}


David

lambros
July 31st, 2007, 06:48 PM
well i edit your code and it seems to be working but how can i refer to just one Context Item so i can put a separator but the most important i want when one of the items i will add when pressed to link to a URL . . .how can i refer to just one Items Click ?

edit::::::::
Finally i managed to get the menu i ant with links and all but now i got a problem importing it to my movie!!! i made the actionscipt file with my right click menu script as document class...but then som of my movie's functions doesn't work and i get compiler errors.......how do i fix it ??? or how can i have my rightClickMenu.as as my documents class but still retaining the functionability ?????

this is the final code i am using:

package {

import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;
import flash.ui.ContextMenuBuiltInItems;
import flash.events.ContextMenuEvent;
import flash.display.Sprite;
import flash.display.Shape;
import flash.net.*;

public class myRightClick extends Sprite {
private var _contextMenu:ContextMenu;
private var homepageItem:ContextMenuItem = new ContextMenuItem("V-Men Homepage");
private var _menuTitle:Array = ["Contact Us at lambrospower@yahoo.gr (msn)", "Copyrights Reserved @ V-Men 2007"];
private var mySiteLink:URLRequest = new URLRequest("http://www.webng.com/volleyman/");


public function myRightClick() {
_contextMenu = new ContextMenu();
removeDefaultItems();
addCustomMenuItems();
contextMenu = _contextMenu;
}

private function removeDefaultItems():void {
_contextMenu.hideBuiltInItems();
}

private function addCustomMenuItems():void {

_contextMenu.customItems.push(homepageItem);
homepageItem.addEventListener(ContextMenuEvent.MEN U_ITEM_SELECT, homepageItemClick);

for (var i:uint = 0; i<_menuTitle.length; i++) {
var menuTitle:ContextMenuItem = new ContextMenuItem(_menuTitle[i]);
_contextMenu.customItems.push(menuTitle);
menuTitle.addEventListener(ContextMenuEvent.MENU_I TEM_SELECT, launchMenuTitleClick);
}
menuTitle.separatorBefore = true;

}

private function launchMenuTitleClick(event:ContextMenuEvent):void {
// This function does nothing at all
}

private function homepageItemClick(event:ContextMenuEvent):void {
navigateToURL(mySiteLink);
}
}
}

thatguythatsme
August 1st, 2007, 05:15 AM
Will have a better look later today, most likely on my lunch but just quickly I can see 2 errors here...



private function addCustomMenuItems():void {

_contextMenu.customItems.push(homepageItem);
homepageItem.addEventListener(ContextMenuEvent.MEN U_ITEM_SELECT, homepageItemClick);

for (var i:uint = 0; i<_menuTitle.length; i++) {
var menuTitle:ContextMenuItem = new ContextMenuItem(_menuTitle[i]);
_contextMenu.customItems.push(menuTitle);
menuTitle.addEventListener(ContextMenuEvent.MENU_I TEM_SELECT, launchMenuTitleClick);
}
menuTitle.separatorBefore = true;

}


They should be MENU_ITEM_SELECT, you've left a space in between menu and an underscore in the wrong place on the other one...

What are the compiler errors you're getting, its difficult to say what's wrong without seeing any errors.

David

lambros
August 5th, 2007, 04:15 AM
ok nevermind i fixed it......i placed it in the first frame of my movie and i changed ome things and everythings works ok!!! you can test it here:

www.volleymen.tk

at the homepage it's AS3, and in slideshow it's AS2 (the same menu though :P:P:P:P:P:P)

flashtek
September 16th, 2007, 06:28 AM
Mind if I ask how do you implement this code?
Thanks in advance