# How to make several dragable objects in the gravity tutorial?

**URL:** <https://forum.kirupa.com/t/how-to-make-several-dragable-objects-in-the-gravity-tutorial/278073>\
**Category:** Uncategorized\
**Created:** [December 21, 2008, 9:10pm UTC](https://forum.kirupa.com/t/how-to-make-several-dragable-objects-in-the-gravity-tutorial/278073 "2008-12-21T21:10:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![antonigeno](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@antonigeno](https://forum.kirupa.com/u/antonigeno)\
**Post date:** [December 21, 2008, 9:10pm UTC](https://forum.kirupa.com/t/how-to-make-several-dragable-objects-in-the-gravity-tutorial/278073/1 "2008-12-21T21:10:46Z")

</div>

Hello all  
First all please forgive my poor english.

I’m very new to actionscript, but i have some notions of java programming  
on a semester I had couple years ago.

I’m a graphic design student. I’m doing a group homework for my  
multimedia class, the task is doing an interactive site in flash.  
It will be a [COLOR=blue]VIRTUAL KITCHEN[/COLOR].

I have used [[COLOR=red]pom’s gravity tutorial[/COLOR]](http://www.kirupa.com/developer/actionscript/gravity.htm) to make the objects of the kitchen  
to be affected by [COLOR=red]gravity[/COLOR] and also to be [COLOR=red]draggable[/COLOR].

code for the movie clips is

```auto
 
onClipEvent (load) {
 // gravity is what I called g in the tutorial. The
 // higher g the harder the ball will fall.
 // gravity = 0 can be set, as an experiment, but 
 // it will in fact create a "zero gravity" effect
 // gravity < 0 will create an inverted gravity effect
 gravity = 4 ;
 
 // This sets the _y position of the floor
 floor = 520 ;
 floorx1 = 70;
 floorx2 = 725 ;
 
 // Bounce is a number < 1 but close to 1
 // The closer to 1, the higher the ball will bounce 
 bounce = 0.6;
 
 // We set the speed of the ball when it is released.
 speedx = 0 ;
 speedy = 0 ;
}
onClipEvent (enterFrame) {
 if (pressing) { 
 // if we are pressing
  // drag the object
  startDrag (_root.bol,true) ;
 
  // calculate the speed
  speedx = this._x - x0 ;
  speedy = this._y - y0 ;
  // set a new reference point
  x0 = this._x ;
  y0 = this._y ;
 }
 
 else {
  stopDrag () ; 
 // We calculate the increase of speed
 // speedx doesn't change
 speedy = speedy + gravity ;
 
 //We move the ball
 this._x += speedx/5 ;
 this._y += speedy/5 ;
 
 if (this._y > floor) {
  this._y = floor ;
  speedy *= -bounce ;
  }
 if (this._x < floorx1) {
  this._x = floorx1 ;
  speedx *= -bounce ;
  }
 if (this._x > floorx2) {
  this._x = floorx2 ;
  speedx *= -bounce ;
  }
 }
}

```

and the button inside the movie clip is

```auto
on (press) {
 pressing = 1 ;
}
on (release) {
 pressing = 0 ;
}

```

I copied the code to the main character of this frame, the “BOWL”  
movie clip. then added the code to the “EGGS” movie clip, and changed  
all the variable names of the gravity code inside eggs. even on the  
button inside eggs, say “pressing 1” instead of “pressing”.

When I call the recipe frame, both eggs and bowl fall to the table,  
but I can’t drag the bowl, [COLOR=red]only the eggs movie clip is dragable[/COLOR].

Bowl and eggs are on different layers. If I move eggs layer under bowl  
layer, I can now drag drag eggs, but can’t drag bowl.

I think there is a much simpler and shorter way to do this, like writing  
all thecode in the first layer, and write the gravity as a function, then  
apply the code to the movie clips with period notation, but i don’t know  
how to do it.

I have a “spoon” button in a layer under eggs, that i want to drag  
with On(press) , but spoon doesn’t move.

I think the problem is in the OnclipEvent (enterframe) and StartDrag  
and stopDrag functions. maybe a problem of mouse listener.

any help ? how can i make all the objects to be dragable and keep  
being affected by gravity after release ?

and it looks like this  
 ![](http://forum.kirupa.com/uploads/kirupa/5081/037c014d60b3cf79.gif)  
The pretty, flat, bad perspective graphics, the girls drew them 🙂 and we were in a rush.

thanks for your time!
