# Move an object with scripts

**URL:** <https://forum.kirupa.com/t/move-an-object-with-scripts/208751>\
**Category:** Uncategorized\
**Created:** [December 1, 2006, 11:38pm UTC](https://forum.kirupa.com/t/move-an-object-with-scripts/208751 "2006-12-01T23:38:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dennis\_gull](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@Dennis\_gull](https://forum.kirupa.com/u/Dennis_gull)\
**Post date:** [December 1, 2006, 11:38pm UTC](https://forum.kirupa.com/t/move-an-object-with-scripts/208751/1 "2006-12-01T23:38:30Z")

</div>

Hello,

I got an instance I wanna move when clicking the background… and I want it to move to the place I click, Its for my volume bar. At the moment you can drag the volume instance but if you click on the background you wont go there…

This is how the code looks like now:

```auto

var music:Sound = new Sound(vSound); 
 
// initial x position fo the dragger 
mp3Player.dragger._x = mp3Player.line_mc._x+mp3Player.line_mc._width+3; 
mp3Player.dragger.onPress = function() { 
   this.startDrag(false, mp3Player.line_mc._x, this._y, mp3Player.line_mc._width+mp3Player.line_mc._x+3, this._y); 
   // drag function for the volume slider 
   this.onEnterFrame = function() { 
      Volume = _root.mp3Player.dragger._x-_root.mp3Player.line_mc._x; 
      // set the volume variable 
      music.setVolume(Volume); 
      // set volume 
   }; 
}; 
mp3Player.dragger.onRelease = mp3Player.dragger.onReleaseOutside=function () { 
   this.stopDrag(); 
   delete this.onEnterFrame; 
}; 
 
      startVolume = 30; // use the start volume variable and set it to 50 
      _root.mp3Player.dragger._x = _root.mp3Player.line_mc._x + startVolume; // set the dragger x position equal to the startVolume 
      this.music.setVolume(startVolume); // set the volume of the sound object 

```

Dragger is the actual volume bar and line\_mc is the background, This is how the player looks like now
