Package | ardisia.components.calculator |
Class | public class Calculator |
Inheritance | Calculator ![]() |
Implements | mx.managers.IFocusManagerComponent |
View the technical documentation on the Ardisia Labs website for more information.
Property | Defined By | ||
---|---|---|---|
animationDuration : Number = 150
The duration of each animation (animating out and animating in). | Calculator | ||
easer : IEaser
The easer to use for animations. | Calculator | ||
fractionalDigits : int = 5
The maximum number of digits after the decimal to display after an
expression is evaluated. | Calculator | ||
value : Number
The last committed value. | Calculator |
Method | Defined By | ||
---|---|---|---|
dispose():void
Remove the component from the display list and prepare it for GC. | Calculator |
Method | Defined By | ||
---|---|---|---|
animationHandler(event:EffectEvent):void
Handles the end of the first part of the animation. | Calculator | ||
backspaceButtonPartHandler(event:Event):void
Handles events on the backspaceButtonPart. | Calculator | ||
buttonsHandler(event:Event):void
Handles events on the skin part buttons. | Calculator | ||
calculateButtonPartHandler(event:Event):void
Handles events on the calculateButtonPart. | Calculator | ||
clear():void
Call to clear the value and display label. | Calculator | ||
clearButtonPartHandler(event:Event):void
Handles events on the clearButtonPart. | Calculator | ||
convertStringToArray(str:String):Array
Parses a string into an array by splitting it via the operators present. | Calculator | ||
displayLabelPartHandler(event:Event):void
Handles events on the displayLabelPart. | Calculator | ||
evaluateExpression(expression:String):Number
Takes the expression, evaluates it, and returns the number or NaN. | Calculator | ||
evaluateOperator(values:Array, operatorsArray:Array):Array
Walks the expression parsed into an array, and evaluates left to right
based on the passed operators. | Calculator | ||
finalAnimationHandler(event:EffectEvent):void
Handles the end of the 2nd part of the animation. | Calculator | ||
isDecimalMark(value:String):Boolean
Returns whether the passed symbol is a decimal mark. | Calculator | ||
isOperand(value:Object):Boolean
Check if the passed value is an operand, or an Operator. | Calculator | ||
keyDownHandler(event:KeyboardEvent):void [override]
Handles keyboard input when the calculator has focus. | Calculator | ||
searchForOperators(haystack:String, needle:String, replacementNeedle:String, delimiter:String):String
Searches the expression for the passed operator and inserts the
replacement string and a delimiter in its place. | Calculator | ||
setValue(value:Number):void
Update the value property and any bindings. | Calculator | ||
update():void
Call to evaluate the current expression and update the value. | Calculator | ||
updateDisplayLabelPart():void
Update the display label skin part. | Calculator | ||
validation():void
Validates the expression after each change to the DisplayLabelPart. | Calculator |
Event | Summary | Defined By | ||
---|---|---|---|---|
Dispatched when the "value" property changes via user interaction. | Calculator | |||
Dispatched when the "value" property changes for any reason. | Calculator |
This component uses skins made up of skin parts. Do not set the skin parts directly. The component's skin sets the skin parts.
To skin the component, implement a skin that defines the following states. Although you must implement all skin states, a skin state can be empty. An empty skin state specifies no changes to the default skin state.
Skin State | Description | Defined By | ||
---|---|---|---|---|
disabled | Calculator | |||
normal | Calculator |
animationDuration | property |
public var animationDuration:Number = 150
The duration of each animation (animating out and animating in). Set to 0 to skip the animation.
This animationDuration is applied twice in a sequence. E.G. the total animation duration is double this value.
The default value is 150
.
easer | property |
public var easer:IEaser
The easer to use for animations.
The default value is Sine(0.5)
.
fractionalDigits | property |
public var fractionalDigits:int = 5
The maximum number of digits after the decimal to display after an expression is evaluated.
The default value is 5
.
value | property |
value:Number
The last committed value. Commits occur when an expression is evaluated.
This property is bindable.
The default value is 0
.
This property can be used as the source for data binding.
public function get value():Number
public function set value(value:Number):void
animationHandler | () | method |
protected function animationHandler(event:EffectEvent):void
Handles the end of the first part of the animation. Starts the 2nd half of the cash register animation.
Parameters
event:EffectEvent |
the — that triggered the handler
|
backspaceButtonPartHandler | () | method |
protected function backspaceButtonPartHandler(event:Event):void
Handles events on the backspaceButtonPart.
Parameters
event:Event — the Event that triggered the handler
|
buttonsHandler | () | method |
protected function buttonsHandler(event:Event):void
Handles events on the skin part buttons.
Parameters
event:Event — the Event that triggered the handler
|
calculateButtonPartHandler | () | method |
protected function calculateButtonPartHandler(event:Event):void
Handles events on the calculateButtonPart.
Parameters
event:Event — the Event that triggered the handler
|
clear | () | method |
protected function clear():void
Call to clear the value and display label.
clearButtonPartHandler | () | method |
protected function clearButtonPartHandler(event:Event):void
Handles events on the clearButtonPart.
Parameters
event:Event — the Event that triggered the handler
|
convertStringToArray | () | method |
protected function convertStringToArray(str:String):Array
Parses a string into an array by splitting it via the operators present.
Parameters
str:String — the String to parse
|
Array — the parsed array
|
displayLabelPartHandler | () | method |
protected function displayLabelPartHandler(event:Event):void
Handles events on the displayLabelPart.
Parameters
event:Event — the Event that triggered the handler
|
dispose | () | method |
public function dispose():void
Remove the component from the display list and prepare it for GC.
evaluateExpression | () | method |
protected function evaluateExpression(expression:String):Number
Takes the expression, evaluates it, and returns the number or NaN.
Parameters
expression:String — the expression as a String
|
Number |
evaluateOperator | () | method |
protected function evaluateOperator(values:Array, operatorsArray:Array):Array
Walks the expression parsed into an array, and evaluates left to right based on the passed operators.
Parameters
values:Array — the expression parsed as an array
| |
operatorsArray:Array — the array of Operators to evaluate
|
Array — the modified passed values array
|
finalAnimationHandler | () | method |
protected function finalAnimationHandler(event:EffectEvent):void
Handles the end of the 2nd part of the animation.
Parameters
event:EffectEvent |
the — that triggered the handler
|
isDecimalMark | () | method |
protected function isDecimalMark(value:String):Boolean
Returns whether the passed symbol is a decimal mark. E.G. whether it is a "." in the anglosphere (is the USA part of the anglosphere? -> YES, but the USA is not in the Commonwealth) or "," everywhere else.
Parameters
value:String — the String to test
|
Boolean |
isOperand | () | method |
protected function isOperand(value:Object):Boolean
Check if the passed value is an operand, or an Operator.
Parameters
value:Object — the Object to check
|
Boolean — a Boolean
|
keyDownHandler | () | method |
override protected function keyDownHandler(event:KeyboardEvent):void
Handles keyboard input when the calculator has focus. Handles the basic calculator keys like ENTER, BACKSPACE, ESCAPE, "=" and the basic symbols.
Parameters
event:KeyboardEvent — the KeyboardEvent that triggered the handler
|
searchForOperators | () | method |
protected function searchForOperators(haystack:String, needle:String, replacementNeedle:String, delimiter:String):String
Searches the expression for the passed operator and inserts the replacement string and a delimiter in its place.
Parameters
haystack:String — the String to search
| |
needle:String — the String to search for
| |
replacementNeedle:String — the String to replace the needle with
| |
delimiter:String — the String to wrap the replacement needle around
|
String — the new String
|
setValue | () | method |
protected function setValue(value:Number):void
Update the value property and any bindings. Does not invalidate properties.
Parameters
value:Number — the Number to set
|
update | () | method |
protected function update():void
Call to evaluate the current expression and update the value.
updateDisplayLabelPart | () | method |
protected function updateDisplayLabelPart():void
Update the display label skin part.
validation | () | method |
protected function validation():void
Validates the expression after each change to the DisplayLabelPart.
Checks that the expression makes sense. Also, applies the emptyString as needed and clears the expression based on internal flags.
change | Event |
ardisia.components.calculator.events.CalculatorEvent
ardisia.components.calculator.events.CalculatorEvent
Dispatched when the "value" property changes via user interaction.
valueCommit | Event |
mx.events.FlexEvent
mx.events.FlexEvent
Dispatched when the "value" property changes for any reason.