The most basic features of each language are creating instances of classes and setting values.
set
assignment statement, it is possible to create objects of base types like String, Integer, Float, Boolean, and DateTimecreate
statement - that is creating an instance of the corresponding class. Once the instance of the class (the object) has been created, it can store data in its attributes.The following examples shows how to use the set assignment statement to create base type objects.
Syntax |
| ||
---|---|---|---|
Semantics | Assigns a value to anObject . | ||
Substitutables | anObject | Can be an object node or an attribute, or an association end. | |
aValue | Can be a literal, a object node of base type, or an action script operation or expression returning a base type. | ||
Examples |
|
The example in the figure below shows how to create base type objects like strings, integers, etc. Base type objects need not to be instantiated, they are created by using the set
assignment statement to directly assign a value to the variable.
All variables are drawn as object nodes with all objects being of base type.
The following example shows how to use the create
statement to create objects of complex type.
Scalar base type objects are never created using the |
Syntax |
| ||
---|---|---|---|
Semantics | Creates an object of complex type. The object reference is stored in anObject. Initial values defined on the class attributes will be set. | ||
Substitutables | anObject | Can be any valid object name. | |
Examples |
|
In the following cases, objects need to be created with the create
statement:
In the following cases, the create
statement is not necessary:
When having related classes, the instantiation of intermediate objects is not mandatory.
In the example below, ClassA has an attribute b, which is of type ClassB (see association). ClassB in turn has a string attribute named aString.
When creating an instance of the top-level class ClassA, the lower classes are instantiated implicitly, so the action script below would be fine.
create objectOfClassA; set objectOfClassA.b.aString ="Hello World!"; |
Basics of the Action Script Language: |