Packagecom.whirled.contrib.display
Classpublic class ClickAnimateFurniture
InheritanceClickAnimateFurniture Inheritance flash.display.Sprite

This class creates a furniture item which can respond to clicks and be animated. The preferred way to use it is to extend it. Ideally you should write a new class which extends this one and its constructor should call super() with an array of images, set the animations, set any desired flags, and then call start.

Generally speaking, unless you know what you are doing, you should stick to the public methods and members and avoid the protected ones. There is a tutorial in the wiki on how to use this class which includes examples.



Public Properties
 PropertyDefined by
  randomizeAnimations : Boolean
This is a flag which indicates whether or not the change in animations should be randomized or serial.
ClickAnimateFurniture
Protected Properties
 PropertyDefined by
  control : FurniControl
This is the furniture control.
ClickAnimateFurniture
  timer : Timer
This is the timer.
ClickAnimateFurniture
Public Methods
 MethodDefined by
  
ClickAnimateFurniture(images:Array)
The constructor.
ClickAnimateFurniture
  
This function restores the default behavior, which is that the furniture changes animation states every time it is clicked.
ClickAnimateFurniture
  
This function is used to cause the furniture to always return to its basic animation state.
ClickAnimateFurniture
  
makeSimpleAnimation(x:int):Array
[static] This creates a very simple default animation.
ClickAnimateFurniture
  
setAnimations(anims:Array):void
This function is used to set or reset the animations which will be used.
ClickAnimateFurniture
  
start():void
This function is used to start the furniture.
ClickAnimateFurniture
  
verifyAnimation(anim:Array):Boolean
[static] This function checks an individual animation array to ensure its correctness.
ClickAnimateFurniture
  
verifyAnimations(anims:Array):Boolean
[static] This routine verifies that the thing being passed as an animation really is an animation.
ClickAnimateFurniture
Protected Methods
 MethodDefined by
  
handleClick(event:Event):void
This is the callback for mouse clicks.
ClickAnimateFurniture
  
handleTimer(event:TimerEvent):void
This is the callback for the timer.
ClickAnimateFurniture
  
handleUnload(event:Event):void
This is the callback for when the furniture is unloaded.
ClickAnimateFurniture
  
memoryChanged(event:ControlEvent):void
This function is the callback for updates to the memory.
ClickAnimateFurniture
  
messageReceived(event:ControlEvent):void
This function is the callback for messages.
ClickAnimateFurniture
  
This gets called whenever things change.
ClickAnimateFurniture
Property detail
controlproperty
protected var control:FurniControl

This is the furniture control.

randomizeAnimationsproperty 
public var randomizeAnimations:Boolean

This is a flag which indicates whether or not the change in animations should be randomized or serial. By default it is false, indicating that the animations will be cycled through in order. If you set it to true, they will instead be cycled through in random order.

The default value is <code>false</code>.

timerproperty 
protected var timer:Timer

This is the timer. If you want to temporarily stop or pause the animations, the easiest way is to stop the timer and then start it when you want things to resume.

Constructor detail
ClickAnimateFurniture()constructor
public function ClickAnimateFurniture(images:Array)

The constructor.

Parameters
images:Array — An Array of DisplayObjects. Should be non-null, non-empty, and all contains objects should be subclasses of DisplayObject
Method detail
disableReturnToBaseAnimation()method
public function disableReturnToBaseAnimation():void

This function restores the default behavior, which is that the furniture changes animation states every time it is clicked. When the furniture is clicked, it changes animations and then runs the new animation over and over until the next time it gets cicked.

By default, returning to the base animation is disabled. This function does not need to be called unless enableReturnToBaseAnimation has been called.

enableReturnToBaseAnimation()method 
public function enableReturnToBaseAnimation():void

This function is used to cause the furniture to always return to its basic animation state. If this has been called, then the furniture item will carry out the first animation until it is clicked on. When clicked on, it will play another animation through once and then will return to the first animation. If randomization is enabled, the animation it plays will be random. Otherwise, it will play the animations in order, one for each click.

handleClick()method 
protected function handleClick(event:Event):void

This is the callback for mouse clicks. It handles changing the animations, notifying everyone else and where applicable, saving the change.

Parameters
event:Event
handleTimer()method 
protected function handleTimer(event:TimerEvent):void

This is the callback for the timer. It advances the frame, looping if necessary. If returnToBaseAnimation is true, it also detects when a given animation has finished and goes back to the base animation. It does not synchronize the return to the base animation with other instances because if some instances are running slower than others, we would still like them to be able to see the complete animation.

Parameters
event:TimerEvent
handleUnload()method 
protected function handleUnload(event:Event):void

This is the callback for when the furniture is unloaded. It handles clean-up.

Parameters
event:Event
makeSimpleAnimation()method 
public static function makeSimpleAnimation(x:int):Array

This creates a very simple default animation. This default animation is used in the event that no animation has been supplied or that the supplied animation was incorrectly formatter. In the default animation, the first x pictures which have been supplied are shown in order each for one half of a second.

It is not generally recommended that users call this. It is primarily here so that the furniture will do something in the case that no animation (or no properly formatted animation) is ever set.

Parameters
x:int — The number of frames to use.

Returns
Array
memoryChanged()method 
protected function memoryChanged(event:ControlEvent):void

This function is the callback for updates to the memory. It enables it to be the case that when one user clicks on the furniture, it changes which animation is being shown for everyone.

Parameters
event:ControlEvent
messageReceived()method 
protected function messageReceived(event:ControlEvent):void

This function is the callback for messages. It enables it to be the case that when one user clicks on the furniture, the same animation plays for everyone.

Parameters
event:ControlEvent
setAnimations()method 
public function setAnimations(anims:Array):void

This function is used to set or reset the animations which will be used. It should be called before start.

Parameters
anims:Array — The format for this input is somewhat complex, so bear with me. It takes an array as input. Each member of this array should be an animation. An animation is also an array. Each member of the animation array should be a frame. A frame is also an array. A frame is an Array of size 2. The first element is the frame number. This should be the index that the frame has in the image array passed to the constructor. The second element is the time in milliseconds for which the frame should be displayed. So essentially, anims is an Array of Arrays of Arrays of integers. If something other than this is given as input, errors will appear in the log and the default animation will be used instead.
start()method 
public function start():void

This function is used to start the furniture. Prior to this function being called, nothing will be displayed and nothing will happen. It should normally be called in the constructor of the superclass.

Before this function is called, setAnimation should be called and any behavior flags (randomizeAnimations, returnToBaseAnimation) should be set.

When called, this function does several things, including begining the first animation and registering the listeners for several events such as mouse clicks, communication with other instances, and timer events.

updateDisplay()method 
protected function updateDisplay():void

This gets called whenever things change. It changes which frame is being displayed and starts the timer for the new frame, if appropriate.

verifyAnimation()method 
public static function verifyAnimation(anim:Array):Boolean

This function checks an individual animation array to ensure its correctness. It is just a helper function for verifyAnimations to make the code cleaner. Generally, it is not expected that this routing will be used outside of this class, but it may be helpful for debugging if you are unsure which animation is not set up properly.

If the input is not properly formatted, specific information about the error can be found in the flash log file.

Parameters
anim:Array — A single animation Array. That is an Array of frames. Each frame is an array of two integers.

Returns
Boolean — Returns true is the animation is properly formatted. False otherwise.
verifyAnimations()method 
public static function verifyAnimations(anims:Array):Boolean

This routine verifies that the thing being passed as an animation really is an animation. If it does not conform to the description of an animation then this will be detected. This is a sanity check measure meant to protect against users who do not understand what they are doing. This would be unnecessary in a language with stronger typing. This function will not usually be called outside of this class, but it may be helpful for debugging in some cases.

If the input is not properly formatted, specific information about the error can be found in the flash log file.

Parameters
anims:Array — An array of animations. Each animation is itself an array of frames. Each frame is an arry of two integers.

Returns
Boolean