Skip to content


[AS 3] ShowRedrawRegions to Display Animated Paths

A simple way of actually seeing what your objects are doing as your timeline/events are playing. <strong>Enables the debugger version of Flash® Player to outline the regions of the screen that are being redrawn (that is regions that are being updated).</strong>

I used the old Ball.as class:

package {
	import flash.display.Sprite;

	public class Ball extends Sprite {
		public var radius:Number;
		private var color:uint;

		public var vx:Number = 0;
		public var vy:Number = 0;
		public var NewXPos:Number = 0;
		public var NewYPos:Number = 0;

		public function Ball(radius:Number=20, color:uint=0xb3d830) {
			this.radius = radius;
			this.color = color;
			init();
		}

		public function init():void {
			graphics.beginFill(color);
			graphics.drawCircle(0, 0, radius);
			graphics.endFill();
		}
	}
}

Here is the Document Class ShowRedrawRegions.as (don’t forget to use the UI Button Component by adding it to your library in your .fla file):

package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import fl.controls.Button;
	import flash.profiler.showRedrawRegions;

	public class ShowRedrawRegions extends Sprite
	{
		private var button:Button;
		private var ball:Ball;
		private var ballArr:Array;
		private var ct:uint;

		public function ShowRedrawRegions()
		{
			var ball:Ball = new Ball(20, Math.random() * 0xffffff);
			ball.x = ball.width;
			ball.y = ball.height + 10;
			addChild(ball);

			ballArr = new Array();
			ballArr.push(ball);

			buildUI();

			addEventListener(Event.ENTER_FRAME, animateBall);
			button.addEventListener(MouseEvent.CLICK, timeline);
		}

		private function buildUI():void
		{
			button = new Button();
			button.width = 250;
            button.height = 30;
            button.move ( stage.stageWidth / 2 - button.width / 2, stage.stageHeight / 2 - button.height / 2 );
            button.label = "Show Redraw Regions";
			addChild(button);
		}

		private function timeline(e:MouseEvent):void
		{
			ct++;  

			if (ct%2)
			{
				button.label = "Stop Animation";
				// addEventListener(Event.ENTER_FRAME, showRedraw);

				showRedrawRegions(true);
			}
			else
			{
				// end
				button.label = "Show Redraw Regions";
				// removeEventListener(Event.ENTER_FRAME, showRedraw);

				showRedrawRegions(false);
			}
		}

		private function animateBall(event:Event):void
		{
			if (ballArr[0].x < stage.stageWidth)
			{
				ballArr[0].x += 5;
			}
			else
			{
				ballArr[0].x = 0;
			}
		}

		private function showRedraw(event:Event):void
		{

		}
	}
}

Posted in Actionscript 3.


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.