2011-05-25 48 views
0

這是用於3D旋轉,如何能夠被丟棄的圖像來在畫布使用FLEX4

<s:Rotate3D id="rotate3DX" 
        target="{image}" 
        angleXFrom="0" 
        angleXTo="360" 
        duration="2000" 
        autoCenterTransform="true" /> 


    <s:Rotate3D id="rotate3DY" 
       target="{image}" 
       angleYFrom="0" 
       angleYTo="360" 
       duration="2000" 
       autoCenterTransform="true" /> 

    <s:Rotate3D id="rotate3DZ" 
       target="{image}" 
       angleZFrom="0" 
       angleZTo="360" 
       duration="2000" 
       autoCenterTransform="true" /> 

</fx:Declarations> 

代碼本爲拖動鱈魚和下降轉動

private function mouseDownHandler(event:MouseEvent):void 
      { 
       var dragInitiator:Image=Image(event.currentTarget); 
       var ds:DragSource = new DragSource(); 
       ds.addData(dragInitiator, "img"); 
       DragManager.doDrag(dragInitiator, ds, event); 

      } 

      private function dragEnterHandler(event:DragEvent):void 
      { 
       if (event.dragSource.hasFormat("img")) 
        DragManager.acceptDragDrop(Canvas(event.currentTarget)); 

      } 
      private function dropHandler(event:DragEvent):void { 
       if (event.dragSource.hasFormat("img")) { 
        var draggedImage:Image = 
         event.dragSource.dataForFormat('img') as Image; 
        var dropCanvas:Canvas = event.currentTarget as Canvas; 

        // Since this is a copy, create a new object to 
        // add to the drop target. 
        var newImage:Image=new Image(); 
        newImage.source = draggedImage.source; 
        newImage.x = dropCanvas.mouseX; 
        newImage.y = dropCanvas.mouseY; 
        newImage.height=200; 
        newImage.width=200; 
        newImage.addEventListener(MouseEvent.MOUSE_MOVE, mouseDownHandler); 
        newImage.addEventListener(DragEvent.DRAG_COMPLETE, dragCompleteHandler); 
        dropCanvas.addChild(newImage); 
        newImage.id=draggedImage.id; 
       } 
      } 


      public function button1_clickHandler(event:MouseEvent):void 
      { 
       canvas1.graphics.clear(); 
      } 
      private function dragCompleteHandler(event:DragEvent):void { 
       var draggedImage:Image = 
        event.dragInitiator as Image; 
       var dragInitCanvas:Canvas = 
        event.dragInitiator.parent as Canvas; 

       if (event.action == DragManager.MOVE) 
        dragInitCanvas.removeChild(draggedImage); 
      }   

圖像是

<mx:Panel width="216" height="349" title="Parts" color="#010101" 
         cornerRadius="10"> 
       <mx:Image source="images\8.png" 
          width="128" height="76" 
          mouseMove="mouseDownHandler(event)" 
          id="image" 


         /> 
       <mx:Image source="images\10.jpg" 
          width="110" height="87" 
          mouseMove="mouseDownHandler(event)"/> 
       <mx:Image source="images\9.jpg" 
          width="111" height="88" 
          mouseMove="mouseDownHandler(event)"/> 
      </mx:Panel> 

在其中圖像被丟棄的帆布是

 <mx:Canvas id="canvas1" 
        height="349" width="1080" 
        backgroundColor="#BFBDBD" 
        cornerRadius="10" 
        borderColor="#000000" 
        borderVisible="true" 
        dropShadowVisible="true" 
        dragEnter="dragEnterHandler(event)" 
        dragDrop="dropHandler(event)" 
        > 




      <mx:ControlBar width="100%" cornerRadius="0"> 
       <s:Button id="buttonX" 
          label="Rotate3D X-axis" 
          click="rotate3DX.play();" /> 
       <s:Button id="buttonY" 
          label="Rotate3D Y-axis" 
          click="rotate3DY.play();" /> 
       <s:Button id="bButtonZ" 
          label="Rotate3D Z-axis" 
          click="rotate3DZ.play();" /> 
      </mx:ControlBar> 

     </mx:Canvas> 

我想在將圖像放入canvas後旋轉圖像,我可以在面板中旋轉圖像。

回答

0

在這種情況下,您正在綁定效果的目標。簡單地將ID從一個組件切換到另一個組件實際上不起作用。對原始圖像的引用是實際綁定的內容。你最好用編程方式在dropHandler方法中切換效果的目標。

// DON'T DO THIS 
newImage.id=draggedImage.id; 

// DO THIS 
rotate3DY.target = newImage; 
rotate3DZ.target = newImage; 
+0

我能夠旋轉上一次放下的圖像在畫布中..現在我想從多個圖像中選擇一個圖像並旋轉該特定圖像..你能幫我解決嗎? – abc 2011-05-26 06:43:39

+0

你必須有一種方法來確定你想要選擇的圖像。例如,您可以點擊圖像並在clickHandler上設置效果的目標爲該圖像。長話短說 - 只要確定將效果上的目標設置爲您實際想要旋轉的圖像即可。 – dtuckernet 2011-05-26 14:04:20

+0

隨意投我的答案,並選擇它作爲答案。 – dtuckernet 2011-05-26 18:13:02

相關問題