# Drag and throw scroll. please help me

**URL:** https://forum.kirupa.com/t/drag-and-throw-scroll-please-help-me/327386
**Category:** Uncategorized
**Created:** [February 26, 2012, 8:51am UTC](https://forum.kirupa.com/t/drag-and-throw-scroll-please-help-me/327386 "2012-02-26T08:51:00Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Mochashu](https://avatars.discourse-cdn.com/v4/letter/m/9f8e36/32.png) [@Mochashu](https://forum.kirupa.com/u/Mochashu)
#### Post date: [February 26, 2012, 8:51am UTC](https://forum.kirupa.com/t/drag-and-throw-scroll-please-help-me/327386/1 "2012-02-26T08:51:00Z")

</div>

I might not write English well because I’m an Asian. and I have some problem about my project.  
I am just a beginner.

I saw Flash on website in Thailand.  
this!!  
[http://79room.net/throwMe\_step4.swf](http://79room.net/throwMe_step4.swf)

But it used Actionscript 2.0

```auto
content.setMask(mcMask);

content.onPress = function()
{
     var left = mcMask._x+(mcMask._width-this._width);
     var top = mcMask._y;
     var right = mcMask._x;
     var bottom = mcMask._y;
     this.startDrag(false,left,top,right,bottom);
     this.oldMouseX = _xmouse;
     this.onEnterFrame = findDelta;
}

content.onRelease = content.onReleaseOutside = function()
{
     this.stopDrag();
     this.onEnterFrame = slowDown;
}

function findDelta()
{
     this.deltaX = (_xmouse - this.oldMouseX)*10;
     this.oldMouseX = _xmouse
}

function slowDown()
{
     if(this._x + this.deltaX > mcMask._x)
          this.deltaX = mcMask._x - this._x;
     if(this._x + this.deltaX < mcMask._x+mcMask._width-this._width)
          this.deltaX = mcMask._x+mcMask._width-this._width-this._x;
     if(Math.abs(this.deltaX * 0.8) > 0.1)
     {
          this._x+=this.deltaX*0.2;
          this.deltaX*=0.8;
     }
     else
          delete this.onEnterFrame;
}

```

I would like to do this project by Actionscript 3.0  
And this is code as3

```auto
import flash.events.MouseEvent;
import flash.events.Event;

var Left:int = McMask.x + (McMask.width - Rectant.width);
var Top = McMask.y;
var Right = McMask.x;
var Bottom = McMask.y;
var rectangle:Rectangle = new Rectangle(Right,Bottom,Left,Top);
var oldMouseX:int;
var deltaX:int;
Rectant.mask = McMask;

Rectant.addEventListener(MouseEvent.MOUSE_DOWN, RectantDown);
function RectantDown(event:MouseEvent):void
{
    Rectant.addEventListener(MouseEvent.MOUSE_UP, RectantUp);
    Rectant.removeEventListener(MouseEvent.MOUSE_DOWN, RectantDown);
    Rectant.startDrag(false,rectangle);

    oldMouseX = mouseX;
    Rectant.addEventListener(Event.ENTER_FRAME, RectantMove);
}
function RectantUp(event:MouseEvent):void
{
    Rectant.addEventListener(MouseEvent.MOUSE_DOWN, RectantDown);
    Rectant.removeEventListener(MouseEvent.MOUSE_UP, RectantUp);
    Rectant.stopDrag();

    Rectant.removeEventListener(Event.ENTER_FRAME, RectantMove);
    Rectant.addEventListener(Event.ENTER_FRAME, onSlowDown);
}
function RectantMove(event:Event):void
{
    deltaX = mouseX - oldMouseX;
    oldMouseX = mouseX;
}
function onSlowDown(event:Event):void
{
    if (Rectant.x + deltaX > McMask.x)
    {
        deltaX = McMask.x - Rectant.x;
    }
    if (Rectant.x + deltaX < McMask.x + McMask.width - Rectant.width)
    {
        deltaX = McMask.x + McMask.width - Rectant.width - Rectant.x;
    }
    if (Math.abs(deltaX * 1) > 0.1)
    {
        Rectant.x += deltaX * 0.2;
        deltaX *= 1;
    }
    else
    {
        removeEventListener(Event.ENTER_FRAME, onSlowDown);
    }
}

```

And this is my project.

[http://79room.net/TestThrow.swf](http://79room.net/TestThrow.swf)

But it’s not work!!! it’s not looks like original project.  
please tell me. How can I solve it? and explain to me please.

Thank you very much!!🙂
