Forum Topic: AS: Swf right-click Menu

(8,546 views • 63 replies)

This topic is 3 pages long. [ 1 | 2 | 3 ]

<< < > >>
None

Denvish

Reply To Post Reply & Quote

Posted at: 7/1/05 10:28 AM

Denvish DARK LEVEL 46

Sign-Up: 04/25/03

Posts: 16,236

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

None

Galactic-Shit-Head

Reply To Post Reply & Quote

Posted at: 7/1/05 10:32 AM

Galactic-Shit-Head NEUTRAL LEVEL 03

Sign-Up: 06/30/05

Posts: 201

Great Denvish! I bookmarked this for the future!


None

Inglor

Reply To Post Reply & Quote

Posted at: 7/1/05 10:44 AM

Inglor NEUTRAL LEVEL 17

Sign-Up: 01/26/03

Posts: 10,948

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


None

CloudConnected

Reply To Post Reply & Quote

Posted at: 7/1/05 10:58 AM

CloudConnected DARK LEVEL 11

Sign-Up: 04/27/05

Posts: 2,270

I agree.


None

osto

Reply To Post Reply & Quote

Posted at: 7/1/05 10:59 AM

osto EVIL LEVEL 10

Sign-Up: 11/22/03

Posts: 13

thanks for that!!! :D


None

Denvish

Reply To Post Reply & Quote

Posted at: 7/1/05 11:03 AM

Denvish DARK LEVEL 46

Sign-Up: 04/25/03

Posts: 16,236

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

None

Starogre

Reply To Post Reply & Quote

Posted at: 7/1/05 11:31 AM

Starogre NEUTRAL LEVEL 18

Sign-Up: 05/08/04

Posts: 1,701

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.

BBS Signature

None

Nano256

Reply To Post Reply & Quote

Posted at: 7/6/05 02:57 PM

Nano256 DARK LEVEL 13

Sign-Up: 02/12/05

Posts: 1,474

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.

Move on to ActionScript 3.0 already!
The third post below this one is a lie.

BBS Signature

None

carmelhadinosaur

Reply To Post Reply & Quote

Posted at: 7/6/05 02:59 PM

carmelhadinosaur LIGHT LEVEL 45

Sign-Up: 06/23/03

Posts: 7,658

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

None

Nano256

Reply To Post Reply & Quote

Posted at: 7/6/05 06:25 PM

Nano256 DARK LEVEL 13

Sign-Up: 02/12/05

Posts: 1,474

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.

Move on to ActionScript 3.0 already!
The third post below this one is a lie.

BBS Signature

None

Denvish

Reply To Post Reply & Quote

Posted at: 7/6/05 06:38 PM

Denvish DARK LEVEL 46

Sign-Up: 04/25/03

Posts: 16,236

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

None

Nano256

Reply To Post Reply & Quote

Posted at: 7/6/05 06:59 PM

Nano256 DARK LEVEL 13

Sign-Up: 02/12/05

Posts: 1,474

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.

Move on to ActionScript 3.0 already!
The third post below this one is a lie.

BBS Signature

None

CW-Clayt

Reply To Post Reply & Quote

Posted at: 7/17/05 04:16 PM

CW-Clayt FAB LEVEL 10

Sign-Up: 07/20/04

Posts: 29

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;


None

Rantzien

Reply To Post Reply & Quote

Posted at: 7/24/05 06:52 AM

Rantzien FAB LEVEL 15

Sign-Up: 01/27/05

Posts: 3,426

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

None

Inglor

Reply To Post Reply & Quote

Posted at: 7/24/05 08:19 AM

Inglor NEUTRAL LEVEL 17

Sign-Up: 01/26/03

Posts: 10,948

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 :)


None

Rantzien

Reply To Post Reply & Quote

Posted at: 7/24/05 08:28 AM

Rantzien FAB LEVEL 15

Sign-Up: 01/27/05

Posts: 3,426

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

None

Pinkasaurus

Reply To Post Reply & Quote

Posted at: 7/29/05 04:28 AM

Pinkasaurus FAB LEVEL 27

Sign-Up: 06/24/05

Posts: 3,408

Is there a way to completely disable right clicking altogether?

BBS Signature

None

ImpotentBoy2

Reply To Post Reply & Quote

Posted at: 7/29/05 04:31 AM

ImpotentBoy2 LIGHT LEVEL 18

Sign-Up: 04/01/03

Posts: 5,318

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

Some times my "L" key decides not to work.


Happy

<deleted>

Reply To Post Reply & Quote

Posted at: 8/2/05 03:09 PM

Thanx, it helps.


None

Rantzien

Reply To Post Reply & Quote

Posted at: 9/8/05 01:47 PM

Rantzien FAB LEVEL 15

Sign-Up: 01/27/05

Posts: 3,426

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

None

liaaaam

Reply To Post Reply & Quote

Posted at: 9/8/05 01:54 PM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,534

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.


None

Rantzien

Reply To Post Reply & Quote

Posted at: 9/8/05 02:01 PM

Rantzien FAB LEVEL 15

Sign-Up: 01/27/05

Posts: 3,426

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

None

DevilsSin666X

Reply To Post Reply & Quote

Posted at: 9/12/05 04:14 PM

DevilsSin666X NEUTRAL LEVEL 14

Sign-Up: 09/03/04

Posts: 408

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

None

Denvish

Reply To Post Reply & Quote

Posted at: 9/12/05 04:20 PM

Denvish DARK LEVEL 46

Sign-Up: 04/25/03

Posts: 16,236

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

None

DevilsSin666X

Reply To Post Reply & Quote

Posted at: 9/12/05 04:42 PM

DevilsSin666X NEUTRAL LEVEL 14

Sign-Up: 09/03/04

Posts: 408

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

None

Denvish

Reply To Post Reply & Quote

Posted at: 9/12/05 04:47 PM

Denvish DARK LEVEL 46

Sign-Up: 04/25/03

Posts: 16,236

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

None

Greenskullkid

Reply To Post Reply & Quote

Posted at: 10/4/05 12:24 AM

Greenskullkid NEUTRAL LEVEL 17

Sign-Up: 04/13/05

Posts: 6,118

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");}

AUDIO PORTAL I'm Not Gay

BBS Signature

None

Foreverkul

Reply To Post Reply & Quote

Posted at: 10/4/05 12:29 AM

Foreverkul NEUTRAL LEVEL 20

Sign-Up: 09/22/04

Posts: 327

id just like to say

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


None

Greenskullkid

Reply To Post Reply & Quote

Posted at: 10/4/05 12:41 AM

Greenskullkid NEUTRAL LEVEL 17

Sign-Up: 04/13/05

Posts: 6,118

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

AUDIO PORTAL I'm Not Gay

BBS Signature

None

Rhinan

Reply To Post Reply & Quote

Posted at: 10/21/05 10:46 AM

Rhinan EVIL LEVEL 15

Sign-Up: 05/19/05

Posts: 562

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


All times are Eastern Standard Time (GMT -5) | Current Time: 06:48 AM

<< Back

This topic is 3 pages long. [ 1 | 2 | 3 ]

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!