Question

Actionscript/Flex 3 - Right Click Context Menu

Asked by: jrwalker2

Can you please provide an example for the following situation? I've looked and I haven't found many examples on context menus.

1. You have a datdGrid (columns --> Title, value1, value2)
2. A row is added to the datagrid
3. You right click on the row and a context menu appears with the following choice: "Create a copy"
4. A copy of the row is created and added to the datagrid, but with the words "Copy of" appended to the beginning  of the title field

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2008-04-01 at 21:52:06ID23288140
Topic

Adobe Flex

Participating Experts
2
Points
500
Comments
9

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. SQL Select where value1 or value2 are NOT empty
    Hi guys, I have a SQL table and I am I trying to select the below fields where either value1 or value2 are NOT empty. value1 and value2 will either contain text, or it may contain " " as in nothing, or it may be <null>. I tried using the bel...
  2. Actionscript/Flex 3 - Actionscript/Flex 3 - Duplicating …
    This is a follow-up to my question posted here: http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/Flex/Q_23288140.html I have the duplication of the rows working, but I am confused as to how to solve the following situation: 1. If you make a copy of a...
  3. Need help getting data to appear in a Flex dataGrid done in …
    Dear fellow developers: I am having trouble getting the data of my datagrid to appear in a very basic flex application using ActionScript. The data is static, and for some reason, the columns, and the column headings appear, but the data itself does not show up inside the t...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: PluckaPosted on 2008-04-01 at 22:10:35ID: 21260318

Firstly Flash and thus Flex only allows limited access to right click. You can customise the Right Click context menu, but it will still have the Flash options that you see when you right click now, and there is no way to get rid of that.

It's a real pain, I wish they would just let you use right click if you wanted to.

So you may want to think of a different method, ie selecting the row then selecting an option from a menu somewhere.

 

by: julianopolitoPosted on 2008-04-01 at 22:12:03ID: 21260323

Just added a clone function to the simpleclass. The rest should be fine for you.

//MXML
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" xmlns:ns1="*" creationComplete="init()">
	<mx:Script>
		<![CDATA[
			import mx.controls.Alert;
			import mx.collections.SortField;
			import mx.collections.Sort;
			import mx.collections.ArrayCollection;
			
			[Bindable]
			private var ac:ArrayCollection = new ArrayCollection([
			new SimpleClass("a",3,6),
			new SimpleClass("a",3,6),
			new SimpleClass("a",3,6),
			new SimpleClass("a",3,6),
			new SimpleClass("a",3,6),
			new SimpleClass("b",5,8),
			new SimpleClass("b",5,8),
			new SimpleClass("b",5,8),
			new SimpleClass("c",1,9),
			new SimpleClass("c",1,9),
			new SimpleClass("c",1,9),
			new SimpleClass("d",2,5),
			new SimpleClass("d",2,5),
			
			]);
			[Bindable]
			private var acg:ArrayCollection = new ArrayCollection();
			
			private function init(){
				var cm:ContextMenu = new ContextMenu();
				cm.hideBuiltInItems();
				var item:ContextMenuItem = new ContextMenuItem("Create Copy");
            	cm.customItems.push(item);
            	item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onSelectItem);
            	dg.contextMenu = cm;
 
			}
			private function onSelectItem(e:ContextMenuEvent):void{
				if(dg.selectedIndex >= 0){
					var copyItem:SimpleClass = SimpleClass(dg.selectedItem).clone();
					copyItem.title = "Copy -" + copyItem.title;
					ac.addItem(copyItem);
				}else{
					Alert.show("Select an item to copy","ATTENTION");
				}
			}
 
			
		]]>
	</mx:Script>
	<!-- THIS IS THE EDITABLE DG -->
	<mx:DataGrid id="dg" dataProvider="{ac}" editable="true">
		<mx:columns>
			<mx:DataGridColumn dataField="title" editable="false" />
			<mx:DataGridColumn dataField="value1" editorDataField="value" >
				<mx:itemEditor>
					<mx:Component>
						<mx:NumericStepper minimum="2" maximum="25" />
					</mx:Component>
				</mx:itemEditor>
			</mx:DataGridColumn>
			<mx:DataGridColumn dataField="value2" editorDataField="value">
				<mx:itemEditor>
					<mx:Component>
						<mx:NumericStepper minimum="2" maximum="25" />
					</mx:Component>
				</mx:itemEditor>
			</mx:DataGridColumn>
		</mx:columns>
	</mx:DataGrid>
	
	
</mx:Application>
 
 
//SimpleClass.as
 
package
{
	public class SimpleClass
	{
			[Bindable]
			private var _title:String = "";
			[Bindable]
			private var _v1:int = 0;
			[Bindable]
			private var _v2:int = 0;
			
			
			
			public function SimpleClass(tit:String = "", v1:int = 0,v2:int = 0){
				value1 = v1;
				value2 = v2;
				title = tit;			
			}
			
			[Bindable]
			public function get value1():int{
				return _v1;
			}
			public function set value1(v:int):void{
				_v1 = v;
			}
			[Bindable]
			public function get value2():int{
				return _v2;
			}
			public function set value2(v:int):void{
				_v2 = v;
			}
			[Bindable]
			public function get title():String{
				return _title;
			}
			public function set title(v:String):void{
				_title = v;
				
			}			
			public function clone():SimpleClass{
				return new SimpleClass(title,value1,value2);
			}
			
	}
}
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:

Select allOpen in new window

 

by: jrwalker2Posted on 2008-04-01 at 22:29:04ID: 31445095

Thanks julianopolito! Is it correct that all the other Flash menu options can not be removed?

 

by: julianopolitoPosted on 2008-04-01 at 22:36:10ID: 21260389

using the ContextMenu.hideBuiltInItems(); we can hide most of it, but the Settings and About will remain, because they are not optional. In the debug player you also see Debugger option and Show Redrw Regions, but only in the debugger player version, which users don't have. So when you use the cm.hideBuiltInItems(); the only options that will appear are
Settings...
About Adobe Flash Player 9...

Nothing else.

 

by: jrwalker2Posted on 2008-04-01 at 23:28:17ID: 21260555

I have the duplication of the rows working, but I am confused as to how to solve the following situation:

1. If you make a copy of a row where Tiltile = "My Test Ttitle",
The resulting row will have a Title="Copy - MyTest Title"

2. If I try to make another copy of the original row where Title="My Test Title", again it will result in a row with the Title="Copy - MyTest Title"

3. If I make a copy of the row with Title="Copy - MyTest Title", the resulting row will have
Title= "Copy - Copy - MyTest Title"

Question:
-----------
 Is there a simple way to create duplicates like the Windows operating system(i.e., Creating a row where Title="Copy(2)-My Test Title", Title="Copy(3)-My Test Title",Title="Copy(4)-My Test Title" and so on if you try to copy the original row or any of the copies)?

 

by: julianopolitoPosted on 2008-04-01 at 23:53:40ID: 21260637

for this you should create a ItemNameManager class that could do that job of verifying existing names and creating new ones in the format above. It's not that simple though, but you could try. One way is to loop through all items, and use some regular expression to verify if the currentitem fits a pattern, then verify if the new name needs a number like you proposed.

 

by: PluckaPosted on 2008-04-02 at 00:02:24ID: 21260674

Still sucks.

If you want right click to do something else other than a context menu, you just cant.

 

by: julianopolitoPosted on 2008-04-02 at 00:09:52ID: 21260691

yeah, sucks, but what can we do? this is what can be accomplished, and is very helpful sometimes. It is very likely that in near future we'll have both right and middle click accessible, but for now, that's the best we can do as developers.

 

by: jrwalker2Posted on 2008-04-02 at 08:03:24ID: 21263787

The following is what I have so far (mainly pseudocode).  Can you please help me with this?
I am basically thinking that I'll have a for block the iterates through the entire array (dataprovider of the datagrid), and check if the title of the current item of the for-loop contains the title of the selected item in the grid. If so then I increment a counter. I know that I will pass the selected item during my traversal, so the first copy of a row will always have a title that starts with "Copy(1) - ". But, I am not sure how to check for contains. Is there a way to check whether a string contains a particular substing like you can in other languages such as Java? Also, I think the above approach may work if the selected item does not already contain "Copy(*) - " in its title. I think that this prefix must be removed before going through the above steps to work in this situation. Thanks




private function onSelectItem(e:ContextMenuEvent):void{
                                if(dg.selectedIndex >= 0){
                                        var copyItem:SimpleClass = SimpleClass(dg.selectedItem).clone();
                                       
                                       var counter:int = 0;
                                     //  for each(item:SimpleClass in ac)
                                       // {
                                           
                                           for(var i:int=0; i<ac.length;i++)
                                          {
                                               //Check if there exists a copy already
                                               if(SimpleClass(i).title  contains SimpleClass(dg.selectedItem).title)
                                              {
                                                 counter++;
                                              }
                                          }
                                         //}

                                        copyItem.title = "Copy("+counter+") - " + copyItem.title;
                                        ac.addItem(copyItem);
                                }else{
                                        Alert.show("Select an item to copy","ATTENTION");
                                }
                        }

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...