:: 首頁 :: 新隨筆 ::  :: 聚合  :: 管理

          圖形拖動(一)副本的方式

          Posted on 2012-10-20 14:40 誰用我名字啦? 閱讀(187) 評論(0)  編輯  收藏 所屬分類: flex學習之路
          <?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">
              
          <fx:Script>
                  
          <![CDATA[
                      import mx.controls.*;
                      import mx.core.IVisualElement;
                      import mx.core.UIComponent;
                      import mx.graphics.ImageSnapshot;  
                      
                      [Embed(source="E:/flex/45.png")]
                      [Bindable]
                      private var bookImage:Class;
                      
                      public var uiComponent:Object;
                      public var targetImage:Object;
                      public var Ax:int = 0;
                      public var Ay:int = 0;
                      public function mouseDown(event:MouseEvent):void{
                          //在原地生成圖片副本,然后將移動圖片。  
                          this.uiComponent = event.currentTarget;
                          //生成圖片  
                          var bd:BitmapData = ImageSnapshot.captureBitmapData( UIComponent( uiComponent ) );  
                          targetImage = new Image();   
                          targetImage.source = new Bitmap(bd);  
                          targetImage.x = uiComponent.x;  
                          targetImage.y = uiComponent.y;  
                          Ax = event.localX;  
                          Ay = event.localY;  
                          this.addEventListener(MouseEvent.MOUSE_MOVE, mouseMove);  
                          this.addEventListener(MouseEvent.MOUSE_UP, mouseUp);
                          this.addElement(targetImage as IVisualElement);// as DisplayObject
                      }  
                      
                      public function mouseMove(event:MouseEvent):void{  
                          targetImage.x = event.stageX-Ax;  
                          targetImage.y = event.stageY-Ay;  
                      }  
                      
                      public function mouseUp(event:MouseEvent):void{  
                          this.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMove);  
                          this.removeEventListener(MouseEvent.MOUSE_UP, mouseUp);  
                          
                          //當鼠標移動到預定位置,將圖片刪除,并且移動源控件。  
                          uiComponent.x = event.stageX-Ax;  
                          uiComponent.y = event.stageY-Ay;  
                          this.removeElement(targetImage as IVisualElement);  
                          targetImage = null;  
                          
                      }  
                  
          ]]>
              
          </fx:Script>
              
          <mx:Image x="331" y="127" source="{bookImage}" mouseDown="mouseDown(event)"/>
              
          </s:Application>
          主站蜘蛛池模板: 新密市| 瑞金市| 诏安县| 屯留县| 合川市| 甘孜| 湘阴县| 龙陵县| 白河县| 漾濞| 泸定县| 射洪县| 洛宁县| 章丘市| 荣成市| 泰顺县| 库车县| 丰宁| 翁源县| 金阳县| 淄博市| 泸水县| 神木县| 桓仁| 丰顺县| 外汇| 蓝田县| 前郭尔| 客服| 义乌市| 民勤县| 甘洛县| 时尚| 朔州市| 石首市| 大安市| 明溪县| 鄄城县| 白河县| 武山县| 连云港市|