`
demojava
  • 浏览: 540514 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

flex drag

 
阅读更多

flex3 Drag
Drag 常用的方法
1.系统startDrag,stopDrag(适合单个拖拽)
2.Move()(适合多个拖拽)
3.DragManager  (有默认的特效)
1.单个拖拽

private function mouseDownHandler():void{
	demo.startDrag();
}

private function mouseUpHandler():void{
	demo.stopDrag();
}
<mx:Button  id="demo" mouseDown="mouseDownHandler()" 
mouseUp="mouseUpHandler()" />


2.拖拽区域限制



 

private function mouseDownHandler():void{
	demo.startDrag(false,new Rectangle(0,0,can1.width-demo.width,can1.height-demo.height));
}



3.拖拽多个原理:把需要拖拽的对象放入一个 容器中拖拽这个容器

private function mouseDownHandler():void{
	cv2.startDrag();
}

private function mouseUpHandler():void{
	cv2.stopDrag();
}
	<mx:Canvas id="cv1" width="544" height="324" backgroundColor="#FFFFFF">
		<mx:Canvas id="cv2" x="0" y="39" width="197" height="159" verticalScrollPolicy="off" horizontalScrollPolicy="off" 
			backgroundColor="green" buttonMode="true" 
			mouseDown="mouseDownHandler()" mouseUp="mouseUpHandler()">
			<mx:Button id="demo" label="demo" x="10" y="38"/>
			<mx:Button label="demo" x="76" y="60"/>
			<mx:Button label="demo" x="28" y="90"/>
		</mx:Canvas>
	</mx:Canvas>


4.拖拽多个控制拖拽区域(容器中x轴最小,最大的元素,y轴最大最小的元素)

 

<mx:Script>
	<![CDATA[
		import mx.core.UIComponent;
		import mx.events.MoveEvent;
		private var maxXObj:Number;
		private var minXObj:Number;
		private var maxYObj:Number;
		private var minYObj:Number;
		private var tempArrayX:Array;
		private var tempArrayY:Array;
		private function mouseDownHandler():void{
			this.cv2.startDrag();
			tempArrayX=new Array(cv2.numChildren);
			tempArrayY=new Array(cv2.numChildren);
			for(var i:int;i<cv2.numChildren;i++)
			{
				var child:UIComponent= cv2.getChildAt(i) as UIComponent;
				tempArrayX[i]=child.x;
				tempArrayY[i]=child.y;
			}
				tempArrayX.sort(Array.NUMERIC);
				tempArrayY.sort(Array.NUMERIC);
				maxXObj=tempArrayX[tempArrayX.length-1];
				minXObj=tempArrayX[0];
				maxYObj=tempArrayY[tempArrayY.length-1];
				minYObj=tempArrayY[0];
			this.addEventListener(MouseEvent.MOUSE_MOVE,moveHandler);
			
		}
		private function mouseUpHandler():void{
			this.removeEventListener(MouseEvent.MOUSE_MOVE,moveHandler);
				if(cv2.x<(0-minXObj))//最左边
			{
				this.cv2.x =(0-minXObj);
			}
			var temp1:Number=cv2.width-(maxXObj+demo.width);
			if(cv2.x>=this.width-(cv2.width-temp1))//最上面
			{
				cv2.x=this.width-(cv2.width-temp1);
			}
			if(this.cv2.y <= (0-minYObj)){
				this.cv2.y = (0-minYObj);
			}
			var temp2:Number=cv2.height-(maxYObj+demo.height);
			if(this.cv2.y >=this.height-(cv2.height-temp2)){//最上面
				cv2.y=this.height-(cv2.height-temp2);
			}
				this.cv2.stopDrag();
		}
		
		private function moveHandler(event:MouseEvent):void{
			if(cv2.x<(0-minXObj))//最左边
			{
				this.cv2.x =(0-minXObj);
				this.cv2.stopDrag();
			}
			var temp1:Number=cv2.width-(maxXObj+demo.width);
			if(cv2.x>=this.width-(cv2.width-temp1))//最上面
			{
				cv2.x=this.width-(cv2.width-temp1);
				this.cv2.stopDrag();
			}
			if(this.cv2.y <= (0-minYObj)){//最上面
				this.cv2.y = (0-minYObj);
				this.cv2.stopDrag();
			}
			var temp2:Number=cv2.height-(maxYObj+demo.height);
			if(this.cv2.y >=this.height-(cv2.height-temp2)){//最下面
				cv2.y=this.height-(cv2.height-temp2);
				this.cv2.stopDrag();
			}
		}
	]]>
</mx:Script>
		<mx:Canvas id="cv2" x="0" y="39" width="197" height="159" verticalScrollPolicy="off" horizontalScrollPolicy="off" 
		backgroundColor="green" buttonMode="true" 
		mouseDown="mouseDownHandler()" mouseUp="mouseUpHandler()">
		<mx:Button id="demo" label="demo" x="10" y="38"/>
		<mx:Button label="demo" x="76" y="60"/>
		<mx:Button label="demo" x="28" y="90"/>
	</mx:Canvas>


5.Move()方法控制



 

  <?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
   <mx:Script>
        <![CDATA[
            import mx.core.UIComponent;
            private var regX:Number;
            private var regY:Number;
            public var closeButton : UIComponent;
            protected function startDragging(event : MouseEvent) : void
            {
                regX = event.stageX - demo.x;
                regY = event.stageY - demo.y;
                systemManager.addEventListener(
                    MouseEvent.MOUSE_MOVE, systemManager_mouseMoveHandler, true);
                systemManager.addEventListener(
                    MouseEvent.MOUSE_UP, systemManager_mouseUpHandler, true);
                systemManager.stage.addEventListener(
                    Event.MOUSE_LEAVE, stage_mouseLeaveHandler); 
            }
            protected function stopDragging() : void
            {
                systemManager.removeEventListener(
                    MouseEvent.MOUSE_MOVE, systemManager_mouseMoveHandler, true);
        
                systemManager.removeEventListener(
                    MouseEvent.MOUSE_UP, systemManager_mouseUpHandler, true);
        
                /* systemManager.stage.removeEventListener(
                    Event.MOUSE_LEAVE, stage_mouseLeaveHandler); */
        
                regX = NaN;
                regY = NaN;
            }
            /**
             *  @private
             */
            private function titleBar_mouseDownHandler(event:MouseEvent) : void
            {
                    startDragging(event);
            }
             var tempx:Number;
             var tempy:Number;
            private function systemManager_mouseMoveHandler(event:MouseEvent) : void
            {
                event.stopImmediatePropagation();
                tempx=event.stageX - regX;
                tempy=event.stageY - regY;
                if(tempx<0)
                {
                 tempx=0; 
                }
                if(tempx>this.width-demo.width)
                {
                 tempx=this.width-demo.width;
                }
                if(tempy<0)
                {
                 tempy=0; 
                }
                if(tempy>this.height-demo.height)
                {
                 tempy=this.height-demo.height; 
                }
                demo.move(tempx,tempy);
            }
            private function systemManager_mouseUpHandler(event:MouseEvent) : void
            {
                if (!isNaN(regX))
                    stopDragging();
            }
            private function stage_mouseLeaveHandler(event:Event) : void
            {
                if (!isNaN(regX))
                    stopDragging();
            }
        ]]>
    </mx:Script>
<mx:HBox id="demo"  backgroundColor="green" mouseDown="{titleBar_mouseDownHandler(event)}" width="141" height="147" x="282" y="156">
</mx:HBox>
</mx:Application>



6.使用DragManager拖拽
DragManager参考连接:
http://demojava.iteye.com/blog/1183448

 

  • 大小: 3.5 KB
  • 大小: 5.3 KB
  • 大小: 4.4 KB
分享到:
评论

相关推荐

    flex 拖拽的例子

    flex 练习拖拽的例子,很简单,可以了解一下原理

    Flex3+组件拖放教程

    Flex3组件拖放教程,该组件是flex组件中最有特色的

    flex支持拖拽的DataGrid

    flex支持拖拽的DataGrid,如果去查api来置一些属性将会比较麻烦,这个DataGrid可以获取拖拽的内容,这是一个application,可以直接运行

    Flex 3 拖放实现

    Flex 3 实现的拖放示例,很简单,可以移植到自己的程序中,Web形式和AIR形式都可以使用。

    Flex拖拽

    介绍Flex 拖拽的事件机制和用法。

    flex窗口最大最小化

    flex实现窗口的拖拽,最大化,最小化,关闭。

    《Flex设计师基础》[PDF]

    Introduction ...Chapter 9 Flex Video Gallery with Drag-and-Drop Chapter 10 Exploring Flex Charting Chapter 11 Creating Forms: The “Will Flex for Food” Registration Page Chapter 12 Flex and AIR

    flex objecthandles一个很不错的拖拽伸缩控件

    flex中一个很不错的拖拉伸缩组件,适合新人学习的组件....

    Flex3组件拖放教程

    处理list-based控件的拖放事件 13 运行在AIR中的Flex应用程序的拖放 16 拖放实例 17 例子1:用Canvas作为drop target 17 例子2:指定drag proxy 18 例子3:为drop target处理dragOver和dragExit事件 ...

    flex漂亮MP3播放器源码

    flex漂亮MP3播放器源码,结合flash、CSS等制作精美皮肤…… 具有一般的mp3播放、声音调节、进度条、3种频谱显示方式,内带flash素材源文件…… Drag.as通用拖动源代码…… Visualization Explorer……

    Amethyst 开发flex 的 vs 插件

    Amethyst is a fully-featured Visual ... Amethyst supports the drag-and-drop design, editing and debugging of Flex and AIR applications and it can also load Flash IDE projects for editing and debugging.

    flex中拖拉拽好实例objecthandles

    一个关于flex中,拖拉拽的控件实例,源码也是摘录的,自己多参谋下大师之作,最后面咱自己写项目,帮助很大

    flex3的cookbook书籍完整版dpf(包含目录)

    使用本地拖拽(Drag-and-Drop)API 23.11节.与操作系统剪贴板交互 23.12节.添加HTML内容 23.13节.在ActionScript和JavaScript之间跨脚本操作 23.14节.本地SQL数据库 23.15节.检测和监控网络连接 23.16节.检测用户是否...

    Developing Flex Applications 910p dda_doc88_cracker.zip

    1. a book Developing Flex Applications 2. a web page viewer for doc88 ebt 3. a DDA downloader for doc88.com CONTENTS PART I: Presenting Flex CHAPTER 1: Introducing Flex. . . . . . . . . . . . . . ...

    FlexLayout:多标签版式管理器

    FlexLayout FlexLayout是一个布局管理器,用于将React组件布置在多个选项卡集中,可以调整和移动选项卡的大小。现在使用尝试FlexLayout唯一的依赖关系是React。 特征: 分离器标签标签拖动和排序拖动选项卡集(一次...

    Flex_DragDrop

    提供: Flex中图片组件的拖放实现实例源码 后续还有 表格数据 等组件的拖放实例

    flash 拖动 购物车 例子 + 源碼

    http://files.riacodes.com/flex_drag-drop-gift-cart/demo/ 示範地址

    topo__image

    flex 对图片的一些操作,loader ,drag

    flex简单拖拽

    某控件在某一固定大小的区域内的拖拽以及拉伸

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    - FIX: When the curve contain more then one figure and they were all unconfined and curve have alternative brush then whole flex-object bounding rectangle was filed. - FIX: The MaskColor property ...

Global site tag (gtag.js) - Google Analytics