In a valliant attempt to finally start using some MX code, i tried to recode my random moving script from flash 5 to MX. It works, but doesn't seem to ease in and out anymore. I've tried adding updateAfterEvent, but that doesn't seem to work..
This is the Flash 5 code:
Code:
onClipEvent(load){
targetX = Math.round(Math.random()*550);
targetY = Math.round(Math.random()*400);
}
onClipEvent(enterFrame){
xDistance= targetX - _parent.block._x;
yDistance= targetY - _parent.block._y;
if(xDistance > 10 || xDistance < -10){
_parent.block._x += xDistance*0.09;
} else {
targetX = Math.round(Math.random()*550);
}
if(yDistance > 10 || yDistance < -10){
_parent.block._y += yDistance*0.09;
} else {
targetY = Math.round(Math.random()*400);
}
}
and this is the MX code
Code:
targetX = Math.round(Math.random()*550);
targetY = Math.round(Math.random()*400);
function checkPos(){
xDistance= targetX - blok._x;
yDistance= targetY - blok._y;
if(xDistance> -10 || xDistance < 10){
targetX = Math.round(Math.random()*550);
}
if(yDistance> -10 || yDistance < 10){
targetY = Math.round(Math.random()*400);
}
}
function move(){
xDistance= targetX - blok._x;
yDistance= targetY - blok._y;
blok._x += xDistance*0.09;
blok._y += yDistance*0.09;
}
setInterval(checkPos, 88);
updateAfterEvent();
setInterval(move, 88);
updateAfterEvent();
does anyone have any suggestions as to how I can improve the MX script to make it move smoothly again?