all groups > flash actionscript > september 2004 >
You're in the

flash actionscript

group:

Move an object with a button


Move an object with a button Cliz
9/20/2004 10:19:58 PM
flash actionscript:
Re: Move an object with a button mandingo
9/20/2004 10:43:38 PM
have you tried searching for this? This has been answered many times.

upBtn.onRelease = function(){
myObject._y -=5;
}
downBtn.onRelease = function(){
myObject._y +=5;
}

now depending on where the button is in relation to the object... you may need

this._parent.myObject to reference the object

I hope that helps... if not, search the forums and you will see this answered
cheers,
Re: Move an object with a button Cliz
9/21/2004 12:59:18 AM
Thank your for your reply. I did try searching the forums. I don't generally
post new threads, I just couldn't find it in my searches.

I'm sure I'm doing something wrong, but that doesn't seem to work. I've
substituted in my own instance names because I believe that's what I'm supposed
to do, but it's just not working. I don't even know how to ask for help...
Re: Move an object with a button mandingo
9/21/2004 1:00:22 AM
post the code that you have got and I will check it out...

Re: Move an object with a button Cliz
9/21/2004 2:20:39 AM
This is it. I used the target path thing for the third line.

on (release) {
upArrow.onRelease = function() {
this.scroller.scroll_thumb.thumb_btn._y -= 5;
};
}
Re: Move an object with a button NSurveyor
9/21/2004 2:36:37 AM
On your up button:

on (release) {
this.scroller.scroll_thumb.thumb_btn._y -= 5;
}

on your down button:

on (release) {
this.scroller.scroll_thumb.thumb_btn._y += 5;
Re: Move an object with a button albee
9/21/2004 3:16:35 AM
Try this code on the first frame of your Flash movie:

var isUp;
upArrow.onPress = function() {
_root.isUp = true;
};
upArrow.onRelease = function() {
_root.isUp = undefined;
};
downArrow.onPress = function() {
_root.isUp = false;
};
downArrow.onRelease = function() {
_root.isUp = undefined;
};
myObject.onEnterFrame = function() {
if (_root.isUp == true) {
this._y -= 5;
if (this._y <= 0) {
this._y = 0;
}
} else if (_root.isUp == false) {
this._y += 5;
if (this._y >= 505) {
this._y = 505;
}
}
};

Make sure your arrow buttons have the instance names upArrow and downArrow.
The object you want to move has a file path which should replace myObject in
the code above. This code will keep moving myObject until it reaches the top or
bottom edges of a 600 px high stage, when myObject is 95 px high. Figure out
the dimensions of your stage and your object and where you want the limits of
the object motion to be and substitute the numbers above...

check out an example at http://www.cristancho.net/flash/move

Good luck...
AddThis Social Bookmark Button