# \[Help\] Inertia, elasticity

**URL:** <https://forum.kirupa.com/t/help-inertia-elasticity/329578>\
**Category:** flash\
**Created:** [September 17, 2012, 2:32pm UTC](https://forum.kirupa.com/t/help-inertia-elasticity/329578 "2012-09-17T14:32:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kurtz](https://avatars.discourse-cdn.com/v4/letter/k/97f17d/32.png) [@Kurtz](https://forum.kirupa.com/u/Kurtz)\
**Post date:** [September 17, 2012, 2:32pm UTC](https://forum.kirupa.com/t/help-inertia-elasticity/329578/1 "2012-09-17T14:32:06Z")

</div>

Hi All,

[COLOR=#333333]I’m trying to build something similar to Oxylus ([http://www.oxylusflash.com/flashfiles/easy-before-and-after-photo-mask-as3](http://www.oxylusflash.com/flashfiles/easy-before-and-after-photo-mask-as3)) to display before/after images.

[/COLOR]  
[COLOR=#333333]What I like of this “slider” is the “inertia”, “elasticity” that has. The code of Oxylus works with a lot of “external” files. I’m trying to get to someghing similar but embeed in a single swf movie. [/COLOR]  
[COLOR=#333333]  
[/COLOR]  
[COLOR=#333333]This is the code I have so far, but there’s no elasticity or inertia in the slider. Could someone help to add that physic property to this code?

[/COLOR]  
[HR][/HR]

> 

[COLOR=#333333]var \_before:Bitmap = new Bitmap(new Before(0,0));[/COLOR]  
[COLOR=#333333]var \_after:Bitmap = new Bitmap(new After(0,0));[/COLOR]  
[COLOR=#333333]var \_slider:Slidebar = new Slidebar();[/COLOR]  
[COLOR=#333333]var \_mask:Sprite = new Sprite();[/COLOR]  
[COLOR=#333333]  
[/COLOR]  
[COLOR=#333333]  
[/COLOR]  
[COLOR=#333333]function Init() : void [/COLOR]  
[COLOR=#333333]{ [/COLOR]  
[COLOR=#333333] \_mask.graphics.beginFill(0x000000);[/COLOR]  
[COLOR=#333333] \_mask.graphics.drawRect(0,0,1280,962);[/COLOR]  
[COLOR=#333333] \_mask.graphics.endFill();[/COLOR]

[COLOR=#333333] addChild(\_mask);[/COLOR]  
[COLOR=#333333]  
[/COLOR]  
[COLOR=#333333] \_after.mask = \_mask;[/COLOR]  
[COLOR=#333333]  
[/COLOR]  
[COLOR=#333333] addChild(\_before);[/COLOR]  
[COLOR=#333333] addChild(\_after);[/COLOR]  
[COLOR=#333333] addChild(\_slider);[/COLOR]

[COLOR=#333333] \_slider.x = 640;[/COLOR]  
[COLOR=#333333] \_mask.x = \_slider.x;[/COLOR]  
[COLOR=#333333] \_slider.y = 481;[/COLOR]  
[COLOR=#333333]  
[/COLOR]  
[COLOR=#333333]  
[/COLOR]  
[COLOR=#333333] \_slider.buttonMode = true; [/COLOR]  
[COLOR=#333333] \_slider.addEventListener(MouseEvent.MOUSE\_DOWN, SlidebarEvents, false, 0, true); [/COLOR]

[COLOR=#333333] stage.addEventListener(MouseEvent.MOUSE\_UP, StopEvents, false, 0, true); [/COLOR]

[COLOR=#333333]} [/COLOR]

[COLOR=#333333]function SlidebarEvents($e:MouseEvent):void[/COLOR]  
[COLOR=#333333]{ [/COLOR]  
[COLOR=#333333] stage.addEventListener(MouseEvent.MOUSE\_MOVE, Move, false, 0, true);[/COLOR]  
[COLOR=#333333]} [/COLOR]

[COLOR=#333333]function StopEvents($e:MouseEvent):void[/COLOR]  
[COLOR=#333333]{ [/COLOR]  
[COLOR=#333333] stage.removeEventListener(MouseEvent.MOUSE\_MOVE,Move);[/COLOR]  
[COLOR=#333333]}[/COLOR]

[COLOR=#333333]function Move(event:MouseEvent):void[/COLOR]  
[COLOR=#333333]{[/COLOR]  
[COLOR=#333333] \_slider.x = mouseX;[/COLOR]  
[COLOR=#333333] if (\_slider.x \> stage.stageWidth){[/COLOR]  
[COLOR=#333333] \_slider.x = stage.stageWidth;[/COLOR]  
[COLOR=#333333] }[/COLOR]  
[COLOR=#333333] else if(\_slider.x \< 0){[/COLOR]  
[COLOR=#333333] \_slider.x = 0;[/COLOR]  
[COLOR=#333333] }[/COLOR]

[COLOR=#333333] \_mask.x = \_slider.x;[/COLOR]  
[COLOR=#333333]}[/COLOR]  
[COLOR=#333333]  
[/COLOR]  
[COLOR=#333333][FONT=Courier]Init();  
[/FONT][/COLOR]

[HR][/HR]

Thanks in advance!
