PDA

View Full Version : Please Help


pilotpierre
08-01-2007, 08:08 PM
I am currently trying to use action script to make a squre move accross the screen and when it hits the side of the stage go back the other way untill it hits the end of the stage and so on..........Here is the code that i made wich doesnt work. Please help.

onClipEvent(enterFrame) {
speed = 5;
this._x -= speed;


if (this._x > Stage.width)
speed = 5;
this._x += speed;


}
I dont know why this doesnt work but it is probally because it has errors n it because i have just began using action script. Thanks alot.

Brucebannor
08-01-2007, 08:20 PM
make your square inside a movieClip called square_mc. place this code on your main timeline.

var forward:Boolean = true;

onEnterFrame = function()
{
if(square_mc._x >= Stage.width - square_mc._width) // so it stops right at the end of stage
{
forward = false;
}
else if(square_mc._x <= 0)
{
forward = true
}

if(forward)
{
square_mc._x += 1;
}
else if(!forward)
{
square_mc._x -= 1;
}
}