PDA

View Full Version : easing actionscript x2?


shaftbond
03-01-2004, 10:32 PM
Hi, I have four movie clip buttons at the top of my page, and I made a movie with this code:

onClipEvent(load){
_y=189.6;
_x=467.3;
speed=5;
}
onClipEvent(enterFrame){
_x+=(targetx-_x)/speed;
_root.homeb.onRelease=function(){
targetx=467.3;
};
_root.compb.onRelease=function(){
targetx=252.3;
};
_root.gallb.onRelease=function(){
targetx=57.3;
};
_root.servb.onRelease=function(){
targetx=-147.7;
};
}


to have it slide back and forth on the x axis when the buttons are pushed. It worked flawlessly. Then I added another movie that I wanted to slide around when the same buttons were pushed and I added this code to the second movie:

onClipEvent(load){
_y=381;
_x=530;
speed=8;
}
onClipEvent(enterFrame){
_x+=(targetx-_x)/speed;
_y+=(targety-_y)/speed;
_root.homeb.onRelease=function(){
targetx=530;
targety=381;
};
_root.compb.onRelease=function(){
targetx=22;
targety=381;
};
_root.gallb.onRelease=function(){
targetx=530;
targety=126;
};
_root.servb.onRelease=function(){
targetx=22;
targety=126;
};
}


Now the second movie clip slides around just as it should, but the first MC doesn't move...I haven't changed the code from when it was working...am I doing something wrong? Thanks.

divarch
03-01-2004, 11:27 PM
You are defining two 'onRelease' events each frame for the same button. That way, it is impossible.
Try changing to 'onPress' for one of the movieclips and you'll see what I mean. (it will work, but find another way)
Here's a modified code-put it on the main timeline, and remove the code from the clips:
//clipA init
clipA._y = 189.6;//name the clip instances as you like
clipA._x = 467.3;
//clipB init
clipB._y = 381;
clipB._x = 530;
function slide(clip, targetX, targetY,speed) {
clip.onEnterFrame = function() {
clip._x += (targetX-clip._x)/speed;
clip._y += (targetY-clip._y)/speed;
};
}
_root.homeb.onRelease = function() {//repeat the code for additional buttons, with different 'slide()' params
_root.slide(clipA,400, 381,5);
_root.slide(clipB,100, 251,8);

};


Cheers

shaftbond
03-01-2004, 11:50 PM
ahh...i didn't know you couldn't have more than one onRelease function for one button.

thanks man, you're a lifesaver! the code you gave worked perfectly.