PDA

View Full Version : moving, but not the way I want



crapboyjr
December 7th, 2003, 01:19 PM
I'm trying to learn actionscript...uphill battle. :(


I have two movie clips.
When I rollover mc1, I want it to move mc2 to a position 108.7 from mc2's original position.

I right-clicked mc1, selected Actions and placed the following code on it:

----------------------------------------------------------------------------------

onClipEvent (load) {
_x = 0;
_y = 0;
div = 5;
}

onClipEvent (enterFrame) {
_parent.mc2._x += (endX-_x)/div;
_parent.mc2._y += (endY-_y)/div;

_parent.mc1.onRollover = function() {
_parent.mc2.onEnterFrame = function() {
endX = 108.7;
endY = 0;

};
}
}

----------------------------------------------------------------------------------

Problem is, when I rollover mc1, it cause mc2 to move right off of the screen. It won't stop at the position of 108.7.

I'm pretty sure the way I wrote the code is messed up. I took bit's and pieces from other examples to get this to work. Or not work in this case.


Thanks for any help

Voetsjoeba
December 7th, 2003, 01:35 PM
Remove the code you have now, and place this code on the timeline in which your movieclips are in:



mc1.onRollOver = function(){
origin = {x:mc2._x}
tX = origin.x+108.7
mc2.onEnterFrame = function(){
this._x = tX-(tX-this._x)/1.2
if(this._x > tX-1 && this._x < tX+1){
delete this.onEnterFrame
}
}
}


That should do it :)

crapboyjr
December 7th, 2003, 02:57 PM
It works, except I wanted mc2 to stop at 108.7 from it's position. Not keep moving 108.7 everytime I rollovered mc1.

Basically, I'd like it to do this:

rollover mc1 and move mc2 108.7.
rollout mc1 and move mc2 back to it's original position

Sorry I didn't make myself clearer.

Voetsjoeba
December 7th, 2003, 03:04 PM
Sorry, my mistake. I forgot to prevent it from doing it again. Here's your new code:



baseX = mc2._x;
MovieClip.prototype.easeX = function(tX) {
this.onEnterFrame = function() {
this._x = tX-(tX-this._x)/1.2;
if (this._x>tX-1 && this._x<tX+1) {
delete this.onEnterFrame;
}
};
};
mc1.onRollOver = function() {
mc2.easeX(baseX+108.7);
};
mc1.onRollOut = function() {
mc2.easeX(baseX);
};

crapboyjr
December 7th, 2003, 03:14 PM
Thanks for your help, but it's still doing the same thing. Any suggestions?

I really appreciate it.

Voetsjoeba
December 7th, 2003, 03:21 PM
Really ? It works fine for me:

crapboyjr
December 7th, 2003, 08:00 PM
You are the best! It works perfectly.

My bad though. I was using instances of the same movie clip whereas you had different movie clips.

Quick question though. How would I change the width of mc1 to make it wider when I rollover it?

I'm guessing there must be some property code to manipulate the width?

Thanks again for helping me. I really learned a lot today!!! :)