GetPrice

Package:
Class:
biz.flashscript.shoppingcart
public class GetPrice
The GetPrice class class will calculate the price with shipping and tax. All variables are static. So use the class name to declare the variables. Also all variables have default values, so no need to declare anything as null. Use the method GetPrice.getInstance() to create an instance of the class.
Public Properties
Property Defined By
itemPrice : Number
Single price of an item.
GetPrice
newItemPrice : Number
When another item price is added to add up to the total price.
GetPrice
itemNumber : int
The number of an item.
GetPrice
shipHandling : Number
The price for shipping and handling.
GetPrice
noTaxPrice : Number
The price before tax is added.
GetPrice
stateTax : Number
The percent state tax to add to the total price.
GetPrice
rawPrice : Number
The amount of state tax to add to the total price.
GetPrice
Public Methods
Method Defined By
GetPrice.getInstance()
Creates a new instance of the GetPrice class.
GetPrice
addTax():String
Function returns the price total price including tax.
GetPrice
addPrice():String
Function returns the price after another item price has been added to the subtotal price.
GetPrice
adjustRawPrice():String
Function returns the price adjusted to two values after the comma.
GetPrice
simplePrice():String
Function returns the price of an item multiplied with its number.
GetPrice
subtractPrice():String
Function returns the price after an item price has been subtracted from the subtotal price.
GetPrice
Property Detail
itemPrice property
itemPrice:Number [read-write]

Value is the single price of an item.

Default value is 0 .

EXAMPLE:

import biz.flashscript.shoppingcart.GetPrice;
var gp:GetPrice=GetPrice.getInstance();
GetPrice.itemPrice=4.43;
GetPrice.itemNumber=2;
var fp2:Number=Number(GetPrice.simplePrice());

Implementation

public static function get itemPrice():Sprite
public static function set itemPrice(value:Number):void
newItemPrice property
newItemPrice:Number [read-write]

When another item price is added to add up to the total price.

Default value is 0.

EXAMPLE:

import biz.flashscript.shoppingcart.GetPrice;
var gp:GetPrice = GetPrice.getInstance();
GetPrice.itemPrice = 20;
GetPrice.itemNumber = 5;
var fp1:Number = Number(GetPrice.simplePrice());
GetPrice.itemPrice = 4.43;
GetPrice.itemNumber = 2;
var fp2:Number = Number(GetPrice.simplePrice());
GetPrice.itemPrice = fp1;
GetPrice.newItemPrice = fp2;
var fp3:Number = Number(GetPrice.addPrice());
trace (fp3);//trace is 108.86

Implementation

public static function get newItemPrice():Number
public static function set newItemPrice(value:Number):void
itemNumber property
itemNumber:int [read-write]

Sets the number of an item.

The default value is 0.

.

Implementation

public static function get itemNumber():int
public static function set itemNumber(value:int):void
shipHandling property
shipHandling:Number [read-write]

Sets the shipping and handling value.

The default value is 0.

EXAMPLE:

import biz.flashscript.shoppingcart.GetPrice;
var gp:GetPrice = GetPrice.getInstance();
GetPrice.itemPrice = 20;
GetPrice.itemNumber = 5;
var textfp1:String = GetPrice.simplePrice();
GetPrice.noTaxPrice = textfp1;
GetPrice.shipHandling = 10;
trace(GetPrice.addTax());//trace is 110

Implementation

public static function get shipHandling():Number
public static function set shipHandling(value:Number):void
noTaxPrice property
noTaxPrice:Number [read-write]

Sets the price before tax and shipping and handling.

The default value is 0.

EXAMPLE:

import biz.flashscript.shoppingcart.GetPrice;
var gp:GetPrice = GetPrice.getInstance();
GetPrice.itemPrice = 20;
GetPrice.itemNumber = 5;
var textfp1:String = GetPrice.simplePrice();
GetPrice.noTaxPrice = textfp1;
GetPrice.stateTax = 7.25;
GetPrice.shipHandling = 10;
trace(GetPrice.addTax());//trace is 117.25

Implementation

public static function get shipHandling():Number
public static function set shipHandling(value:Number):void
stateTax property
stateTax:Number [read-write]

Is the state tax in per cent used with the addTax() method.

The default value is 0.

Implementation

public static function get stateTax():Number
public static function set stateTax(value:Number):void
rawPrice property
rawPrice:Number [read-write]

Is the state tax in per cent used with the addTax() method.

The default value is 0.

EXAMPLE:

import biz.flashscript.shoppingcart.GetPrice;
var gp:GetPrice = GetPrice.getInstance();
GetPrice.rawPrice=87.45345;
trace(GetPrice.adjustRawPrice());//trace is 87.45

Implementation

public static function get rawPrice():Number
public static function set rawPrice(value:Number):void
Constructor Detail
GetPrice ()  Constructor
public function GetPrice(mp:MakePrivate)
To initialize an instance use GetPrice.getInstance().
Method Detail

addTax():String
public static function addTax():String

Function returns the price total price including tax. This function uses the noTaxPrice and optional stateTax and/or shipHandling values.

addPrice():String
public static function addPrice():String

Function returns the price after another item price has been added to the subtotal price. This function uses the values from the variables itemPrice and newItemPrice and sums them up.

adjustRawPrice():String
public static function adjustRawPrice():String

Function returns the price adjusted to two values after the comma. The function uses the rawPrice variable.

simplePrice():String
public static function simplePrice():String

Function returns the price of an item multiplied with its number. The function uses the itemNumber and itemPrice variables.

subtractPrice():String
public static function subtractPrice():String

Function returns the price after an item price has been subtracted from the subtotal price. The function subtracts the value of newItemPrice from the value of itemPrice.

Examples
Create a new fla file and name it Getprice.fla. Place the fla in the same folder as the biz folder. Place a dynamic textfield on the timeline and name it myText. Then add the script below in a new Actionscript file and name it Getprice.as. Use as a Document class.


package 
{
	import flash.display.Sprite;
	import biz.flashscript.shoppingcart.GetPrice;
	import flash.text.TextField;

	public class Getprice extends Sprite
	{
		public var myText:TextField;
		
		public function Getprice ():void
		{
			var gp:GetPrice = GetPrice.getInstance();
			GetPrice.itemPrice = 20.52;
			GetPrice.itemNumber = 5;
			var fp1string:String = GetPrice.simplePrice();
			var fp1:Number = Number(fp1string);
			myText.appendText("20.52 x 5 (price as string): "+fp1string+"\n");
			GetPrice.rawPrice = fp1;
			fp1 = Number(GetPrice.adjustRawPrice());
			myText.appendText("20.52 x 5 (price as number): "+fp1+"\n");
			GetPrice.noTaxPrice = String(fp1);
			GetPrice.stateTax = 7.25;
			myText.appendText ("price plus 7.25 tax: "+GetPrice.addTax()+"\n");//trace is 110
			var textfp1:String = GetPrice.simplePrice();
			GetPrice.itemPrice = 4.43;
			GetPrice.itemNumber = 2;
			var fp2:Number = Number(GetPrice.simplePrice()+"\n");
			GetPrice.itemPrice = fp1;
			GetPrice.newItemPrice = fp2;
			var fp3:Number = Number(GetPrice.addPrice());
			myText.appendText ("price add 8.86: "+fp3+"\n");//trace is 108.86
			GetPrice.noTaxPrice = textfp1;
			GetPrice.shipHandling = 10;
			GetPrice.stateTax = 7.25;
			myText.appendText ("price plus shiphand (10) plus 7.25 tax: "+GetPrice.addTax()+"\n");//trace is 110
			GetPrice.rawPrice = 87.45345;
			myText.appendText ("raw price is 87.45345. Adjust price: "+GetPrice.adjustRawPrice()+"\n");//trace is 87.45
		}
	}
}