Just to let you know that i have successfully moved all my tutorials across from my old site and they are all working perfectly. I also had the time to create a getting started with APE tutorial for those interested!
More to come soon!
Just to let you know that i have successfully moved all my tutorials across from my old site and they are all working perfectly. I also had the time to create a getting started with APE tutorial for those interested!
More to come soon!
APE, or the Actionscript Physics Engine is a free as3 physics engine built by Alex Cove. It is really easy to use once you get the hang of it and it has detailed documentation to read if you get stuck.
In this tutorial i will show you how to make a simple ball example with gravity.
Firstly you will need to download the latest version of APE. There is a stable release on Alex Cove’s website but i am using the ‘bleeding edge’ one from the google code repository. You can download the whole package from my site here.
Unzip the folder and save it in a place so that you know where it is for example mine is located in my documents folder on my computer.
Now load up flash and create a new actionscript 3 file like normal and save this file however you want. To load the APE classes into the flash authoring environment so that we can use them we first need to change the root classpath of the .swf that will be created. The next step is the most important to get APE running in flash. Follow exactly as i say!

Go to file>publish settings then a screen should pop up that looks like this one below. Click on the flash tab in the centre, that is highlighted in the picture below. Now look to the picture on the right.

Click on actionscript 3 settings, where the mouse curser is on the screenshot. A screen like the one below should show.

Click on the browse to path button that is above the large ‘classpath’ box at the bottom of the window, where the mouse curser is pointing.

This will send you to a browsing screen where you have to select the classpath.
h of your .swf. You need to choose the ape_a045 folder that you downloaded earlier and select the source folder inside that. This is where your classpath needs to be. Take a look at this picture. The folder should only have a folder called org inside it like shown.
Click choose and then the white box at the bottom of the publish settings should have the direct path to the source folder inside the ape_a045 folder on it.
If the class path is correct click OK and then click OK again to return to the flash authoring environment.
Next we can start to code and use the engine.
Loading sound from an external source (i.e, not embedded in the .swf file) is really easy to do once you know how. I am going to use the same example as i used for the last tutorial but the sound is not going to be embedded in the .swf it is going to be hosted on my site
Here is the example. I have changed the sound to a whole song to demonstrate how quickly it takes to load.
Important!
Before i started i uploaded a .mp3 file to the internet so that i could call it with a URL request in this code.
You will need to do this for this code to work from the internet, alternatively you can put a sound file in the root classpath of your .fla (this is usually the same folder as the .fla).
Another important note
if you are loading a file on the internet change you publish settings for flash to “access network file only” and if you are loading it from a folder change it to “access local files only”.
To do this it was simple. I replaced one line of the old code for three more lines of code.
I replaced the line:
var sound:Sound = new acoust();
with:
var loadsound:URLRequest = new URLRequest(“http://where my mp3 file is on the internet.mp3″);
var sound:Sound = new Sound();
sound.load(loadsound);
Line 1: a new variable called loadsound which requests the file from the url mentioned inside the brackets and the “”
line 2: a variable like before that holds a blank instance of the sound class instead of the class that we made called acoust.
line 3: loading the sound that we got from the internet via the URL request into the blank instance of the sound class that we named earlier.
Note: if you want to load the sound locally from a folder you just replace “http://where my mp3 file is on the internet.mp3″ with “sound name.mp3”
The complete code for ease.
import flash.media.Sound;
var loadsound:URLRequest = new URLRequest(“http://where my mp3 file is on the internet.mp3″);
var sound:Sound = new Sound();
sound.load(loadsound);
var channel:SoundChannel;
var soundisplaying:Boolean = false;
var pausePosition:int = 0;
playbut.addEventListener(MouseEvent.CLICK, playsound);
stopbut.addEventListener(MouseEvent.CLICK, stopsound);
function playsound(event:Event):void {
if (soundisplaying==false) {
channel = sound.play(pausePosition);
soundisplaying = true;
channel.addEventListener(Event.SOUND_COMPLETE, soundComplete);
}
}
function stopsound(event:Event):void {
pausePosition = channel.position;
channel.stop();
soundisplaying =false;
}
function soundComplete(event:Event):void {
channel = sound.play();
channel.addEventListener(Event.SOUND_COMPLETE, soundComplete);
}
Ok this will hopefully help some of you.
i am going away for a week so don’t expect any more posts until i get back!