![]() |
||
This tutorial covers getting APE set up in Flex Builder 2, using an ActionScript project. The process is basically identical for a Flex project. 1. Download and unzip the latest release from this site from the home page. 2. Open Flex Builder 2 and create a new ActionScript project. You can do this from the file->new menu, or by right-clicking in the navigator panel (fig 1).
3. Name the project. For the tutorial we'll name it "APETest" (fig 2). The name of the project will also be the name of your main application class. Leave the "Use default location" checkbox checked.
4. Click "Next" to go to the build paths screen of the new project wizard. Now there are two different ways to access the APE library in your project. The first way is to specify the source path. The second is to specify the library path. Using the source path gives you access to the actual source code of APE. Using the library path imports the compiled SWC file, so the APE source code will not be accessible. Otherwise, there's really no difference between the two. If you feel like you want to hack or alter the APE source (which you can under the LGPL license) then feel free. If you just want to use APE and not alter the source code, then use the SWC. Note that using the SWC will not stop you from writing your own classes that inherit from, or are composites of, the APE classes. To use the source path option, make sure the "Source path" tab is selected. Then press the "Add Folder" button, click "Browse", and navigate to the location of the APE 'source' folder (fig 3). Click the "OK" button and the path to the APE source will now be displayed in the list of additional source folders. To use the library path option, make sure the "Library path" tab is selected. Then press the "Add SWC" button, click "Browse", and navigate to the location of the APE SWC file (fig 4). The file is located within the "bin" folder. Click the "OK" button and the path to the APE SWC file will now be displayed in the list of build path libraries. Use only one of these options. Don't import both the source and the SWC.
5. Click the "Finish" button and you're done. If you used the source path option, the source code will appear under your project in the navigator panel. The main application file can be altered as the code shown below. It's a simple example of using APE, creating a single falling circle.
package {
import org.cove.ape.*;
import flash.events.Event;
import flash.display.Sprite;
public class ApeTest extends Sprite {
public function ApeTest() {
stage.frameRate = 60;
addEventListener(Event.ENTER_FRAME, run);
APEngine.init(1/4);
APEngine.container = this;
APEngine.addMasslessForce(new Vector(0,2));
var defaultGroup:Group = new Group();
defaultGroup.collideInternal = true;
var cp:CircleParticle = new CircleParticle(250,10,5);
defaultGroup.addParticle(cp);
var rp:RectangleParticle = new RectangleParticle(250,300,300,50,0,true);
defaultGroup.addParticle(rp);
APEngine.addGroup(defaultGroup);
}
private function run(evt:Event):void {
APEngine.step();
APEngine.paint();
}
}
}
back to home |
||