2012-01-13 2 views
0

플렉스 에어 프로젝트를 만들고 있으므로 mxml 파일이 실행됩니다.
한쪽에 하나의 큰 원으로 원이 있고 다른 한쪽에 똑같을 것입니다.플렉스 프로젝트에서 하나의 컨테이너에서 다른 컨테이너로 원을 끌는 방법

큰 원에서 다른 원으로 원을 드래그하는 방법. 또는 서클이있는 두 컨테이너와 같을 수 있습니다. 그런 다음 서클을 드래그 앤 드롭하는 방법은 무엇입니까?

하나의 서클에서 드래그 앤 드롭을 할 수 있습니다.하지만 왼쪽에 하나의 큰 원과 오른쪽에 큰 원이 필요합니다. 그리고 클래스 이름이있는 작은 원이이 큰 원에 포함됩니다. 이제 그 작은 원을 큰 원으로 끌어다 놓으 려구요. 큰 싸구려가 움직여서는 안됩니다. 제발 도와주세요. 심지어 나는 액션 스크립트

package 
{ 
    import flash.display.Sprite; 
    import flash.events.MouseEvent; 
    import flash.text.engine.GroupElement; 

    public class lastWork extends Sprite 
    { 
     public function lastWork() 
     { 
      drawBigCircles(200,100,100); 
      drawBigCircles(400,280,100); 
     drawCircles(190,90,15); 
     drawCircles(180,130,15); 
     drawCircles(150,70,15); 
     drawCircles(400,240,20); 

     } 
     public function drawBigCircles(x:Number,y:Number,radius:Number):void{ 
      var circle:Sprite=new Sprite(); 
      circle.graphics.beginFill(0xFFCC00,1); 
      circle.graphics.lineStyle(1,0x666666); 


      circle.graphics.drawCircle(x,y,radius); 
      this.addChild(circle); 
      addChild(circle); 
     } 
     public function drawCircles(x:Number,y:Number,radius:Number):void 
     { 
      var group:GroupElement =new GroupElement(); 

      var circle:Sprite=new Sprite(); 
      circle.graphics.beginFill(0xFFCC00,1); 
      circle.graphics.lineStyle(1,0x666666); 


      circle.graphics.drawCircle(x,y,radius); 
      this.addChild(circle); 
      addChild(circle); 
      circle.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown) 

      function mouseDown(event:MouseEvent):void 
      { 
       circle.startDrag(); 
      } 
      circle.addEventListener(MouseEvent.MOUSE_UP, mouseReleased); 

      function mouseReleased(event:MouseEvent):void 
      { 
       circle.stopDrag(); 
       trace(circle.dropTarget.name); 
      } 
     } 

    } 
} 

에이 코드를 시도하지만 나는 큰 원이 이동하지 않아야하고 이러한 작은 circles.Small에 텍스트를 넣어하는 방법을 말해 줄 수 dragged.If 작은 원은해야합니다 텍스트가있는 원은 드래그하여 다른 큰 원으로 떨어 뜨려야합니다.

+0

드래그 앤 드롭을 할 수 있습니다.하지만 왼쪽에 하나의 큰 원과 오른쪽에 큰 원을 원합니다. 그리고 클래스 이름이있는 작은 원은 t에 있습니다. 큰 동그라미를 치고. 작은 동그라미를 드래그 앤 드롭하여 큰 동그라미에 넣고 싶습니다. 거대한 동굴이 움직여서는 안됩니다. 제발 도와주세요. –

답변

0

왜 용기가 두 개입니까? 그냥 내부의 사용자 지정 구성 요소 및 드래그 원 (코드 아래에서도 볼 수있는 모바일 Flex 프로젝트에서 작동) 작성 :

enter code here

에 MyApp.mxml :

<?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" 
    xmlns:comps="*"> 
    <comps:MyCircle width="100%" height="100%"/> 
</s:Application> 

MyCircle.mxml :

<?xml version="1.0" encoding="utf-8"?> 
<mx:UIComponent 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx" 
    width="100%" height="100%"> 

    <fx:Script> 
     <![CDATA[ 
      import flash.filters.*; 

      public static const SHADOW:Array = [ new DropShadowFilter(10, 80, 0x000000, 0.5, 32, 32, 1, 1, false, false, false) ]; 
      private var dX:Number, dY:Number; 
      private var circle:Shape = new Shape(); 

      override protected function createChildren():void { 
       super.createChildren(); 

       circle.graphics.beginFill(0xFF0000); 
       circle.graphics.drawCircle(0, 0, 20); 
       addChild(circle); 

       addEventListener(MouseEvent.MOUSE_DOWN, handleDown); 
      } 

      override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void { 
       super.updateDisplayList(unscaledWidth, unscaledHeight); 

       circle.x = unscaledWidth/2; 
       circle.y = unscaledHeight/2; 
      } 

      private function handleDown(event:MouseEvent):void { 
       dX = circle.x - stage.mouseX; 
       dY = circle.y - stage.mouseY; 
       circle.scaleX = circle.scaleY = 1.5; 
       circle.filters = SHADOW; 
       //startDrag(); 
       stage.addEventListener(MouseEvent.MOUSE_MOVE, handleDrag); 
       stage.addEventListener(MouseEvent.MOUSE_UP, handleUp); 
      } 

      private function handleDrag(event:MouseEvent):void { 
       circle.x = stage.mouseX + dX; 
       circle.y = stage.mouseY + dY; 
       event.updateAfterEvent(); 
      } 

      private function handleUp(event:MouseEvent):void { 
       circle.filters = null; 
       circle.scaleX = circle.scaleY = 1; 
       //stopDrag(); 
       stage.removeEventListener(MouseEvent.MOUSE_MOVE, handleDrag); 
       stage.removeEventListener(MouseEvent.MOUSE_UP, handleUp); 
      } 

     ]]> 
    </fx:Script> 
</mx:UIComponent> 
관련 문제