TWaver网元动态转动效果

news/2024/7/4 1:43:46 标签: function, class, timer, application, network, object
class="baidu_pl">
class="article_content clearfix">
class="htmledit_views">

最近有客户提了一个网元动态旋转的需求,用TWaver实现起来还是很方便的,效果如下图所示:
主要实现功能:
1:网元动态旋转
2:网元选中效果,被选中网元快速转到最前端后停止旋转,取消选中自动重启旋转
3:根据鼠标位置自动调整旋转方向
4:可以在程序中修改fw/bw/fh/bh调整图片显示效果。

class="alignnone size-thumbnail wp-image-4325" style="border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; max-width:649px" />

代码如下所示:

class="language-javascript"><?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
				layout="absolute"
				creationComplete="test()"
				width="100%"
				height="100%"
				xmlns:ns="http://www.servasoftware.com/2009/twaver/flex">
	<mx:Script>
		<![CDATA[
			import mx.events.ResizeEvent;

			import twaver.Collection;
			import twaver.Consts;
			import twaver.ElementBox;
			import twaver.IData;
			import twaver.IElement;
			import twaver.Layer;
			import twaver.Node;
			import twaver.SelectionChangeEvent;
			import twaver.SelectionModel;
			import twaver.Styles;
			import twaver.SubNetwork;
			import twaver.Utils;
			import twaver.core.util.l.u;
			private var box:ElementBox = new ElementBox();

			private var _rotationList:Collection = new Collection();
			private var rectIndexMap:Object = {};
			private var indexRectMap:Object = {};
			private var rList:Collection = new Collection();
			private var _startAngle:Number = 90;
			private var timer:Timer;
			private var _selectNode:Node;

			private var _clockSise:Boolean = false;

			private var _stopAngle:Number = 0;
			private var _needStop:Boolean = false;

			[Embed(source="images/1.png")]
			public static const p1:Class;
			[Embed(source="images/2.png")]
			public static const p2:Class;
			[Embed(source="images/3.png")]
			public static const p3:Class;
			[Embed(source="images/4.png")]
			public static const p4:Class;
			[Embed(source="images/5.png")]
			public static const p5:Class;
			[Embed(source="images/6.png")]
			public static const p6:Class;
			[Embed(source="images/7.png")]
			public static const p7:Class;
			[Embed(source="images/8.png")]
			public static const p8:Class;

			public class="tags" href="/tags/FUNCTION.html" title=function>function get clockSise():Boolean
			{
				return _clockSise;
			}

			public class="tags" href="/tags/FUNCTION.html" title=function>function set clockSise(value:Boolean):void
			{
				if(this.clockSise==value){
					return;
				}
				_clockSise = value;
			}
			private class="tags" href="/tags/FUNCTION.html" title=function>function resetClockSize( point:Point):void {
				if (_needStop == true) {
					return;
				}
				if (point.x > this.network.width / 2) {
					clockSise = false;
				} else {
					clockSise = true;
				}
			}

			public class="tags" href="/tags/FUNCTION.html" title=function>function get selectNode():Node
			{
				return _selectNode;
			}

			public class="tags" href="/tags/FUNCTION.html" title=function>function set selectNode(value:Node):void
			{
				if(this.selectNode==value){
					return;
				}
				_selectNode = value;
				if(this.selectNode==null){
					_needStop = false;
					timer.delay = 30;
					if(!timer.running){
						timer.start();
					}
				}else{
					var rect:Rectangle = indexRectMap[this.selectNode] as Rectangle;
					var left:Boolean = (rect.x+rect.width/2)<network.width/2;
					if(left){
						clockSise = false;
					}else{
						clockSise = true;
					}
					var index:int = rotationList.getItemIndex(this.selectNode);

					var size:int = this.rotationList.count;
					var step:Number = 360/size;
					_stopAngle = 90 - index * step;
					_needStop = true;
					timer.delay = 5;
					if(!timer.running){
						timer.start();
					}
				}
			}

			public class="tags" href="/tags/FUNCTION.html" title=function>function start():void{
				timer.start();
			}
			public class="tags" href="/tags/FUNCTION.html" title=function>function stop():void{
				if(timer!=null){
					timer.stop();
				}
			}

			public class="tags" href="/tags/FUNCTION.html" title=function>function get startAngle():Number
			{
				return _startAngle;
			}

			public class="tags" href="/tags/FUNCTION.html" title=function>function set startAngle(value:Number):void
			{
				_startAngle = (value+360)%360;
				this.measureRotation();
			}

			public class="tags" href="/tags/FUNCTION.html" title=function>function get rotationList():Collection
			{
				return _rotationList;
			}

			public class="tags" href="/tags/FUNCTION.html" title=function>function set rotationList(value:Collection):void
			{
				_rotationList = value;
				this.box.layerBox.clear();
				var size:int = this.rotationList.count;
				for(var i:int = 0;i<size;i++){
					var l:Layer = new Layer("r:"+i);
					box.layerBox.add(l);
				}
				this.measureRotation();
			}
			private class="tags" href="/tags/FUNCTION.html" title=function>function measureRotation():void{
				rectIndexMap = {};
				indexRectMap = {};
				rList.clear();
				var size:int = this.rotationList.count;
				if(size==0){
					return;
				}
				var w:Number = this.network.width;
				var h:Number = this.network.height;

				var fw:Number = 1.0 / 3 * w;
				var bw:Number = 1.0 / 6 * w;
				var fh:Number = h / 2.5;
				var bh:Number = h / 7.0;

				var m:Number = (fw - bw) / 4;
				var cw:Number = m * 2 + bw;
				var halfcw:Number = cw / 2;
				var x:Number = halfcw + 15;
				w = w - halfcw * 2 - 30;
				var y:Number = bh / 2 + 10;
				h = h - fh / 2 - bh / 2 - 20;

				var step:Number = 360.0 / size;
				for(var i:int = 0;i<size;i++){
					var n:Node =  this.rotationList.getItemAt(i) as Node;
					var p:Point = this.getPointAtEllipse(x,y,w,h,startAngle+step*i);
					var px:Number = p.x;
					var py:Number = p.y;
					var pm:Number = (py - y) / h * (fw - bw) / 2;
					var ww:Number = pm * 2 + bw;
					var hh:Number = (py - y) / h * (fh - bh) + bh;
					var rect:Rectangle = new Rectangle(px - ww / 2, py - hh / 2, ww, hh);
					n.setSize(rect.width,rect.height);
					n.setCenterLocation(px,py);
					rectIndexMap[rect] = n;
					indexRectMap[n] = rect;
					rList.addItem(rect);
				}
				rList.sort(rectSort);

				for(var j:int = 0;j<size;j++){
					var rr:Rectangle = rList.getItemAt(j) as Rectangle;
					var nn:Node = rectIndexMap[rr];
					nn.layerID = "r:"+j;
				}
			}

			private class="tags" href="/tags/FUNCTION.html" title=function>function rectSort(r1:Rectangle,r2:Rectangle):int{
				if (r1.width> r2.width) {
					return 1;
				}
				if (r1.width < r2.width) {
					return -1;
				}
				return 0;
			}

			public class="tags" href="/tags/FUNCTION.html" title=function>function  getPointAtEllipse(x:Number,   y:Number,   w:Number,   h:Number,   angled:Number):Point {
				var angle:Number =angled / 180.0 * Math.PI;
				var px:Number = x + (Math.cos(angle) * 0.5 + 0.5) * w;
				var py:Number = y + (Math.sin(angle) * 0.5 + 0.5) * h;
				return new Point(px, py);
			}

			private class="tags" href="/tags/FUNCTION.html" title=function>function init():void{
				timer=new Timer(30);
				timer.addEventListener(TimerEvent.TIMER,class="tags" href="/tags/FUNCTION.html" title=function>function():void{
					if(clockSise){
						startAngle = startAngle+1;
					}else{
						startAngle = startAngle-1;
					}
					if(_needStop){
						var abs:Number = Math.abs(startAngle-(_stopAngle+360)%360);
						if(abs<2){
							timer.stop();
						}
					}
				});
				network.addEventListener(MouseEvent.MOUSE_MOVE,class="tags" href="/tags/FUNCTION.html" title=function>function(e:MouseEvent):void{
					var p:Point = network.getLogicalPoint(e);
					resetClockSize(p);
				});
				network.addEventListener(MouseEvent.MOUSE_DOWN,class="tags" href="/tags/FUNCTION.html" title=function>function(e:MouseEvent):void{
					var p:Point = network.getLogicalPoint(e);
					var element:IElement = network.getElementByMouseEvent(e);
					selectNode = element as Node;
					resetClockSize(p);
				});
				network.addEventListener(ResizeEvent.RESIZE,class="tags" href="/tags/FUNCTION.html" title=function>function():void{
					measureRotation();
				});
			}

			private class="tags" href="/tags/FUNCTION.html" title=function>function test():void{
				init();
				Utils.registerImageByClass("p1", p1);
				Utils.registerImageByClass("p2", p2);
				Utils.registerImageByClass("p3", p3);
				Utils.registerImageByClass("p4", p4);
				Utils.registerImageByClass("p5", p5);
				Utils.registerImageByClass("p6", p6);
				Utils.registerImageByClass("p7", p7);
				Utils.registerImageByClass("p8", p8);
				var list:Collection = new Collection();
				for(var i:int = 1;i<9;i++){
					var sub:Node = new Node();
					sub.setStyle(Styles.SELECT_STYLE,Consts.SELECT_STYLE_BORDER);
					sub.setStyle(Styles.IMAGE_STRETCH,Consts.STRETCH_FILL);
					sub.setStyle(Styles.SELECT_COLOR,"0x00ff00");

					sub.setStyle(Styles.LABEL_POSITION,Consts.POSITION_CENTER);
					sub.image = "p"+i;
					sub.name = "sub"+i
					list.addItem(sub);
					box.add(sub);
				}
				this.rotationList = list;
				network.elementBox = box;
				this.start();
			}

		]]>
	</mx:Script>
	<ns:Network id="network" width="100%" height="100%" backgroundColor="0xffffff">

	</ns:Network>
</mx:Application>





http://www.niftyadmin.cn/n/1765856.html

相关文章

设备的3D化展示

现在收到的关于3D应用的需求主要集中在了4个方面&#xff0c;一是室外场景的再现&#xff0c;二是室内布局的呈现&#xff0c;三是单个设备对象的3D化呈现&#xff0c;四是空间交互。针对第三种需求&#xff0c;很多人都提出了设备打开动作&#xff0c;移出动作的需求&#xff…

小波分解及其Python实现方法

小波分解及其Python实现方法 摘要&#xff1a; 小波分解是一种信号处理方法&#xff0c;可以将信号分解为不同频率和时间分辨率的小波系数。在本文中&#xff0c;我们将详细介绍小波分解的原理和算法&#xff0c;并使用Python编程语言演示实现。我们将介绍小波函数的选择、离散…

替换TWaver中Tree展开合并图标

TWaver最大的优点之一是“ 灵活的定制功能”。光说不练不行&#xff0c;来个例子演练一下&#xff1a;定制Tree节点的标签。 默认Tree和Network上的标签显示的是网元的name属性&#xff0c;设置Styles.TREE_LABEL属性后&#xff0c;可以让Tree显示Styles.TREE_LABEL的值&#…

一个华为人写的忠告

一、“从小事做起&#xff0c;学会吃亏&#xff0c;与他人合作。   二、“心有多大&#xff0c;舞台就有多大。   三、“好好学习&#xff0c;天天向上"。   四、勇于实践&#xff0c;勇于犯错&#xff0c;善于反思。   五、要有方法、有套路&#xff0c;对问题系…

修改MySQL默认字符集

今天发现有库级字符集和表级字符集&#xff0c;实验了下发现&#xff0c;库级字符集是该库内表的默认字符集&#xff0c;当创建表时&#xff0c;如果未指定字符集&#xff0c;默认使用该表所属库的字符集。表也可使用不同于所属库的字符集。 MySQL对于字符集的指定可以细化到一…

oracle 10g WMSYS.WM_CONCAT 函數的用法

select t.rank, t.Name from t_menu_item t;10 CLARK10 KING10 MILLER20 ADAMS20 FORD20 JONES20 SCOTT20 SMITH30 ALLEN30 BLAKE30 JAMES30 MARTIN30 TURNER30 WARD-------------------------------- 我们通过 10g 所提供的 WMSYS.WM_CONCAT 函数即可以完成 行转列的效果selec…

减少Menu分割线的间距

之前看到社区中有介绍怎样灵活使用右键菜单的文章。现在积累下来右键菜单的方式还是比较多的&#xff0c;让我们来初步了解一下&#xff1a; 1. 使用flash自带的右键菜单&#xff0c;通过ContextMenu来设置&#xff0c;这是twaver最早右键菜单的解决方法&#xff0c;但这种…

TWaver图形界面之道(六)TWaver设计模式

继续上一章的TWaver图形界面之道&#xff08;五&#xff09;Hello TWaver TWaver设计模式 让我们详细探讨TWaver的设计模式&#xff0c;本章包括三个方面&#xff1a;MVC的设计模式&#xff0c;数据元素与数据容器&#xff0c;以及事件驱动机制。 什么是设计模式&#xff1f;…