Categories
Articles

Actionscript 3 Revolving Animation Around a Center Point

By Lon (Alonzo) Hosford

I was working through chapter 3 of Keith Peter’s Foundation Actionscript 3.0 Animation: Making Things Move and came up with this Rotator class that will revolve any sprite around a given point.

Keith Peters AS3 Animation
Learn More

[August 18 2010] I updated this to an ActionScript project to Flex Builder 4. Download the example code. You can build this with the free Flex SDK by using the code in the src folder. Same for Flash CS3 and CS4. You need to create a Flash Document in the src folder and set the document class to Chapter02_Factory_PrintCenters. For your convenience you can download a Flash CS4 ready to go example.

Application Class – Animation_Circular_Rotation
This is the application class. The actual use of the Rotator class is all done on lines 81 to 86 with the _rotator instance and the Circle class circle instance. The rest of this class is dedicated to user interaction with the keyboard to start, stop and step the animation and with informational feedback using the DebugConsole class.

The circle created on line 80 is what the Rotator class instance _rotator revolves. The Rotator class constructor requires the Sprite object it will revolve and the radius as shown on line 85.

/**
 *  Purpose: Animating a rotation motion in Actionscript 3
 *  <p>Author: Lon Hosford https://www.lonhosford.com 908 996 3773</p>
 *  <p>Version history:</p>
 *  <p>	Number:			1.00.00</p>
 *  <p>	Date:			06/15/2007</p>
 *  <p>	Programmer:		Lon Hosford: https://www.lonhosford.com</p>
 *  <p>	Changes:		Original programming</p>
 * */	

package
{
	import com.lonhosford.util.debug.lite.DebugConsole;
	
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.events.TimerEvent;
	import flash.system.Capabilities;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	import flash.ui.Keyboard;
	import flash.utils.Timer;
	

	[SWF(width=600, height = 770, frameRate = 30)]
	/**
	 *  Application class
	 * */	
	public class Animation_Circular_Rotation extends Sprite
	{
		private var _debugConsole:DebugConsole = DebugConsole.getInstance();
		public var maxDebugConsoleLines:Number = 500;				// Maximum lines in debug console.
																	// More line lowers performance.
		// Basic background - set your preference here
		public static const backgroundColor:Number = 0xcccccc;
		public static const backgroundBorderColor:Number = 0x666666;
		public static const backgroundBorderWidth:Number = 2;
		
		private var _rotator:Rotator;								// Rotation animator
		
		// Language
		private var _lang_clickStage:String = "Click stage to get keyboard focus.";
		private var _lang_enterKey:String = "ENTER starts and stops animation.";
		private var _lang_spacebar:String = "SPACE BAR increments animation one step. Auto repeats after delay.";
		private var _lang_debugCleared:String = "Debug window cleared every";
		private var _lang_debugClearedWhen:String = "lines when animating to maintain low memory.";
		private var _lang_traceDisabled:String = "Trace output suppressed when animation plays in Flash Control->Test Movie.";
		private var _lang_keyboardShortcuts:String = "In Flash after Control->Test Movie, select Control->Disable Keyboard Shortcuts.";
		// Space bar repeat timer
		private var _keySpacebarTimeDelay:Number = 350;					// Delay between each Keyboard.SPACE event.
		private var _keySpacebarTimer:Timer; 							// Timer for repeating Keyboard.SPACE events.

		public function Animation_Circular_Rotation()
		{
			// Set stage options
			initStage();
			// Create a background
			var backgroundRect:Shape = getRectShape(backgroundColor, backgroundBorderColor, backgroundBorderWidth, stage.stageWidth, stage.stageHeight)
			addChild(backgroundRect);
			
			// Add output monitor
			stage.addChild(_debugConsole);
			_debugConsole.width = stage.stageWidth;
			_debugConsole.height = stage.stageHeight * .25;
			_debugConsole.y = stage.stageHeight - _debugConsole.height;
			// Disable tracing to Flash External player. Tracing impairs performance.
			if ( Capabilities.playerType == "External")
			{
				_debugConsole.isTracing = false;
			}
			// Instructions
			var instruction_tf:TextField = instructionDisplay();
			addChild(instruction_tf);
			instruction_tf.x = (stage.stageWidth - instruction_tf.width) / 2;
			
			// Create sprite to rotate
			var circle:Circle = new Circle();
			
			// Create a rotator
			_rotator = new Rotator(circle, backgroundRect.width * .3);
			_rotator.x = (stage.stageWidth - _rotator.width) / 2;
			_rotator.y = instruction_tf.y + instruction_tf.height + 5;
			addChild(_rotator);
			_rotator.addEventListener(Event.ENTER_FRAME,rotatorEnterFrameEventHandler);
			
			// Use keyboard events to control the animation
			stage.addEventListener( KeyboardEvent.KEY_DOWN, keyPressed);
			stage.addEventListener( KeyboardEvent.KEY_UP, keyReleased);
			
			_keySpacebarTimer = new Timer(_keySpacebarTimeDelay,1); 
			_keySpacebarTimer.addEventListener(TimerEvent.TIMER, keySpacebarTimerEventHandler);
		}

[ad name=”Google Adsense”]


		/**
		 * Set any stage options per your needs
		 * */
		private function initStage():void 
		{ 
			stage.scaleMode = StageScaleMode.NO_SCALE;
		}
		/**
		 * Instructions display.
		 * */
		private function instructionDisplay():TextField 
		{
			var instructions_tf:TextField = new TextField();		
			var format:TextFormat = new TextFormat();
			format.font = "_typewriter";
			format.color = 0x000000;
			format.size = 12;
			format.indent = 2;
			instructions_tf.defaultTextFormat = format;
			instructions_tf.border = true;
			instructions_tf.borderColor = 0x000000;
			instructions_tf.background = true;
			instructions_tf.backgroundColor = 0xffffff;
			instructions_tf.autoSize = TextFormatAlign.LEFT
			instructions_tf.appendText(_lang_clickStage + "\n");
			instructions_tf.appendText(_lang_enterKey + "\n");
			instructions_tf.appendText(_lang_spacebar + "\n");
			instructions_tf.appendText(_lang_debugCleared + " " + maxDebugConsoleLines + " " + _lang_debugClearedWhen + "\n");
			instructions_tf.appendText(_lang_traceDisabled + "\n");
			instructions_tf.appendText(_lang_keyboardShortcuts);
			
			return instructions_tf;
		}
		/**
		 * Handler for KeyboardEvent.KEY_DOWN
		 * */
		private function keyPressed(evt:KeyboardEvent):void 
		{
			
			switch (evt.keyCode)
			{
				case Keyboard.SPACE:
					
					if (!_keySpacebarTimer.running)
					{
						_keySpacebarTimer.start();
					}	
					break;
			}
		}
		/**
		 * Handler for KeyboardEvent.KEY_UP 
		 * */
		private function keyReleased(evt:KeyboardEvent):void 
		{
			switch (evt.keyCode)
			{
				case Keyboard.SPACE:
					if (_keySpacebarTimer.running)
					{
						_keySpacebarTimer.stop();
						_keySpacebarTimer.reset();
					}
					if (_rotator.isPlaying)
					{
						_rotator.stop();
					}
					else
					{
						_rotator.step();
					}
					
					break;
				case Keyboard.ENTER:
					if (_rotator.isPlaying)
					{
						_rotator.stop();
					}
					else
					{
						_rotator.start();
					}
					break;
			}
		}
		/**
		 * Handler for TimerEvent.TIMER event. Resets the delay interval once the default delay 
		 * is reached.
		 * */
		private function keySpacebarTimerEventHandler(event:TimerEvent):void 
		{
			_rotator.start();
		}
		/**
		 * Handler for _rotator Event.ENTER_FRAME event. 
		 * */
		private function rotatorEnterFrameEventHandler(event:Event):void 
		{
			clearDebugConsoleFlashExternalPlayer();
		}
		/**
		 * Handles slower processing in Flash external player Control->Test Movie
		 * and clears debugConsole when 100 lines are reached.
		 * */
		
		private function clearDebugConsoleFlashExternalPlayer():void
		{
			if (_debugConsole.contentLineCount > maxDebugConsoleLines && _rotator.isPlaying )
			{
				_debugConsole.clear();
				
			}
		}
		/**
		 * Utility to draw a rectangle Shape object 
		 * */
		private function getRectShape(bgColor:uint, borderColor:uint, borderSize:uint, width:uint, height:uint):Shape 
		{
			var newShape:Shape = new Shape();
			newShape.graphics.beginFill(bgColor);
			newShape.graphics.lineStyle(borderSize, borderColor);
			newShape.graphics.drawRect(0, 0, width, height);
			newShape.graphics.endFill();
			return newShape;
		}
	}
}

Rotator Class
This is the class that does the rotation. The main work is done in the move() method on lines 154 – 187. Comments tell what each step accomplishes. The lines past 187 in the move() method are for information only and can be deleted. The move() method only advances the animation one step defined by the _vr variable on line 38. Increase the _vr variable will speed up the animation and decreasing slows the animation down. As an exercise you could make this a speed option via a setter method and the constructor.

The init() method on lines 74 to 94 set the sprite to animate inside a rectangular boundary.

package
{
	import com.lonhosford.util.debug.lite.DebugConsole;
	import com.lonhosford.util.debug.lite.Debugger;
	
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	
	/**
	 *  Purpose: Circular rotation of a sprite around a radius
	 *  <p>Author: Lon Hosford www.lonhosford.com 908 996 3773</p>
	 *  <p>Version history:</p>
	 *  <p>	Number:			1.00.00</p>
	 *  <p>	Date:			06/15/2007</p>
	 *  <p>	Programmer:		Lon Hosford: https://www.lonhosford.com</p>
	 *  <p>	Changes:		Original programming</p>
	 * */	
	public class Rotator extends Sprite
	{
		/**
		 * A sprite object to rotate
		 * */
		private var _spriteToRotate:Sprite;
		/**
		 * Current angle in radians. 
		 * */
		private var _angle:Number = 0;  
		/**
		 * Radius of rotation. 
		 * @default 150
		 * */
		private var _radius:Number;
		/**
		 * Velocity of the angle change in radians. 
		 * @default .05
		 * */
		private var _vr:Number = .03; // Radians
		/**
		 * Center of rotation for x.
		 * */
		private var _centerX:Number;
		/**
		 * Center of rotation for y.
		 * */
		private var _centerY:Number;
		/**
		 * Coordinate x for _spriteToRotate.
		 * */
		private var _coordinateX:Number;
		/**
		 * Coordinate y for _spriteToRotate.
		 * */
		private var _coordinateY:Number;
		/**
		 * Animation is playing.
		 * */
		private var _isPlaying:Boolean = false;
		private var debugConsole:DebugConsole = DebugConsole.getInstance();
		/**
		 * Constructor
		 * @param radius see _radius
		 * */
		public function Rotator(spriteToRotate:Sprite, radius:uint = 150)
		{
			_spriteToRotate = spriteToRotate;
			_radius = radius;
			
			init();
		}

[ad name=”Google Adsense”]

		/**
		 * Initialize the class
		 * */
		private function init():void
		{
			var boundaryBorderWidth:Number = 1
			// Create a boundaries object to set container height and width 
			var boundaries:Shape = new Shape();
			boundaries.graphics.beginFill(0xcccccc, 0);
			boundaries.graphics.lineStyle(boundaryBorderWidth, 0x000000, 0);
			boundaries.graphics.drawRect(0, 0, _radius * 2 + _spriteToRotate.width , _radius * 2 + _spriteToRotate.height );
			boundaries.graphics.endFill();
			addChild(boundaries);
			
			// Compute the center of container
			_centerX = (boundaries.width - boundaryBorderWidth)/2 ;
			_centerY = (boundaries.height - boundaryBorderWidth)/2  ;
			
			// Set starting position for sprite to rotate
			
			// Add sprite
			_spriteToRotate.alpha = .5;
			addChild(_spriteToRotate);
			move();
			
			/*----------------------------------------------------------------------
			Start statistical data for information only.
			Can delete for actual implementations
			----------------------------------------------------------------------*/		
			debugConsole.write("\n");
			debugConsole.write("Rotator.init() - width:" + width);
			debugConsole.write("Rotator.init() - height:" + height);
			debugConsole.write("Rotator.init() - _angle:" + _angle);
			debugConsole.write("Rotator.init() - _radius:" + _radius);
			debugConsole.write("Rotator.init() - Math.cos(_angle):" + Math.cos(_angle));
			debugConsole.write("Rotator.init() - Math.sin(_angle):" + Math.sin(_angle));
			/*----------------------------------------------------------------------
			End statistical data for information only.
			Can delete above for actual implementations
			----------------------------------------------------------------------*/		
		}
		/**
		 * Handler for Event.ENTER_FRAME events
		 * */
		private function onEnterFrame(event:Event):void
		{
			move();
		}
		/**
		 * Get the playing status
		 * */
		public function get isPlaying():Boolean
		{
			return _isPlaying;
		}
		/**
		 * Starts the animation.
		 * */
		public function start():void
		{
			_isPlaying = true;
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}
		/**
		 * Stops the animation.
		 * */
		public function stop():void
		{
			_isPlaying = false;
			removeEventListener(Event.ENTER_FRAME, onEnterFrame);
		}
		/**
		 * Animates one unit of velocity.
		 * */
		public function step():void
		{
			stop();
			move();
		}

[ad name=”Google Adsense”]

		/**
		 * Animates one velocity unit.
		 * <p>Performs computations for rotation and moves sprite object</p>
		 * */
		private function move():void
		{
			/*----------------------------------------------------------------------
			Sprite coordinates
			----------------------------------------------------------------------*/		
			var _coordinateX:Number = _centerX + Math.cos(_angle) * _radius;
			var _coordinateY:Number = _centerY + Math.sin(_angle) * _radius;
			/*----------------------------------------------------------------------
			Position sprite object
			----------------------------------------------------------------------*/	
			_spriteToRotate.x = _coordinateX;
			_spriteToRotate.y = _coordinateY;
			/*----------------------------------------------------------------------
			Augment the angle by the velocity
			----------------------------------------------------------------------*/		
			_angle += _vr;
			/*----------------------------------------------------------------------
			Draw triangle
			----------------------------------------------------------------------*/		
			graphics.clear();
			graphics.lineStyle(1);
			/*----------------------------------------------------------------------
			Draw hypotenuse
			----------------------------------------------------------------------*/		
			graphics.moveTo( _coordinateX, _coordinateY );
			graphics.lineTo(_centerX, _centerY);
			/*----------------------------------------------------------------------
			Draw adjacent leg
			----------------------------------------------------------------------*/		
			graphics.lineTo(_coordinateX , _centerY);
			/*----------------------------------------------------------------------
			Draw opposite leg
			----------------------------------------------------------------------*/		
			graphics.lineTo(_coordinateX, _coordinateY);
			
			/*----------------------------------------------------------------------
			Start statistical data for information only.
			Can delete for actual implementations.
			dx and dy are not used in the class.
			----------------------------------------------------------------------*/		
			debugConsole.write("\n");
			debugConsole.write("Rotator.move() - _vr:" + _vr);
			debugConsole.write("Rotator.move() - _angle:" + _angle);
			debugConsole.write("Rotator.move() - _coordinateX:" + _coordinateX);
			debugConsole.write("Rotator.move() - _coordinateY:" + _coordinateY);
			debugConsole.write("Rotator.move() - _centerX:" + _centerX);
			debugConsole.write("Rotator.move() - _centerY:" + _centerY);
			var dx:Number = _centerX - _coordinateX;
			var dy:Number = _centerY - _coordinateY;
			debugConsole.write("Rotator.move() - Length: hypotenuse:" + ( Math.sqrt(dx * dx + dy * dy)  ));
			dx = _centerX - _coordinateX;
			dy = 0;
			debugConsole.write("Rotator.move() - Length: adjacent leg:" + ( Math.sqrt(dx * dx + dy * dy)  ));
			dx = 0;
			dy = _centerY - _coordinateY;
			debugConsole.write("Rotator.move() - Length: adjacent leg:" + ( Math.sqrt(dx * dx + dy * dy)  ));
		
			/*----------------------------------------------------------------------
			End statistical data for information only.
			Can delete above for actual implementations
			----------------------------------------------------------------------*/		
			
		}
	}
}

Circle Class
This is the sprite that is revolving in the animation.

package {
	import flash.display.Sprite;
	/**
	 *  Purpose: Draw a circle in a Sprite
	 *  <p>Author: Lon Hosford www.lonhosford.com 908 996 3773</p>
	 *  <p>Version history:</p>
	 *  <p>	Number:			1.00.00</p>
	 *  <p>	Date:			06/15/2007</p>
	 *  <p>	Programmer:		Lon Hosford: https://www.lonhosford.com</p>
	 *  <p>	Changes:		Original programming</p>
	 * */	
	public class Circle extends Sprite {
		/**
		 * Radius of the circle. 
		 * @default 40	
		 * */
		private var _radius:Number;
		/**
		 * Fill color. 
		 * @default 0x000000	
		 * */
		private var _color:uint;
		/**
		 * Constructor.
		 * @param radius See _radius
		 * @param color See _color
		 * */
		public function Circle(radius:Number=40, color:uint=0x000000) 
		{
			_radius = radius;
			_color = color;
			
			init();
			
		}
		/**
		 * Initialize the class
		 * */
		public function init():void 
		{
			draw();
		}
		/**
		 * Draw class graphics
		 * */
		public function draw():void 
		{
			graphics.clear();
			graphics.beginFill(_color,alpha);
			graphics.drawCircle(0, 0, _radius);
			graphics.endFill();
		}
	}
}
Categories
Articles

Apollo is Now Air: Adobe Integrated Runtime

Adobe has announced a beta for Apollo. With it is a name change with a trademark. The new name is AIR standing for Adobe Integrated Runtime. As well in beta is Flex 3.

Adobe describes AIR as follows:

“AIR is a cross-operating system runtime that allows developers to use their existing web development skills to build and deploy rich Internet applications to the desktop. “

You can get the information and downloads at Adobe labs.

Categories
Articles

Adobe AsDoc -doc-sources

I was experimenting with the Adobe ASDoc tool. Adobe uses it for its on-line API documentation for Flex, Apollo and Actionscript.

In my case I had a com folder with my own domain, com.hosford. I also had com.otherDomains from various sources such as books I purchased where the author provided a library of code.

I wanted to create the docs for all of the com.hosford portion and not include other com.otherDomains. In fact I wanted to limit the docs to com.hosford.practice. This is a place for examples and experiments and future code snippets, a play area.

The folder layout is as follows:

com/hosford/practice/… various

apps/practice

In apps/practice is the command file for ASDocs. I wanted ASDocs to create a folder called Practice-Docs in apps/practice.

The ASDocs switch to use was -doc-sources. The command line in a Windows batch file worked out as follows (all on one line):

"C:\Program Files\Adobe\Flex Builder 2\Flex SDK 2\bin\asdoc.exe" "-doc-sources" "../../com/hosford/practice" "-main-title" "Practice API Documentation" "-window-title" "Practice API Documentation Window Title" "-output" "Practice-Documentation"

More information on ASDocs as follows:

ASDocs Documentation

ASDocs -doc-sources

Categories
Articles

Using MXMLC for Sharing Common Libraries

When using mxmlc (the Flash Flex AS3 command line compiler) I wanted to create a folder structure for sharing a common libraries but for different examples and apps that have their own sibling folders. This would keep the parent folder of both the library and the apps clean.

Ex:

com.hosford.core

com.hosford.controls

apps.clock

apps.diceRoller

I use Windows and batch files for mxmlc. I prefer to copy a new version of the batch for each need and edit rather than type at the command line. Thus I can just click the batch file in a Window for each iteration.

I also do not use any environment variables so the batch file allows for hard paths were needed.

Assume in apps.clock the source file was ClockApp.as

Its package would be:

package apps.clock{

The imports are as you can expect:

import com.hosford.controls.* 

The mxmlc line is in a Windows batch file is as follows:

"C:\Program Files\Adobe\Flex Builder 2\Flex SDK 2\bin\mxmlc.exe" "-source-path+=../../" "-file-specs=ClockApp.as"


The -source-path option is the item that allows ClockApp.as to find the com libraries. The += adds to any environment path you also have.

Adobe Apollo Beta First Trys

Well I am into trying the Adobe Apollo beta. So cool. Flash or Flex apps on the desktop. Internet apps on the desktop. So so cool!

The Adobe Apollo Runtime Demos

I had fun with the few complete demos in Adobe labs. These are completed Apollo applications. You only need to download the Apollo runtime. Then you can download and install the samples on the same page.

Creating Adobe Apollo Applications

Apollo is an extension of the Actionscript 3/ Flex 2 language. Or said another way, Actionscript 3 and Flex are a subset of the Apollo language since Apollo also allows Javascript and HTML as an application development component. A matter of perspective. But you can see knowing Actionscript 3, Flex 2, HTML, Java are important as they can be part of the Apollo application.

The Adobe Apollo SDK

I had already installed the Flex 2.01 SDK and using it a lot to get a guerrilla warfare (no IDE) experience with Flex and Actionscript 3. Flex has a command compiler (mxml compiler) to generate the swf. You can use it to create Actionscript only UI, Flex only UI or combinations. The language is Actionscript 3.

One task very helpful to this I did recently was to go through every Flex QuickStart example on the Adobe site.

Apollo SDK installs over the Flex 2.01 if you have it installed. It simply extends the Actionscript 3/ Flex 2 language with classes or members to existing classes for the OS UI (like desktop windows) , OS file system (reading and writing to files) and more for OS interfacing.

Adobe Apollo also has a command line compiler (amxml compiler) to generate a swf. Then it has a command line debug launcher (adl or Apollo Debug Launcher) so you can test the application without installing it on your system.

For packaging, there is the (adt Apollo Developer Tool) for packaging into an AIR file. The AIR file is a zip compressed file for installation. Clicking on it with the Apollo run time installed will start the installation of your application.

In general the install was tricky because it needed CLASSPATH and PATH statements updated. I was able to avoid those with just the Flex 2 SDK.

The Adobe Apollo Hello World Application

Since I was focused on command line learning with Flex I found the Create your first Flex-based Apollo application using the Apollo SDK page very helpful.

Adobe Apollo Documentation

The key page I found helpful is Adobe Apollo Documentation. This is not really a documentation page. Rather it is more a index to documentation and pages depending on your needs. You can get to the API documentation from here if that is useful. It has the lower left class window with the Apollo icon for the additional API over and above that used in Flex and Flash apps.

Tip for Windows Batch Files Command Line Processing

In Windows if you are using your own batch files to process the command lines you will find the command window may close before you see Apollo errors. You need to place pause statements in the adl.bat, adt.bat and amxmlc.bat in the Adobe\Flex Builder 2\Flex SDK 2\bin folders.

Categories
Articles

FlashTracer Extension For Firefox

Debugging Flash in a Web browser creates all sorts of issues and clever solutions. Anywhere to having one Flash movie talk to another through LocalConnection, to a floating TextField or TextArea object or Movie containing such with a grabber and perhaps some buttons to using the difficult built in remote debugging built-in.

Adobe now has a Flash Debugger version. One of its features is outputting the trace function to a local file. A bit geeky on how to go about setting up that but it can be done. And so others have created solutions already.

One solution is FlashTracer. This is a Firefox plug-in that uses the Flash debugger version.

Once installed you will be seeing trace statements from the millions of Flash Movies on the Internet where the publishers failed to check “Omit trace actions” on their final publish.

But more so you can debug tricky client server Flash web apps quicker seeing your trace statements in a Window.

FlashTracer Version 2.0 download Note the Mozilla plug-in page has the older 1.3.1 1 version of FlashTracer.Flash Player Debug Version Download

The author is Alessandro Crugnola in case the links above get moved.

A good instructional site that covers installation and use is Flash PowerTools: FlashTracer for Firefox just be careful as the links here take you to the Firefox plug-in pages and that has the older 1.3.1 1 version of FlashTracer.

Just be careful as the links here take you to the Firefox plug-in pages and that has the older 1.3.1 1 version of FlashTracer. Other than the download links, follow the few short instructions here and you are good. The instructions do not cover the new features in 2.0 however but the product is relatively simple with just a few buttons and options.

After the plug-in installation, the instructions have you enter in a path that you modify to the location and name of the output file.

In my case the path was: C:\Documents and Settings\MyUserName\Application Data\Macromedia\Flash Player\Logs\flashlog.txt

You also can open this same output file in an editor like Dreamweaver or TextPad and use their search functionality. The file will update as you are using Flash movies in FireFox as well.

Categories
Articles

Actionscript 3 Language Features

Actionscript 2 (AS 2) is great! Actionscript 3 (As 3) is even better. Some of the benefits you might find pleasing include:

Runtime exception reporting

This allows the developer to see runtime failures in the code. Actionscript 2 fails silently when running to protect the user from seeing developer intended error messages.

EMCAScript for XML (E4X)

This basically means XML handling is built into the language. You can avoid parsing XML into object trees as it is automatic.

Regular Expressions

At last fast manipulation and processing of string. No more loops to trim spaces for example.

New Primitive Types

Number is the data type in AS 2.0. With AS 3.0 you have int for example that will take advantage of faster CPU math processing features.

Decomposed Display API

The display API is not soley dependent on the bulging MovieClip class. A lighter Sprite class is available. As well there is a Shape class to remove all that vector drawing code. So for basic vector shape UI items you can use the Sprite and Shape class and drop the overhead of the MovieClip class.

Event Handling is part of the Language

In AS 2.0 we needed to use additional code to register event listener. This was found deep in the Component documentation as the EventDispatcher and Delegate classes. In AS you had to build the equivalent of these for your projects and use the Function class methods for the call backs as one technique.

Categories
Articles

Flash Simulations for Flash Animation and Interaction Development

Flash is very useful for creating simulations. One example I did was for the Avaya IP office phones.

The use of Flash for simulations is wide open territory of potential.

Using Flash to Simulate Flash

One use I think requires serious consideration is using Flash to simulate Flash development. With the widespread move to developing complex applications with Flash we find the problem of successfully communicating the interactivity and animation timings of creative ideas.

Add to that requirement the Flash movies dynamically consuming and generating data. The data may include user data such as ecommerce but could also be UI data to configure the UI dynamically. In other words they cannot be hand coded on the time lines in Flash. Rather the interaction and animation is communicated to software programmers to reproduce in Actionscript that consume data from a server for the dynamic processing.

The High Cost and Failure of Flash Development

This communication from creative to developers is where you have a lot of failure or at least a lot of costly repetitions. WE have various vehicles such as storyboards and “comps” and flow charts and use cases to help in the process.

The programmer produces from these communication vehicles the end product. A good programmer can produce exactly what was requested. Therein the problem begins. You can get what you ask for which is not what you think you want.

Often the finished result fosters reconsideration because a moving picture is worth a thousand words. Details such as how fast a fade out of an item like unselected menu choices or when another item such as the selected menu choice should begin to move becomes more visual as the programmer delivers your request.

Although such a simple set of animations seems easy to envision, it becomes more complicates as there is a need to also slide in a grid of product items from one direction and then fade out a background and more and more until words and screen shots fail your imagination.

Your  observation of what the programmer delivers then leads to the need to change it. Change then results in more costs and delays because the resource you are using for the iterative review need is incorrectly choosen.

Lack of Skills In Communicating Animation and Interactivity

In a project with a major international consumer products company I met very creative marketing talent. They had vast resources and skills for dealing with print and broadcast media. They along with interactive consultants also could envision very creative ideas for interactivity and animation on a broad level. Dealing with the details however revealed a handicap.

They used their expert skills in design communication in these medias to design a large rich internet application upgrade for their web site. During the development process completed complex Flash code was changed over and over as the review process produced a need to change.

Now you might say that is not a good. But in the case of a consumer products company, spending time and money to get it right for marketing is key. Despite creative visions they had on the broad scale, the details were missing. Somewhat like watching a movie over and over and seeing something new each time. Well that is what animation and interactive design is about.

Still this process of iterations to get it right resulted in delays and frustrations because they were missing an important step.

How to Use Flash Simulations in Flash Development

Along the way I recommended a solution. Continue to use the current communication vehicles such as Powerpoint storyboards and Photoshop renderings. However add one step between those and the programmer. That is to use Flash to simulate.

Simulation allows for viewing the end result without the pain of producing the full working model. To do this efficiently you simply use the standard Flash IDE. You can even use junior college students with Flash skills to take the story boards, graphics and do some or all of the work.

Simulations may or may not allow interaction. For example the simulation may start after a user interaction and merely show the sequence of events up to the next step. This is how storyboards are used. The storyboard shows the key frames. The animators make the in between frames.

Once the Flash simulation is complete, everyone can view and comment. The simulation can then be modified cheaply from tweaking to showing more detail to get it right.

Then the simulation along with the other supporting communication documentation become the starting material for the Flash programmer.

The result is less programming resources, better software and less frustration trying to visualize the end result.