Be a Supporter!

AS: Swf right-click Menu

  • 11,068 Views
  • 60 Replies
New Topic Respond to this Topic
Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
AS: Swf right-click Menu Jul. 1st, 2005 @ 10:28 AM Reply

AS: Main

Changing the swf right-click menu

I need to begin by saying that full customisation of the swf right-click menu is only available in Flash MX 2004 and higher. If you're stuck with an earlier version, the best you can do is disable the menu by using

FSCommand("showMenu", false);

=========================================================

OK. So if you ARE using MX 2004, you can basically change the swf context menu to suit your needs.
Lets start off by creating a new menu, and hiding the default Macromedia entries. This should be on the first frame of your Flash:

var myMenu=new ContextMenu();
myMenu.hideBuiltInItems();

Next, let's create a menu item that will open Newgrounds in a browser, and add the text 'Visit Newgrounds' to the menu

function itemHandler1(obj, item){getURL("http://newgrounds.com");}
item1=new ContextMenuItem("Visit Newgrounds", itemHandler1);
myMenu.customItems.push(item1);

This code could alternatively be written like this:

myMenu.customItems.push(new ContextMenuItem("Visit Newgrounds", itemHandler1));
function itemHandler1(obj, item){getURL("http://newgrounds.com");}

Finally, we replace the default menu with myMenu

_root.menu=myMenu;

That's it. You have a new context menu.

=========================================================

Here's an example that will show 'Stop' and 'Play' on the menu, greying one each one out when it's pressed.

var myMenu=new ContextMenu();
myMenu.hideBuiltInItems();
myMenu.customItems.push(new ContextMenuItem("Stop!", itemHandler0));
myMenu.customItems.push(new ContextMenuItem("Play!", itemHandler1));
myMenu.customItems[1].separatorBefore = true; //this will add a separator between the two items
function itemHandler0(obj, item){
_root.stop();
myMenu.customItems[0].enabled=false;
myMenu.customItems[1].enabled=true;
}
function itemHandler1(obj, item){
_root.play();
myMenu.customItems[0].enabled=true;
myMenu.customItems[1].enabled=false;
}
_root.menu=myMenu;

You can basically create as many itemHandler functions as you want, and push them into the menu array. In fact, it's entirely possible to adapt this code and run it on button/MC rollovers & rollouts, to allow different context menus for different symbols in your movie/game

More information

http://www.actionscript.org/fo...3?t=47891&page=2&pp=15
http://planetbob.net/ftd/contextmenu/contextmenu.htm
http://www.actionscript.org/tutorials/intermediate/context_menu/index.shtml


- - Flash - Music - Images - -

BBS Signature
Galactic-Shit-Head
Galactic-Shit-Head
  • Member since: Jun. 30, 2005
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to AS: Swf right-click Menu Jul. 1st, 2005 @ 10:32 AM Reply

Great Denvish! I bookmarked this for the future!

Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Swf right-click Menu Jul. 1st, 2005 @ 10:44 AM Reply

very good denvish, just for further reference use Stage.showMenu=false; instead of FScommand, it's newer and "faster"

CloudConnected
CloudConnected
  • Member since: Apr. 27, 2005
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to AS: Swf right-click Menu Jul. 1st, 2005 @ 10:58 AM Reply

I agree.

osto
osto
  • Member since: Nov. 22, 2003
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to AS: Swf right-click Menu Jul. 1st, 2005 @ 10:59 AM Reply

thanks for that!!! :D

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to AS: Swf right-click Menu Jul. 1st, 2005 @ 11:03 AM Reply

At 7/1/05 10:44 AM, Inglor wrote: very good denvish, just for further reference use Stage.showMenu=false; instead of FScommand, it's newer and "faster"

Oops. I knew that, I just wasn't paying attention when I copy/pasted that code.


- - Flash - Music - Images - -

BBS Signature
Starogre
Starogre
  • Member since: May. 8, 2004
  • Offline.
Forum Stats
Member
Level 18
Artist
Response to AS: Swf right-click Menu Jul. 1st, 2005 @ 11:31 AM Reply

AWWW. you copied and pasted! :P Just kidding.

Thanks for this tutorial. I found it VERY useful. *bookmarks*

You should've also included how to make the screen fullsize, through the right click menu.

I think it's like FSCommand (full, true) or something. I'm not sure.


the events are merely fictional, written, directed, and acted out by all who create them

BBS Signature
Redshift
Redshift
  • Member since: Feb. 12, 2005
  • Offline.
Forum Stats
Member
Level 15
Programmer
Response to AS: Swf right-click Menu Jul. 6th, 2005 @ 02:57 PM Reply

You can also change it to this to make your own custom "quality" buttons:

function itemHandler1(obj, item){_quality = "low";;}
item1=new ContextMenuItem("Low quality", itemHandler1);
myMenu.customItems.push(item1);

You can change "low" to other things like "best" (yes, a secret quality), medium or high.


#include <stdio.h>
char*p="#include <stdio.h>%cchar*p=%c%s%c;%cmain() {printf(p,10,34,p,34,10);}";
main() {printf(p,10,34,p,34,10);}

BBS Signature
carmelhadinosaur
carmelhadinosaur
  • Member since: Jun. 23, 2003
  • Offline.
Forum Stats
Member
Level 49
Blank Slate
Response to AS: Swf right-click Menu Jul. 6th, 2005 @ 02:59 PM Reply

Wow this is really awesome, people can learn AS well just from reading your guides! Good jobs Denvish!

P.S. Cool sig! :D


BBS Signature
Redshift
Redshift
  • Member since: Feb. 12, 2005
  • Offline.
Forum Stats
Member
Level 15
Programmer
Response to AS: Swf right-click Menu Jul. 6th, 2005 @ 06:25 PM Reply

I have a question.

How do you make a thing that goes out? Like in the default menu when you click "Quality" a little mini menu comes out and you can select the quality.


#include <stdio.h>
char*p="#include <stdio.h>%cchar*p=%c%s%c;%cmain() {printf(p,10,34,p,34,10);}";
main() {printf(p,10,34,p,34,10);}

BBS Signature
Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to AS: Swf right-click Menu Jul. 6th, 2005 @ 06:38 PM Reply

At 7/6/05 06:25 PM, icycomputer wrote: I have a question.

How do you make a thing that goes out? Like in the default menu when you click "Quality" a little mini menu comes out and you can select the quality.

Good question. Answer: I don't know.


- - Flash - Music - Images - -

BBS Signature
Redshift
Redshift
  • Member since: Feb. 12, 2005
  • Offline.
Forum Stats
Member
Level 15
Programmer
Response to AS: Swf right-click Menu Jul. 6th, 2005 @ 06:59 PM Reply

At 7/6/05 06:38 PM, Denvish wrote:
At 7/6/05 06:25 PM, icycomputer wrote: I have a question.

How do you make a thing that goes out? Like in the default menu when you click "Quality" a little mini menu comes out and you can select the quality.
Good question. Answer: I don't know.

Damn.


#include <stdio.h>
char*p="#include <stdio.h>%cchar*p=%c%s%c;%cmain() {printf(p,10,34,p,34,10);}";
main() {printf(p,10,34,p,34,10);}

BBS Signature
CW-Clayt
CW-Clayt
  • Member since: Jul. 20, 2004
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to AS: Swf right-click Menu Jul. 17th, 2005 @ 04:16 PM Reply

well here is what i would, do i dont know for the little mini menu, but to have just the quality.

Code:

function itemHandler5(obj, item){_quality = "high";}
function itemHandler6(obj, item){_quality = "medium";}
function itemHandler7(obj, item){_quality = "low";}

root_cm = new ContextMenu();
root_cm.hideBuiltInItems();

eee_cmi = new ContextMenuItem("High Quality", itemHandler5);
fff_cmi = new ContextMenuItem("Mid Quality", itemHandler6);
ggg_cmi = new ContextMenuItem("Low Quality", itemHandler7);

ccc_cmi.separatorBefore = true;
eee_cmi.separatorBefore = true;

root_cm.customItems.push(aaa_cmi, bbb_cmi, ccc_cmi, ddd_cmi, eee_cmi, fff_cmi, ggg_cmi);
_root.menu = root_cm;

Rantzien
Rantzien
  • Member since: Jan. 27, 2005
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to AS: Swf right-click Menu Jul. 24th, 2005 @ 06:52 AM Reply

At 7/1/05 10:28 AM, Denvish wrote: You can basically create as many itemHandler functions as you want

Not according to the Actionscript Dictionary, you can't. 15 appears to be the limit, although I never tested :P

At 7/1/05 11:31 AM, Starogre wrote: I think it's like FSCommand (full, true) or something. I'm not sure.

fscommand("fullscreen", true) is correct.

At 7/6/05 06:25 PM, icycomputer wrote: How do you make a thing that goes out? Like in the default menu when you click "Quality" a little mini menu comes out and you can select the quality.

It's not in the properties or methods of ContextMenuItem, so I don't think it's possible. Too bad, I could've used it too.

Oh, and I just thought I'd add one point to the tutorial:
Custom Items in a context menu can't contain the words "Macromedia", "Flash Player", or "Settings". To prevent trickery, I guess.


BBS Signature
Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Swf right-click Menu Jul. 24th, 2005 @ 08:19 AM Reply

At 7/24/05 06:52 AM, Rantzien wrote: Not according to the Actionscript Dictionary, you can't. 15 appears to be the limit, although I never tested :P

there are ways around that

At 7/6/05 06:25 PM, icycomputer wrote:
It's not in the properties or methods of ContextMenuItem, so I don't think it's possible. Too bad, I could've used it too.

sure it's possible, you make a movieclip that looks like the menu, and clicking the menu item pops it.

Custom Items in a context menu can't contain the words "Macromedia", "Flash Player", or "Settings". To prevent trickery, I guess.

actually, that's new to me, tnx :)

Rantzien
Rantzien
  • Member since: Jan. 27, 2005
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to AS: Swf right-click Menu Jul. 24th, 2005 @ 08:28 AM Reply

At 7/24/05 08:19 AM, Inglor wrote: sure it's possible, you make a movieclip that looks like the menu, and clicking the menu item pops it.

But that would close the regular menu right? What I meant was that I don't think it's possible to do it so that it looks and works like the usual. But you're right of course, there are ways around most things

actually, that's new to me, tnx :)

No prob :P


BBS Signature
GeoKureli
GeoKureli
  • Member since: Apr. 1, 2003
  • Offline.
Forum Stats
Supporter
Level 19
Game Developer
Response to AS: Swf right-click Menu Jul. 29th, 2005 @ 04:31 AM Reply

not entirely. there will always be 2 items in the menu. i wish you could though. then i could set right click to some action

<deleted>
Response to AS: Swf right-click Menu Aug. 2nd, 2005 @ 03:09 PM Reply

Thanx, it helps.

Rantzien
Rantzien
  • Member since: Jan. 27, 2005
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to AS: Swf right-click Menu Sep. 8th, 2005 @ 01:47 PM Reply

Hello boys and girls. I just came to think of this, a little tool I made quite a while ago. Note that you have to be very lazy or a copy-and-paster to have any use of it.

Good day, or in Swedish:
"Jamen då får du väl ha det så trevligt då, och så ses vi imorgon eller någon annan dag. Hej då, Betty!"


BBS Signature
liam
liam
  • Member since: Dec. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to AS: Swf right-click Menu Sep. 8th, 2005 @ 01:54 PM Reply

At 9/8/05 01:47 PM, Rantzien wrote: Hello boys and girls. I just came to think of this, a little tool I made quite a while ago. Note that you have to be very lazy or a copy-and-paster to have any use of it.

I saw that on the portal, I gave it a 1. It didn't deserve to stay in the portal but it can be useful.


Sup, bitches :)

BBS Signature
Rantzien
Rantzien
  • Member since: Jan. 27, 2005
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to AS: Swf right-click Menu Sep. 8th, 2005 @ 02:01 PM Reply

At 9/8/05 01:54 PM, -liam- wrote: I saw that on the portal, I gave it a 1. It didn't deserve to stay in the portal but it can be useful.

You are now my enemy.

No, just kidding. I know it didn't really belong in the portal, I would've voted low too :D


BBS Signature
DevilsSin666X
DevilsSin666X
  • Member since: Sep. 3, 2004
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
Response to AS: Swf right-click Menu Sep. 12th, 2005 @ 04:14 PM Reply

i used all the scripts said here and the menu looks like this...

Visit Newgrounds
-------------------------
Play!
Stop!
High Quality
Medium Quality
Low Quality
-------------------------
Settings
-------------------------
Debugger

is there any way i can insert a horizontal rule (the ------------...) in between "high Quality" and "stop!"?


[RE Club]:[SSB Crew]:[Free Hentai Exchange Club]

Want animated Signature Pics back? Copy this Sig Pic as protest!

BBS Signature
Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to AS: Swf right-click Menu Sep. 12th, 2005 @ 04:20 PM Reply

At 9/12/05 04:14 PM, DevilsSin666X wrote: is there any way i can insert a horizontal rule (the ------------...) in between "high Quality" and "stop!"?

This is the appropriate code line:

myMenu.customItems[1].separatorBefore = true; //this will add a separator between the two items

Just copy/paste that line, and change the [1] as appropriate.


- - Flash - Music - Images - -

BBS Signature
DevilsSin666X
DevilsSin666X
  • Member since: Sep. 3, 2004
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
Response to AS: Swf right-click Menu Sep. 12th, 2005 @ 04:42 PM Reply

At 9/12/05 04:20 PM, Denvish wrote: This is the appropriate code line:

thanks.


[RE Club]:[SSB Crew]:[Free Hentai Exchange Club]

Want animated Signature Pics back? Copy this Sig Pic as protest!

BBS Signature
Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to AS: Swf right-click Menu Sep. 12th, 2005 @ 04:47 PM Reply

At 9/12/05 04:42 PM, DevilsSin666X wrote:
At 9/12/05 04:20 PM, Denvish wrote: This is the appropriate code line:
thanks.

I can't believe I used 'appropriate' twice in the same post. Quelle fromage...


- - Flash - Music - Images - -

BBS Signature
Greenskullkid
Greenskullkid
  • Member since: Apr. 13, 2005
  • Offline.
Forum Stats
Member
Level 18
Audiophile
Response to AS: Swf right-click Menu Oct. 4th, 2005 @ 12:24 AM Reply

This might sound N00bie..
Buuut.. Where do I past this?

myMenu.customItems.push(new ContextMenuItem("Visit Newgrounds", itemHandler1));

function itemHandler1(obj, item){getURL("http://newgrounds.com");}


gsk.

Foreverkul
Foreverkul
  • Member since: Sep. 22, 2004
  • Offline.
Forum Stats
Member
Level 21
Blank Slate
Response to AS: Swf right-click Menu Oct. 4th, 2005 @ 12:29 AM Reply

id just like to say

FINALLY!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!111111
Ive been looking for this for a while and couldnt find it. Thx Denvish!

Greenskullkid
Greenskullkid
  • Member since: Apr. 13, 2005
  • Offline.
Forum Stats
Member
Level 18
Audiophile
Response to AS: Swf right-click Menu Oct. 4th, 2005 @ 12:41 AM Reply

At 10/4/05 12:29 AM, Foreverkul wrote: id just like to say

FINALLY!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!111111
Ive been looking for this for a while and couldnt find it. Thx Denvish!

=p what about me i bumped it from liek 2 years ago!!!111one


gsk.

Rhinan
Rhinan
  • Member since: May. 19, 2005
  • Offline.
Forum Stats
Member
Level 15
Game Developer
Response to AS: Swf right-click Menu Oct. 21st, 2005 @ 10:46 AM Reply

WHY DOES NOONE EVER EXPLAIN?!??!
this really doesn't help me, though i thought i finally found something...dissapointing =(

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to AS: Swf right-click Menu Oct. 21st, 2005 @ 02:10 PM Reply

At 10/21/05 10:46 AM, -Rhinan- wrote: WHY DOES NOONE EVER EXPLAIN?!??!
this really doesn't help me, though i thought i finally found something...dissapointing =(

How come everybody else in this thread is able to understand perfectly what I wrote, AND make it work, and you can't?

It's not a problem with the tutorial, it's a problem with your brain.


- - Flash - Music - Images - -

BBS Signature