2 Replies Latest reply on Nov 26, 2007 12:37 PM by ChristopherCesarz

    How to make it move correctly?

    nmduc073

      I made a simple Flex application. There is a helicopter which will move to points that user clicks in the canvas. For example, it is at A point. When I click at B point, the helicopter will move to B. Then it will move to C when I click at C.

      However, the problem arises when I click at B, C, D continuously. It moved from A to B. However, I don't think it moved from B to C. Maybe it moved from B' to C.

      Please tell me how to make it move correctly.

      [CODE]
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
      <mx:Script>
      <![CDATA[
      import flash.events.Event;
      import mx.controls.Alert;

      [Embed(source="library.swf", symbol="Helicopter")]
      public var MayBay:Class;

      [Bindable]
      public var xF:Number;
      [Bindable]
      public var xT:Number;
      [Bindable]
      public var yF:Number;
      [Bindable]
      public var yT:Number;

      public function onCanvasClick(event:Event):void
      {
      var x:Number= myCanvas.mouseX;
      var y:Number= myCanvas.mouseY;

      var oX:Number=h1.x;
      var oY:Number=h1.y;

      xF=oX;
      yF=oY;
      xT=x;
      yT=y;

      MoveEffect.play();
      // Alert.show("x="+x+" y="+y+" xOld="+oX+" yOld="+oY);

      }

      ]]>
      </mx:Script>
      <mx:Move id="MoveEffect" target="{h1}" xFrom="{xF}" yFrom="{yF}" xTo="{xT}" yTo="{yT}" duration="2000" >

      </mx:Move>
      <mx:states>
      <mx:State id="NewState">

      </mx:State>
      </mx:states>
      <mx:Panel width="70%" height="50%" title="Vi du">
      <mx:Canvas click="onCanvasClick(event)" id="myCanvas" width="100%" height="100%" color="White">
      <mx:Image id="h1" source="{MayBay}" width="80" height="50">
      </mx:Image>
      </mx:Canvas>
      </mx:Panel>
      </mx:Application>

      [/CODE]