FMX gravity problems

Hello all, I’ve pretty much straight copied the gravity tut. script onto a bunch of clips in my movie, with one addition- I put an onMouseDown handler in there so when you click on the little buggers, the _y position gets decremented by 10, and they jiggle a little bit. looks cute.
The problem is, all the clips on the stage that have this script applied to it jiggle when you click on any one. ? I thought
[AS]this._y[/AS] just applied to the clip instance it’s applied to? help? here’s the script, again, applied to about 20 clips that are nested within 2 clips on the main stage.
[AS]
onClipEvent (load) {

gravity = 7 ;

// This sets the _y position of the floor
floor = 49 ;

// Bounce is a number < 1 but close to 1
// The closer to 1, the higher the ball will bounce 
bounce = 0.7 ;

// We set the speed of the ball when it is released.
speedx = 0 ;
speedy = 0 ;

}

onClipEvent (enterFrame) {

speedy = speedy + gravity ;

this._x += speedx/5 ;
this._y += speedy/5 ;

// If we are beyond the floor, invert the speed
if (this._y > floor) {
	this._y = floor ;
	speedy *= -bounce ;
}

}
onClipEvent(mouseDown){
this._y = this._y-10;
}
[/AS]

Any suggestions would be greatly appreciated. Thank you.
-Corey

onClipEvent (load) {
        
        gravity = 7 ;
        
        // This sets the _y position of the floor
        floor = 49 ;
        
        // Bounce is a number < 1 but close to 1
        // The closer to 1, the higher the ball will bounce
        bounce = 0.7 ;
        
        // We set the speed of the ball when it is released.
        speedx = 0 ;
        speedy = 0 ;
}

onClipEvent (enterFrame) {
        
        speedy = speedy + gravity ;
        
        this._x += speedx/5 ;
        this._y += speedy/5 ;
        
        // If we are beyond the floor, invert the speed
        if (this._y > floor) {
                this._y = floor ;
                speedy *= -bounce ;
        }
}
on(press){
        this._y = this._y-10;/* with MX you can use mouse actions too */
}

Unfortunately, that’s just made it so that particular clip doesn’t jiggle when you click on any of the other ones. Perhaps I’m doing something else wrong, I’ve attached the .fla . Thank you.

You wanted that if you click on one instante, that instance would move down, right?

Actually, up.

[AS]this._y -= 10;[/AS]
should decrease the y position for that specific instance by 10, correct? I can’t figure out why it does it for every clip instead of just the one you click.

My code doesn’t do that?

nope, every clip moves up 10 px. when you click on any one. Weird, huh?

Stupid me. I know why. Because buttons are special objects with fixed timelines, the code always refers to the timeline where the button resides, kina like using _parent on everything. But the _parent of the movieclip is the stage, so it moves thestage (and the mc’s in it) up.

Just make a button inside of your mc, eith only the hitframe filled. Than paste the on(press) code on that and remove the on(press)from the movieclip.

Actually, they already were buttons,

{Stage}
-art MC
-accessories MC
-mc1
-mc2
-button
-mc3
-mc4, etc.

if that makes any sense. I applied the on Press action to the button, same problem. Sorry to be such a pain.

Interesting point about button timelines though, I didn’t know that.

Thanks for your help.

hm, my formatting dissapeared.


{stage}
        -art MC
        -accessories MC
               -mc1
               -mc2
                      -button
               -mc3
               -mc4, etc.

Basically, I have a main movie clip for each menu item, within the movie clip are several movie clips that each contain a button. I want the buttons, when clicked, to move all the clips in the parent clip up 10 pixels. does that make sense?
Thanks again.
-C

Try

on(press){
_parent._y -= 10;
}

This will, in your example, move accessories MC. If you don’t want to move accessories MC, but you still want to move the buttons, than the only way is to encapsulate the buttons with mc’s and use a loop to address all movieclips.

Can you take a look at the .fla I uploaded? If I address the parent clip, it will move the entire container clip up 10 px, and since it doesn’t have the gravity script applied to it (nor should it), it stays 10px higher. I can’t figure out why it moves every clip that contains a button up 10 px when you click on any one clip.
I don’t think using a loop would help anyways, because I’d just put the same code in the loop that’s attached to each button-containing clip already, and for some reason it seems to be affecting all clips that contain a button.

Hey, I figured it out. I put this code in the first frame of the accessories movie clip:
[AS]acc_1.onPress = function(){
_root.accessories.acc_1._y -=10;
_root.accessories.acc_2._y -=10;
_root.accessories.acc_3._y -=10;
_root.accessories.acc_4._y -=10;
_root.accessories.acc_5._y -=10;
_root.accessories.acc_6._y -=10;
_root.accessories.acc_7._y -=10;
_root.accessories.acc_8._y -=10;
_root.accessories.acc_9._y -=10;
_root.accessories.acc_10._y -=10;
_root.accessories.acc_11._y -=10;
};[/AS]
where acc_1 is the instance name of the movie clip that contains the button I want to press.
Unfortunately, it looks like I’ll have to repeat this for each instance. Seems like there should be a tidier way to do this. hm.

I still don’t understand why this worked, but the previous code I had didn’t. Perhaps because I gave all the instances names and accessed them by absolute paths? Any comments would be appreciated, I’m a pretty bad actionscripter, but am trying to learn.