Archive for the ‘AS3.0 Core’ Category


February 23, 2012 Leave a comment

v_mag = 5
v_ang = 0

c.onPress = function(){
c.onRelease = function(){

b.onEnterFrame = function(){
dist = Pythagoras(b._x, b._y,c._x, c._y)
if(dist > 100){
v_ang = getAngle(b._x, b._y,c._x,c._y)
vx = v_mag*Math.cos(v_ang)
vy = v_mag*Math.sin(v_ang)

b._x += vx;
b._y += vy;

function getAngle(x1, y1,x2, y2):Number{
distX = x2-x1
distY = y2-y1
ang = Math.atan2(distY, distX)
return ang

/*b.onPress = function(){
b.onRelease = function(){
b.onEnterFrame = function(){
//min = (b._width +c._width)*0.5
//dist = Pythagoras(b._x, b._y,c._x, c._y)

c._x += 1
function Pythagoras(x1, y1,x2, y2):Number{
distX = x2-x1
distY = y2-y1
z = Math.sqrt(distX*distX + distY*distY)

return z

Categories: Basics

Let’s Get Started

February 20, 2012 Leave a comment

I’ve been delivering a module that introduces Mathematical manipulations to simulate physics environment in my workplace. It’s my interest to get students across the hurdle of programming interface in the shortest time and really dip into the Math. After trying several rounds of AS 2.0 and AS 3.0 with batches of students, I find students benefitted most when I used As 2.0.

While Actionscript 3.0 had been rocking for the past 5-6 years, whenever it comes to teaching and learning for fresh students (absolute beginner in programming), I still find Actionscript 2.0 superior. Here are a few observations:

  1. Less-overwhelmed. AS 2.0 has a smaller set of tools compared to AS 3.0. Students reach the boundary of what’s possible through API sooner and will look elsewhere like Math to improve + build upon the basic scaffolding provided through API calls.
  2. Syntatically simpler. Needless to say, they are able to write their own AS 2.0 easier.
  3. Structurally simpler. Although AS 2.0 do make use of event model, but structure required to write it is short. No separate function to do the event handling, you can write all in one line.
  4. Loosely typed. Variable declaration is loose. No need to get know the exact datatype of variables. Students will not know the whole extend of things they can create initially, so this help is valuable for jump start.

Now I’m not undermining the importance of knowing AS 3.0. My point is rather to start students off easily using AS 2.0, then only at level 2 (or upon their own effort) usher in migration to AS 3.0.

There’s advantage in knowing both these programming structures. AS 3.0 is mature in the way the language is structured and libraries are organised. It’s comparable to the way Java and C# programs are being written. On the other hand, AS 2.0 is a little similar to Javascript, which is used to develop HTML 5.0 games. So students get a taste of both worlds. As the need to program for different platform comes, they can quickly adapt because they are exposed already.

Categories: Basics

Roadmap of Content:

February 3, 2012 Leave a comment
Categories: Physics_Simulation

Angle units – Pi radians vs degrees

February 3, 2012 Leave a comment

Let’s establish that half circle is 180 degrees and Pi radians, and from there on we can conclude on several facts as below.


Now, I’m sure you are able to understand the degrees pretty well. It’s the Pi radian measurement that’s bogging your mind. However, its actually quite elegant. You see semi-circle makes 1 Pi radians, a perpendicular angle makes 0.5 Pi radians and you can just keep dividing by two to get the exact angle you like.

Having said that, I take a neutral stand when it comes to preferences. Cos unit of degrees are just drilled into my brain. Im sure that’s the case for many of us, so let’s come up with a formula that will solve this issue. We use ratios and a little algebra.


So all the sudden, things are a little easier. Well, that’s what revision is suppose to be…

Categories: Physics_Simulation

Coordinate Spaces

February 3, 2012 Leave a comment

Here’s a quick note on coordinate spaces: that of Flash and that of Cartesian. Spot the difference!space

If you say, “the y is inverted!” you are right! Not just that, the whole coordinate space is inverted on y. If positive angle increment is anti-clockwise, now its the other direction and vice versa for the negative angle increment.


Im sure you can extend the coordinate space into its negative regions and be comfortable manipulating it because they’re basic stuff. Otherwise, we’ll still have a chance to see them in topic of Vectors.

Categories: Physics_Simulation

Pythagoras’ Theorem

February 3, 2012 Leave a comment

Pythagoras’ a Greek and he’s a brilliant mathematician (more of a philosopher back then) who arrived at a theorem shown as below.


The diagonal side (aka hypothenus) power 2 is the sum of horizontal and vertical side, each power by 2.

Ok, so let’s make use of it. Here’s a question. Get the length of line in image. We know the two bounding coordinates.


So its a trivial question. So here’s the answer.


This problem is frequently met so you are advised to program it into a class file for quick reference. It’s applied when we’d like to get the magnitude of a vector. Given a case where we have the following information, we should know to quickly remember Pythagoras.


Another application of it leads to collision detection. Once you have understood this fundamental, you’ve got Pythagoras!

Categories: Physics_Simulation


February 3, 2012 Leave a comment

The topic of trigonometry cannot escape GP. In fact, it forms the backbone of the whole GP. Let’s go through some of the bacis: sine, cosine and tangent.

Here’s a diagram that will sum them up:


Note that these basics are used to translate polar coordinate to Cartesian coordinate. Recall polar coordinate is written as (magnitude, angle) while Cartesian coordinate is (x, y). For example write in Cartesian coordinate format the polar coordinate (10, 30).


So there you have it. Another important application of trig is to quickly obtain the angle of triangle given sides x and y. Check out image below.


This case happens when you want to do the reverse: translating from Cartesian to polar. Given Cartesian coordinate (x1, y1) measured origin, we shall use the Pythagoras’ theorem to get the magnitude and inverse tangent of side y over x to get angle.

Categories: Physics_Simulation