使用Flash Player 11.2的新功能实现右键菜单

原文出处:http://twaver.servasoft.com/?p=3620

Flash Player 11.2新加了一个非常重要的特性:支持右键,具体参见:Flash Player 11.2 Beta Features
下面是在TWaver Flex的Network中使用右键菜单的效果,等了多少年的功能终于可以轻松实现了,不用再通过html的js脚本屏蔽右键菜单


使用Flash Player 11.2的新功能实现右键菜单

 

需要注意几点:
1. 从这里 下载Flash Player 11.2以及playerglobal.swc 文件
2. 将下载的flashplayer11-2_p3_playerglobal_122011.swc文件改名为playerglobal.swc,并放入 SDK的相应目录中(Adobe Flash Builder 4.5/sdks/4.5.1/frameworks/libs/player/11.2):


使用Flash Player 11.2的新功能实现右键菜单

 

3. 最好使用SDK 4.5或以上版本的SDK(SDK4.0之前不支持Flash Player 11)
4. 工程选项里Flash Player版本,需要设置为11.2
5. 工程选项里添加 -swf-version=15 编译选项


使用Flash Player 11.2的新功能实现右键菜单

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
			   xmlns:s="library://ns.adobe.com/flex/spark"
			   xmlns:mx="library://ns.adobe.com/flex/mx"
			   xmlns:twaver="http://www.servasoftware.com/2009/twaver/flex"
			   applicationComplete="init()">
	<fx:Script>
		<![CDATA[
			import mx.collections.ArrayCollection;
			import mx.controls.Menu;

			import twaver.*;

			private function init():void {
				var box:ElementBox = new ElementBox();

				var from:Node = new Node();
				from.name = "From";
				from.location = new Point(100, 100);
				box.add(from);

				var to:Node = new Node();
				to.name = "To";
				to.location = new Point(300, 300);
				box.add(to);

				var link:Link = new Link(from, to);
				link.name = "From - To";
				box.add(link);

				network.elementBox = box;
				network.addEventListener('rightClick', handleRighClick);
			}

			private var menu:Menu = null;

			private function handleRighClick(e:MouseEvent):void {
				var element:IElement = network.getElementByMouseEvent(e);
				var myMenuData:ArrayCollection = new ArrayCollection([
					{label: element == null ? "none" : element.name}
				]);
				if(menu != null){
					menu.hide();
				}
				menu = Menu.createMenu(network, myMenuData, false);
				var point:Point = network.globalToLocal(new Point(e.stageX, e.stageY));
				menu.show(point.x, point.y);
			}
		]]>
	</fx:Script>

	<twaver:Network id="network" width="100%" height="100%" backgroundAlpha="0" backgroundColor="#FF0000"/>
</s:Application>

 

完整工程见附件:TestRightClick

你可能感兴趣的:(Flex,右键菜单,TWaver)