Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Chrysto

Use TransformManager as RuntimeDebugger - my snippet

Recommended Posts

Hi;

 

Sometimes a client come and asks you "what if this picture is a little big bigger" , or "I'm sure it will looks better if this button was 10 pixels right from..."

 

For all of you, who have the awsome TransformManager, here's little snipper for you:

package  bassta.debug {

import com.greensock.transform.TransformManager;
import com.greensock.events.TransformEvent;
import com.greensock.transform.TransformItem;
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.display.Sprite;

public class MagicDebugger {

	private static var t:TransformManager;
	private static var c:Vector. = new Vector.

	public function MagicDebugger() {
		throw new Error("Use only with it's static methods");
	}

	public static function create(debuggedObject:DisplayObjectContainer):void{

		if(c.indexOf(debuggedObject) == -1){

			c.push(debuggedObject);

			t = new TransformManager();
			t.allowDelete = true;
			t.allowMultiSelect = true;
			t.arrowKeysMove = true;
			t.forceSelectionToFront = false;
			t.lockScale = false;
			t.scaleFromCenter = false;

			var i:int = debuggedObject.numChildren;
			for ( i >= 0; i--; ) {
				var s:DisplayObject = debuggedObject.getChildAt(i);
				t.addItem(s);
				t.getItem(s).addEventListener(TransformEvent.FINISH_INTERACTIVE_MOVE, outputChange);
				t.getItem(s).addEventListener(TransformEvent.FINISH_INTERACTIVE_ROTATE, outputChange);
				t.getItem(s).addEventListener(TransformEvent.FINISH_INTERACTIVE_SCALE, outputChange);
				t.getItem(s).addEventListener(TransformEvent.MOVE, outputChange);
			}
		} else {
			trace("Duplication Found");
		}
	}

	private static function outputChange(event:TransformEvent):void{
		var currentItem:TransformItem = (event.currentTarget as TransformItem);
		trace("Child [ " + currentItem.targetObject.name + " ] with bounds: { x: " 
			  + Math.ceil(currentItem.x)
			  + ", y:" + Math.ceil(currentItem.y) 
			  + ", width: " + Math.ceil(currentItem.width) 
			  + ", height: " + Math.ceil(currentItem.height)
			  + ", rotation: " + Math.ceil(currentItem.rotation) + " }");
	}

	public static function releaseManager():void{
		t.destroy();
		c.splice(0,c.length);
	}

	//getter, return the manager

	public static function manager():TransformManager{
		return t;
	}

}//end
}

 

 

Demo: http://burnandbass.com/demo15/

 

Just use MagicDebugger.create(this.stage) for example and transform all children of the stage The code does not do recursion, so only the childs (not their inner childs) will be applied for the manager

 

For more snippers - check me in http://www.facebook.com/bassta

If you are developing websites using SWFAddress, stay tuned for my "bassta debugger", demo - http://burnandbass.com/maggi (upper left corner), it has memory monitor, flash logging (DebugPanel.log(message), use it instead of (trace) for browser testing), grawl like notifications, rulers and many more things to come :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×