I am new :cyclops: to action script and am learnign a great deal from you all! THANKS for all the help!
Now for the question:
I have read several tutorials on moving objects around but i have had no luck finding one that tells how to put a simple function of sliding a movie one way and then another way when mousing over 2 different buttons.
I have a photo i want to slide on mouse over to the left for one button but stop at a certain point and then another button that would make it slide to thr right but only to the end of the photo.
Does anyone know the best way to do this and the easiest and cleanest coded way?
The easiest and cleanest code I have seen involves easing, not just simple movement. I like easing because it looks good. Easing is when an object moves at speed and then slows when it nears its destination.
Voetsjoeba has written a genuinely beautiful piece of code for easing:
Easing in x direction:
MovieClip.prototype.easeX = function(to){
this.onEnterFrame = function(){
this._x = to-(to-this._x)/1.1;
if(this._x > to-1 && this._x < to+1){
this._x = to;
delete this.onEnterFrame
//do other stuff here, this is the point at which the object reaches its target
}
}
}
MC.easeX(100);
easing in x and y direction:
MovieClip.prototype.ease = function(x,y){
this.onEnterFrame = function(){
this._x = x-(x-this._x)/1.1;
this._y = y-(y-this._y)/1.1
if(this._x > x-1 && this._x < x+1 && this._y > y-1 && this._y < y+1){
this._x = x;
this._y = y;
delete this.onEnterFrame
//do other stuff here, this is the point at which the object reaches its target
}
}
}
MC.ease(100,100);
Put the prototype code on the main timeline in an actionscript layer. Put the code that calls the prototype function (in this case MC.ease(x, y)) anywhere you want to call it. You can call it from an on(release) button event:
I will give it a shot and see if i can figure it out. Since i am new to this i might have some more questions.
Will this alow me to slide it only when pressign the button and when i release it stops sliding? I dont want it to go all the way to the end but only move as long as you hold the button and then when you let off it stops. This way if it is a really long image you scroll a little bit and release to look and then click to keep scrolling to the end or hower far you want.
Do you think that maybe some kind of panoramic script does this with buttons and such?
Thanks!!! I can not tell you how much i really appreciate all the help everyone has given me!
Aaron
Nah the script I gave you wont’ suit your needs then. What I gave you is something that, when you call it the function and give it an x or x,y coordinate, it will move to that spot. Sounds like what you want is something different.
Well, don’t know about the bounds part - that is much more complicated (look up getBounds in your actionscript reference). But I can help with the other part.
man that is awesome too!!! you are very fast at this stuff!
Thanks for the help! I will see what i can find. If i find somthing i will post because i doubt i will know how implement. Sorry for being such a newb!
Sorry ,my mistake. I`ve fixed your file but you will have to play with the variables when you change photo_mc.
EDIT/
if you want to use easing something like this might work better
function move(clip, targetX, speed) {
clip._x += (targetX-clip._x)/speed;
if (Math.abs(clip._x-targetX)<1) {
clip._x = targetX;
clearInterval(myInterval);
}
}
btn1.onPress = function() {
clearInterval(myInterval);
myInterval = setInterval(move, 20, photo_mc, 385, 30);
};
btn2.onPress = function() {
clearInterval(myInterval);
myInterval = setInterval(move, 20, photo_mc, 0, 30);
};
btn1.onRelease = btn2.onRelease=function () {
clearInterval(myInterval);
};