June 9, 2011 - No Comments!

WCK Pure AS3 Example with Contact Events

The WCK framework is something I used recently on the Blackberry Playbook version my Susie Starfish app. Moving into the world of physics is a big step for any flash dev and I feel the WCK framework is a good way to get up to speed on some of the basics.

Moving onwards I wanted to be able to appreciate how the framework works a little more so I could begin to program aspects myself through pure code in a way that was more familiar to me than the Box2DAS port. My reasoning is that I just wanted to be a little more in control for when I come to memory management and the general interactivity of the project. The following code snippet is a quick example of a box falling onto the ground and firing off the events related to such an activity.

import Box2DAS.Common.b2Base;
import Box2DAS.Dynamics.ContactEvent;

import flash.display.Sprite;
import flash.events.Event;

import shapes.Box;

import wck.WCK;
import wck.World;

public class Level1 extends Sprite

public var world:World;

public function Level1()
world = new World();


var box:Box = new Box();
box._bubbleContacts = true;

var floor:Box = new Box();
floor._bubbleContacts = true;
floor.type = "STATIC";
floor.y = 600;

box.reportBeginContact = true;
box.reportEndContact = true;
box.reportPreSolve = true;
box.reportPostSolve = true;

box.addEventListener(ContactEvent.BEGIN_CONTACT, onBlockContact, false, 0, true);
box.addEventListener(ContactEvent.END_CONTACT, onBlockContact, false, 0, true);
box.addEventListener(ContactEvent.POST_SOLVE, onBlockContact, false, 0, true);
box.addEventListener(ContactEvent.PRE_SOLVE, onBlockContact, false, 0, true);

protected function onBlockContact(event:ContactEvent):void

Published by: nick in AS3, Code Sample, Flash, Uncategorized

Leave a Reply