Object class script interface
IObjectClass script interface represents an object class in the project, e.g. a Sprite object type. An ObjectClass can have multiple instances created, which are represented by the IWorldInstance script interface if it appears in a layout, otherwise the IInstance interface.
Getting an IObjectClass
References to the project's object classes are typically accessed through the IRuntime interface
objects property. For example
runtime.objects.Sprite would refer to the
IObjectclass interface for the Sprite object type, assuming one was added to the project.
Object class events
The following events can be listened for using the
- Fired whenever a new instance belonging to this object type (or family) is created. The event object has an
instance property referring to the IInstance (or derivative) that was created.
- Fired whenever any instance belonging to this object type (or family) is destroyed. After this event, all references to the instance are now invalid, so any remaining references to the instance should be removed or cleared to
null in this event. Accessing an instance after it is destroyed will throw exceptions or return invalid data. The event object has an
instance property referring to the IInstance (or derivative) that was destroyed. It also has an
isEndingLayout property to indicate if the object is being destroyed because it's the end of a layout, or destroyed for other reasons.
Object class APIs
- A read-only string of the object class's name.
- addEventListener(eventName, callback)
- removeEventListener(eventName, callback)
- Add or remove a callback function for an event. See Object class events above for more information.
- Set a custom class to be used to represent instances of this object type. The class must derive from the default class. This can only be called in
runOnStartup, before any instances have been created. For more information see the guide on subclassing instances.
- Return an array of all instances of this object class.
- Return the first instance in the array returned by
null if no instances exist.
- Iterates over all the object class's instances.
- Return an array of instances that have been picked by the event's conditions. This is only useful with scripts in event sheets.
- Return the first instance that has been picked by the event's conditions, or
null if none. This is only useful with scripts in event sheets.
- Iterates over the instances that have been picked by the event's conditions. This is only useful with scripts in event sheets.
- createInstance(layerNameOrIndex, x, y, createHierarchy, template)
- Create a new instance of the object type at a position. The layer to create on is specified either by a case-insensitive string of the layer name or its zero-based index. The position is given in layout co-ordinates. If
createHierarchy is true, all children of the created instance in the scene-graph hierarchy will also be created automatically with their connections in place. If
template is a valid template name then the new instance will be based on the template rather than an arbitrary instance.
Returns an instance class representing the created instance.
Construct 3 Manual
You are here:
Search this manual:
This manual entry was last updated on 16 May, 2022 at 10:41