At 11/8/09 10:53 AM, Jynxxx wrote:
Anyway, as a result, I'm looking or what the equivalent is of onClipEvent(enterFrame) for the timeline? (Basically a chunk of code that will execute over and over and loop).
You'll eventually want to code everything in seperate classes and .as files, but to get you started with AS3.0, you can do the following. Draw a ball. Convert it into a movieclip and keep it placed on the stage. Give it an instance name "ball".
Put all of this on the first frame of the movie.
stage.addEventListener(Event.ENTER_FRAME, mainLoop);
function mainLoop(e:Event)
{
ball.x++;
}
I'll explain the code a bit to get you on your way.
AS3.0 uses 'Event Listeners' which basically just sit around waiting for certain events to happen. When those events do happen, it can call a specific function. In the example above, we create a listener on the stage that listens for ENTER_FRAME events. Whenever one happens, it will run the mainLoop function. It's a bit more advanced than that with how it passes arguments and what not, but we won't get into that. =)
Now, if you had 3 different clips, a ball, triangle and square, you could do this.
stage.addEventListener(Event.ENTER_FRAME, mainLoop);
function mainLoop(e:Event)
{
ball.x++;
square.y +=30;
triangle.x --;
}
And all three would move their respective ways every frame. If you want to take it one step further, you can add INDIVIDUAL events to different shapes by changing something simple..
instead of ;
stage.addEventListener(Event.ENTER_FRAME , mainLoop);
You could do something like..
ball.addEventListener(Event.ENTER_FRAME, ballLoop);
And change the name of the function.
function ballLoop(e:Event)
{
//Whatever you want the ball to do every frame
}