# Beginner needs help with tweens

**URL:** https://forum.kirupa.com/t/beginner-needs-help-with-tweens/288946
**Category:** flash
**Created:** [May 23, 2009, 6:38pm UTC](https://forum.kirupa.com/t/beginner-needs-help-with-tweens/288946 "2009-05-23T18:38:59Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![davidtidwell86](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@davidtidwell86](https://forum.kirupa.com/u/davidtidwell86)
#### Post date: [May 23, 2009, 6:38pm UTC](https://forum.kirupa.com/t/beginner-needs-help-with-tweens/288946/1 "2009-05-23T18:38:59Z")

</div>

Hello, I’m having issues with this simple program I made. There’s two rectangles, a holder and a dragger. When you click the dragger, you can drag it until you mouse\_up and it will return back to the position of the holder via tweens. It works fine, if you give enough time for the tween to fully take action and let it return to its proper place, but if you reclick it before it’s finished, the dragger gets stuck and misaligned. Here’s the code I have so far, thank you so much! :bounce:

```auto

package
{
    import flash.display.*;
    import flash.events.*;
    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    import fl.transitions.TweenEvent;
    
    public class script extends MovieClip
    
    {
        public var mcRectangleDragger:MovieClip = new MovieClip( );
        public var mcRectangleHolder:MovieClip = new MovieClip( );
        
        public var twnMoveX:Tween;
        public var twnMoveY:Tween;
        
        public function script( )
        {
            mcRectangleHolder.graphics.lineStyle( 1 );
            mcRectangleHolder.graphics.beginFill( 0x0000FF );
            mcRectangleHolder.graphics.drawRect( 100, 100, 150, 100 );
            mcRectangleHolder.graphics.endFill( );
            
            mcRectangleDragger.graphics.lineStyle( 1 );
            mcRectangleDragger.graphics.beginFill( 0xFF0000 );
            mcRectangleDragger.graphics.drawRect( 100, 100, 150, 100 );
            mcRectangleDragger.graphics.endFill( );
            mcRectangleDragger.addEventListener( MouseEvent.MOUSE_DOWN, rectangleEventDrag_handler );
            this.addEventListener( MouseEvent.MOUSE_UP, mouseUp_handler );
            //
            this.addChild(mcRectangleHolder);
            this.addChild(mcRectangleDragger);
        }
        
        private function rectangleEventDrag_handler( e:Event ):void
        {
            mcRectangleDragger.startDrag( );
        }
        
        private function mouseUp_handler( e:Event ):void
        {
            mcRectangleDragger.stopDrag( );
            
            twnMoveX = new Tween( mcRectangleDragger, "x", Strong.easeOut, mcRectangleDragger.x, mcRectangleHolder.x, 1.0, true );
            twnMoveY = new Tween( mcRectangleDragger, "y", Strong.easeOut, mcRectangleDragger.y, mcRectangleHolder.y, 1.0, true );
            
            twnMoveX.addEventListener( TweenEvent.MOTION_STOP, tweenStop_handler );
        }
        
        private function tweenStop_handler( e:TweenEvent ):void
        {
            trace( "finished" );
        }
    }
}

```
