Functions

I’m reading Colin Moocks Actionscript for flash MX book and upon reading functions he instructs to create a symbol named ballSymbol, than put an instance on the stage (frame 1 maintimeline) and call it ball. Than on frame 1 on the main timeline put the following actionscript:


_global.mainTimeline = this;
 
function moveBall() {
mainTimeline.ball._x += 10;
mainTimeline.ball._y += 10;
};
moveBall();

The ball is supposed to move diagonally. But my problem is when I test the movie, nothing happens. No movement, nothing…

What am I missing?

so mainTimeline is a movieclip that contains an instance of ball?

Make sure all movieclips have an instance name and try again.

:hr:

You don’t see anything because that code (or at least the part you posted) is only executed once. What you see is the ball after it has moved 10px to the right and 10px to the bottom. To keep it executing, use for example an onEnterFrame handler:

this.onEnterFrame = function(){
moveBall();
}

That’ll keep it moving.

it is important to know that both the function to move the ball and the EnterFrame command should be placed inside the ball movie clip.