Invoking Operations from Within Action Script
As discussed on self Context, class operations can be static or non-static. Both can be invoked from within Action Script using the scripting style explained on Basics of the Action Script Language.
Calling Non-static Operations
Non-static operations can be invoked on an object of that class.
Example:
Assume you have the following Product class with a non-static updateStock() operation that updates a given quantity of the current product to the stock.

When we have an object aProduct of type Product, we can call updateStock() use the notation explained on self Context:
aProduct.updateStock(100)
Calling Static Operations
Static operations from custom classes cannot be invoked directly from within Action Script. Similar to non-static operations, you have to provide some context for the Compiler to find the operation. There are different possibilities for how to do that.
Assume you have the following Product class with a static updateStorageSystem() operation that updates the storage system with a given quantity for a given product.

From Within a Non-static Operation of the Same Class
Wanting to call updateStorageSystem() from within a non-static operation of that same class, you can use the same notation as explained on Basics of the Action Script Language | Scripting-Style. Inside the non-static operation, the self context is available, and you can use it to provide the path to the static operation.
self.updateStorageSystem("AF-1200", 100)
From Within a Static Operation of the Same Class
Wanting to call updateStorageSystem() from within a static operation of that same class, you can use the following notation:
self:updateStorageSystem("AF-1200", 100)
Note the colon : after self. Inside static class operations, there is an implicit use dependency called self available that you can use to point to the operation you want to use.
From Within an Operation of a Different Class via Inheritance
Wanting to call updateStorageSystem() from within an operation of a different class, you can provide the necessary context by inheriting from the class you want to use the operation of.
Example:

Class Delivery inherits from Product. So, when wanting to book a delivery, the book() operation can call updateStorageSystem() like the following:
if book() is non-static:
self.updateStorageSystem(deliveredArticle, deliveredQuantity)if book() is static:
aDelivery.updateStorageSystem(deliveredArticle, deliveredQuantity)
From Within an Operation of a Different Class via Context Parameter
Alternatively, you can provide the necessary context by adding an object of the target class as a dedicated parameter to the operation to be called. This parameter is only used to identify the operation, but not used in the operation itself.
Example:
Let’s assume the book() operation from the previous example has an additional parameter product of type Product: book(product : Product)
Now, book() can call updateStorageSystem() like the following:
product.updateStorageSystem("AF-1200", 100)
The product parameter of operation book() only serves to identify the updateStorageSystem() operation.
It must be defined as not mandatory to avoid validation errors.
It does not need to be used in the implementation at all.
It does not need to be provided by any caller (can be NULL).
Related Content
Related Pages: