Scripting
Using APE Physics Engine with Awesome Animator – Part 2
by Administrator on Jul.23, 2011, under Scripting
In this post we shall delve into using a pre-built physics library (namely APE by Alec Cove). This is a set of AS3 classes. First download them off the the APE website. Next copy all the files in each of the demo folders into the source folder. This is so the source files can be found by Awesome Animator. (Make sure you have the latest version). Now open the script window and go to AS3 > Import class… and choose the CarDemo.as for example. We set CarDemo as the main class and parse everything. Next we can close the script window and decorate the background. What we end up with is something that looks like this:
(The keys are ‘A’ for go and ‘D’ for reverse)
Other things we could do is modify the colours in the CarDemo constructor or class file to change the colours of the robot and obstacles.
You may find it useful to download the Flash debug projector when working with scripts. It can be found on the Adobe website.
Using APE Physics Engine with Awesome Animator – Part 1
by Administrator on Jul.23, 2011, under Scripting
In this post we shall delve into using a pre-built physics library (namely APE by Alec Cove). This is a set of AS3 classes. First download them off the the APE website. Next copy all the files in each of the demo folders into the source folder. This is so the source files can be found by Awesome Animator. (Make sure you have the latest version). Now open the script window and go to AS3 > Import class… and choose the RobotDemo.as for example. We set RobotDemo as the main class and parse everything. Next we can close the script window and decorate the background with some clouds. What we end up with is something that looks like this:
(The keys are ‘P’ for go and ‘R’ for reverse)
Other things we could do is modify the colours in the RobotDemo constructor or class file to change the colours of the robot and obstacles.
You may find it useful to download the Flash debug projector when working with scripts. It can be found on the Adobe website.
Earth Moon Gravity Simulation
by Administrator on Oct.25, 2010, under Scripting
In this tutorial we shall make a basic gravitational simulation with the inverse square law of attraction. It should end up looking like this:
We draw two spheres and group each one as a MovieClip. Using the frame panel we assign a reference name to each one: earth and moon. For the moon we set up the variables by choosing the MovieClip Events > onLoad action from the action menu. And type in:
And then for the MovieClip Events > onEnterFrame we have:
//work out distance from earth to moon
dx = _root.earth._x – _x
dy = _root.earth._y – _y
r = Math.sqrt(dx*dx + dy*dy)
//get the mass of the earth from the other MovieClip
m = _root.earth.mass
//change the velocity according to the inverse square law of attraction
velocity.x += m*dx/r/r/r
velocity.y += m*dy/r/r/r
//change the position with the values of the velocity
_x += velocity.x
_y += velocity.y
We then repeat these actions for the Earth but wherever it says earth put moon. Also, the starting values for the earth MovieClip in the onLoad action should be:

Showing events and references in editor
Other things you might like to add would be a reset button.
Bouncing Ball
by Administrator on Oct.25, 2010, under Scripting
In this tutorial we are going to model a bouncing ball using the equations of Newtonian physics no less! This is the result:
First let us create a new animation with size 400 x 300 using the File > Document Properties menu.
Next we draw the ball with the sphere tool. Next we group the ball as a MovieClip.
Next with the ball selected we go to the Action menu and in the MovieClip Events we choose onLoad to set up some values for when the ball first appears on the screen. In the action box we type in:
gravity = 4
velocity = {x:10, y:0}
This sets the strength of the gravitational force to a suitable number and adjusts it for 24 frames a second animation. It sets the initial velocity to a sideways direction in the x-axis.
We close this window. Then in the MovieClip Events we choose onEnterFrame which tells the ball what to do on every frame. We type in:
//the velocity increases downwards every frame
velocity.y += gravity
//the position of the ball change with the velocity
_x += velocity.x
_y += velocity.y
//if it hits the floor reverse the downward velocity
if( _y + _height/2 > Stage.height){
velocity.y*= -1
_y=Stage.height -_height/2
}
//if it hits the sides reverse the sideways velocity
if( _x - _width/2 < 0 || _x + _width/2 > Stage.width){
velocity.x*= -1
}
Close the action window and preview the result!
(You may notice that when it hits the floor we also adjust the position of the ball so it touches the floor exactly. This prevents unusual behaviour such as the ball bouncing higher then it fell.)
Crazy Lines Animation
by Administrator on Oct.12, 2010, under Scripting
In this tutorial you will create a crazy effect which is made out of many colourful lines. This is an example of an effect where it is far easy for it to be done in scripting than by doing it by hand.
Step 1
Go to the first frame and from the animation menu choose ‘Add new frames’ and add 2 frames.
Step 2
Go to the first frame and from the actions menu choose ‘Frame Action’. The script window will open and you can type in what’s indicated in bold:
// Set some variables to hold the width and height
W=300
H=300
// Clear the screen
clear()
// Now we will draw 50 lines
for(n=1;n<=50;n++){
// Store some properties in some variables
linewidth = Math.random()*10
linecolor = Math.random()*256*256*256
opacity = 100
// Actually draw the line
lineStyle(linewidth,linecolor,opacity)
moveTo(Math.random()*W,Math.random()*H)
lineTo(Math.random()*W,Math.random()*H)
}
The lines preceded by // are comments and are not strictly necessary but are simply there to remind you what different lines of the script do. The function Math.random() gives a number between 0 and 1 so to give a number between say 0 and 100 this number is just multiplied by 100.
Step 3
Close the script window and go to frame 2. In frame two add a new frame action and type in (or use the quick action menu):
gotoAndPlay(1)
You should end up with this delightful animation:
Moving an object
by Administrator on Jul.07, 2010, under Scripting
In this post we shall see how to change the position of an object by pressing a button. This gives you a basic idea of how interactions work.
Step 1
First create you button! You can do this with the quick button wizard from the quick menu.
Step 2
Create the object that you will be moving. In our example it could be just a circle. Select the object(s) and group them as a MovieClip. Now in the frame panel choose a reference name for this movieclip for example myellipse.
Step 3
With the button selected, choose the menu item: Actions>>Button Events…>>on Press… This will open the action window.
Step 4
Now we get to the scripting part. Say we want to move myellipse to the position 200 across and 300 down. We write:
myellipse._x = 200
myellipse._y = 300
Or more interestingly if we wanted to move myellipse 10 pixels to the right and 15 pixels down we would write instead:
myellipse._x += 10
myellipse._y += 15
Step 5
Export your animation as a SWF. All going well it should look like this: