PDA

View Full Version : Limiting MC move

kinfa3
01-08-2009, 10:11 PM
I have 2 buttons, DESNO and LJEVO
and MC "Traka6"

How to limit moving of MC from x(-810),to x(810) pic ?

DESNO.onRelease = function() {
traka6._x += -81;
};

LJEVO.onRelease = function() {
traka6._x += 81;
};

A will be very thankful if somebody help me.

asf8
01-08-2009, 11:06 PM
I have 2 buttons, DESNO and LJEVO and MC "Traka6" How to limit moving of MC from x(-810),to x(810) pic ? A will be very thankful if somebody help me.

Hi kinfa3, welcome to AS.org

Try this....

var maxRight:Number = 810;
var maxLeft:Number = -810;
var moveNum:Number = 81;
//
trace("maxRight = "+maxRight);
trace("maxLeft = "+maxLeft);
trace("moveNum = "+moveNum);
trace("\n");
//
// going Left
DESNO.onRelease = function() {
if (traka6._x<=maxLeft) {
traka6._x = maxLeft;
trace("maxLeft "+traka6._x+" reached");
} else {
traka6._x -= moveNum;
trace("traka6 _x = "+traka6._x);
}
};
// going Right
LJEVO.onRelease = function() {
if (traka6._x>=maxRight) {
traka6._x = maxRight;
trace("maxRight "+traka6._x+" reached");
} else {
traka6._x += moveNum;
trace("traka6 _x = "+traka6._x);
}
};

Does that do what you want? If you want it to move smoothing you can use an onEnterFrame event also. Let us know how that works, hopefully it helps.

asf8
01-08-2009, 11:52 PM
If you want it to move smoothing you can use an onEnterFrame event also. Let us know how that works, hopefully it helps.

Here is an example using an onEnterFrame event (like I mentioned above)...

var maxRight:Number = 810;
var maxLeft:Number = -810;
var moveNum:Number = 20;
//
trace("maxRight = "+maxRight);
trace("maxLeft = "+maxLeft);
trace("moveNum = "+moveNum);
trace("\n");
//
// going Left
DESNO.onPress = function() {
this.onEnterFrame = function() {
if (traka6._x<=maxLeft) {
traka6._x = maxLeft;
delete this.onEnterFrame;
trace("maxLeft "+traka6._x+" reached");
} else {
traka6._x -= moveNum;
trace("Going Left: traka6 _x = "+traka6._x);
}
};
this.onRelease = function() {
delete this.onEnterFrame;
trace("traka6 - Stopped: _x = "+traka6._x);
};
};
// going Right
LJEVO.onPress = function() {
this.onEnterFrame = function() {
if (traka6._x>=maxRight) {
traka6._x = maxRight;
delete this.onEnterFrame;
trace("maxRight "+traka6._x+" reached");
} else {
traka6._x += moveNum;
trace("Going Right: traka6 _x = "+traka6._x);
}
};
this.onRelease = function() {
delete this.onEnterFrame;
trace("traka6 - Stopped: _x = "+traka6._x);
};
};

;)

kinfa3
01-11-2009, 01:10 PM
It work great,