加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

FB4 元素拖动

发布时间:2020-12-15 04:00:43 所属栏目:百科 来源:网络整理
导读:?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" minWidth="955" minHeight="600" creationComplete="createbutton(
<?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" minWidth="955" minHeight="600" creationComplete="createbutton()">
	<s:layout>
		<s:BasicLayout/>
	</s:layout>
	<fx:Script>
		<![CDATA[
			import flash.events.*;
			import flash.net.FileReference;
			import flash.system.Capabilities;
			 
			import mx.collections.ArrayCollection;
			import mx.core.IVisualElement;
			import mx.events.DragEvent;
			import mx.events.MoveEvent;
			private var mouseDownPosition:Point=null;
			private var componentBag:Dictionary=new Dictionary();
			private function butto(setid:String,prom:String):void
			{
				var tempbutton:Button=new Button;
				tempbutton.id=setid;
				tempbutton.x=50;
				tempbutton.y=90;
				tempbutton.label=prom;
				tempbutton.width=137;
				tempbutton.height=46;
				tempbutton.setStyle("color","#F9F9F9");
				tempbutton.setStyle("chromeColor","#F51302");
				tempbutton.setStyle("fontWeight","bold");
				tempbutton.addEventListener(MouseEvent.MOUSE_DOWN,function ():void {
					
					//tempbutton.depth=0;
					tempbutton.addEventListener(MouseEvent.MOUSE_MOVE,MoveLocation);
				
					//componentMouseDownHandler(e);
					
				});
				
				tempbutton.addEventListener(MouseEvent.MOUSE_UP,function ():void {
					
					
					
					tempbutton.removeEventListener(MouseEvent.MOUSE_MOVE,MoveLocation);
					
					
					
					
					
				}
				
				
				
				);
				
				
				
				tempbutton.addEventListener(MouseEvent.MOUSE_DOWN,componentMouseDownHandler);
					
					
					
		
				
				
				this.addElement(tempbutton);
				//sb.addElement(tempbutton);
				componentBag[setid]=tempbutton;
			}
			
			private function MoveLocation(e:MouseEvent):void {
				//this.setChildIndex(e.currentTarget.id,this.numAutomationChildren-1);
				
				
				//Alert.show(e.currentTarget.id.toString());
			//	componentBag[e.currentTarget.id].x=this.contentMouseX-componentBag[e.currentTarget.id].width/2;
				//componentBag[e.currentTarget.id].y=this.contentMouseY-componentBag[e.currentTarget.id].height/2;
				
				//componentBag[e.currentTarget.id].x=this.contentMouseX-(e.localX-componentBag[e.currentTarget.id].x);
				//componentBag[e.currentTarget.id].y=this.contentMouseY-(e.localY-componentBag[e.currentTarget.id].y);
				//			//var a:int=this.numElements
				
					componentBag[e.currentTarget.id].x=this.contentMouseX-transation_x;
				componentBag[e.currentTarget.id].y=this.contentMouseY-transation_y;
				
				
				this.setElementIndex(e.currentTarget as IVisualElement,this.numElements-1);  
			}
			
			
			public var transation_x:int;
			public var transation_y:int;
			
			
			public function componentMouseDownHandler(e:MouseEvent):void
				
			{
				transation_x=this.contentMouseX-componentBag[e.currentTarget.id].x;
				
				transation_y=this.contentMouseY-componentBag[e.currentTarget.id].y;
			}

			
			
			
			
			
			
			
			
			public var testdata:ArrayCollection=new ArrayCollection([
				{id:'1',process:'ICT Test1',resx:'100',resy:'290',limit:'90'},{id:'2',process:'ICT Test2',resx:'140',resy:'230',{id:'3',process:'ICT Test3',resx:'150',resy:'380',{id:'4',process:'ICT Test4',resx:'200',resy:'270',{id:'5',process:'ICT Test5',resx:'510',resy:'200',{id:'6',process:'ICT Test6',resx:'400',resy:'410',{id:'7',process:'ICT Test7',resx:'190',resy:'300',{id:'8',process:'ICT Test8',resx:'330',resy:'320',limit:'90'}
				
				
			]);
			
			
			private function createbutton():void
			{
				
				var tempbutton1:Button=new Button;
				tempbutton1.id="sdfsdf";
				
				tempbutton1.label="test1234";
				tempbutton1.width=137;
				tempbutton1.height=46;
				tempbutton1.setStyle("color","#F9F9F9");
				tempbutton1.setStyle("chromeColor","#F51302");
				tempbutton1.setStyle("fontWeight","bold");
				test11.addElement(tempbutton1);
				//test11.removeElement(tempbutton1);
				for(var i:int = 0; i <testdata.length ; i++) {
					butto(testdata[i].id,testdata[i].process);	
				}
				
			}
			
		]]>
	</fx:Script>
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
	</fx:Declarations>
	<s:Button x="110" y="244" label="按钮test" width="83" height="42" />
	<s:Label x="124" y="534" width="413" height="118" text="标签"/>
	<s:Panel x="19" y="10" width="100%" height="118">
	</s:Panel>
	<s:TitleWindow x="258" y="244" width="250" height="200" id="test11">
	</s:TitleWindow>
</s:Application>
并不是Data拖动,动态创建无素后,拖动各元素

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读