PDA

View Full Version : Keep moving ball when mouse is pressed and held


Atlasts
06-19-2002, 08:17 PM
Hi,

I'm trying to move a ball in my component 5 pixels to the left when the mouse is pressed (that works) but I would like the ball to keep moving 5 pixels if the user keeps the button pressed. It trying to use the setInterval but the ball will not keep moving. Snipplet:

// On Press Code

this.slideLeft_mc.onPress = function()
{
this._parent.ballObject_mc._x = this._parent.ballObject_mc._x - 5; // this works!!
if (leftLooping != "YES") {
leftLooping = "YES";
leftIntervalSet = setInterval(startLeftMove,50);
}
}

// Interval Function (trace keeps printing intervals but ball does not keep moving!

function startLeftMove ()
{
trace("Left = "+b1);
this._parent.ballObject_mc._x = this._parent.ballObject_mc._x - 5;
count = count + 1;
trace("ball = " +b1.ballObject_mc + " " + count);
updateAfterEvent();
}

Thanks for any help! If there is a better way, let me know.

I've also attached the fla if you want to execute the code.

Thanks,
Atlasts

Atlasts
06-19-2002, 08:30 PM
Didn't realize that it needed to be .txt so I renamed my fla. Just rename to testMoveObj.fla

farafiro
06-20-2002, 07:30 AM
I didn't see your code but try this
function move(){
this._x +=speed
}
ball.onMouseDown = function(){
speed = 5
this.onEnterFrame = move
}
ball.onMouseUp = function(){
speed = 0
}

Atlasts
06-20-2002, 05:41 PM
That worked fine!