Skip to content


APE – Multiple Draggable Particles

I was trying to figure out a way to improve my initial movie that stop and starts the APE engine to allow for the user to drag an object. After mucking around with the original APE classes, I found in Google Groups that there are 2 new classes to allow the use to drag either a CircleParticle or a RectangleParticle.

You can grab the zip file here: http://ape-general.googlegroups.com/web/dragable_particles.zip and here is what can be produced:

package {
    import flash.display.Sprite;
    import flash.events.Event;
	import flash.events.MouseEvent;

    import org.cove.ape.*;

	public class Main extends Sprite {

		private var circle:DragableCircleParticle;
		private var circle2:DragableCircleParticle;

		public function Main()
		{
			init();
		}

		private function init():void
		{
			stage.frameRate = 55;

			// Initialize the engine. The argument here is the time step value.
			// Higher values scale the forces in the sim, making it appear to run
			// faster or slower. Lower values result in more accurate simulations.
			APEngine.init(1/4);

			// set up the default diplay container
			APEngine.container = this;

			APEngine.addMasslessForce(new Vector(0,8));

			var defaultGroup:Group = new Group();

			defaultGroup.collideInternal = true;

            var rect:RectangleParticle = new RectangleParticle(350, 348, 700, 20, 0, true);
            defaultGroup.addParticle(rect);

           	circle = new DragableCircleParticle(350, 150, 25);
			defaultGroup.addParticle(circle);

			circle2 = new DragableCircleParticle(300, 150, 25);
			defaultGroup.addParticle(circle2);

			APEngine.addGroup(defaultGroup);

			addEventListener(Event.ENTER_FRAME, run);
		}

		private function run(e:Event):void
		{
			APEngine.step();
			APEngine.paint();
		}
	}
}

Here is the new class file located in org/cove/ape/DragableCircleParticle.as (relative to my Main.as file)

package org.cove.ape{
	import flash.events.MouseEvent;
	import org.cove.ape.*;
	public class DragableCircleParticle extends CircleParticle{
		private var mouseIsDown:Boolean;
		public function DragableCircleParticle(
				x:Number,
				y:Number,
				radius:Number,
				fixed:Boolean = false,
				mass:Number = 1,
				elasticity:Number = 0.3,
				friction:Number = 0){
			super(x, y, radius, fixed, mass, elasticity, friction);
			alwaysRepaint = fixed;
			mouseIsDown = false;
			sprite.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
			sprite.stage.addEventListener(MouseEvent.MOUSE_UP,mouseUpHandler);
			sprite.stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
		}
		private function mouseDownHandler(evt:MouseEvent):void{
			mouseIsDown = true;					// on mouse down set mouseIsDown to true
			curr.setTo(evt.stageX,evt.stageY);	// set the current position of the particle to the position of the mouse
			prev.setTo(evt.stageX,evt.stageY);	// set the previous position of the particle to the position of the mouse
		}
		private function mouseUpHandler(evt:MouseEvent):void{
			mouseIsDown = false;			// on mouse up set mouseIsDown to false
		}
		private function mouseMoveHandler(evt:MouseEvent):void{
			if(mouseIsDown){				// On mouse move if the mouse is down
				prev.copy(curr);			// set the previous position to the curent position of the particle
				curr.setTo(evt.stageX,evt.stageY);	// set the current position to the position of the mouse
			}
		}
		public override function update(dt2:Number):void {
			if(!mouseIsDown){		// Don't update if the mouse is down
				super.update(dt2);
			}
		}
	}
}

Posted in APE - Actionscript Physics Engine, Actionscript 3.


Craigslist RSS Reader with ItemRenderer

So, I simply wanted to learn more about the itemRenderer property of the List component and made a little .swf that will read different Craigslist.com RSS feeds. (crossdomain.xml issues will not allow this movie to work, but will from your desktop when published)

Within my Flex Project I have the following 2 files within my ’src’ folder.

The main file called: CragsListReaderFlex.mxml:



	
		

	

	
		
                  
                     
                     http://burlington.craigslist.org/rea/index.rss
                     http://burlington.craigslist.org/sys/index.rss
                   
		
	
	

	

	
	

and my itemRenderer called: CLListView.mxml:



	
	
	

Posted in Flex Web Development.


JQuery Thickbox – Dynamic Resizing of Windows

With much assistance of my good buddy Scott Nellé we were able to create a function that will dynamically resize the window dimensions when using the JQuery Thickbox plugin.

This function simply scans the page and looks for those anchor tags that have the class of thickbox, takes in the href attribute value, and then changes the height and width variables to a ratio of the users viewport dimensions.


Posted in Web Development.


Google Analytics/Tracking for Flash Elements

Just thought I would pass along this AS3 Library:

http://code.google.com/p/gaforflash/

Posted in manewc.com.


Flex and Cairngorm

I know that I am behind the times with Flex and this is a continual learning process, but I wanted to learn more about MVC structures and Flex. I chose to explore Cairngorm and found this site as a great launching pad for learning more:

http://www.davidtucker.net/category/cairngorm/

I am not sure how it compares to other frameworks like PureMVC or ARP (or any others), I just randomly chose Cairngorm to begin with, especially because David Tucker has great simple examples of usage.

Posted in manewc.com.