Extensions Common Traits

The MMFI Object API is able to discern between different kinds of objects (where 'kind' here refers to a unique MFX extension file, not a unique instance of said extension).  When creating a new object, this allows the module to only add the fields and methods that are compatible with it.  The API only has limited support for object-specific functionality, so most objects will only support the functionality that is common to all objects.  That functionality is documented below.

Common Object Fields

These fields can be read from or written to directly, and are supported by all objects.

number x Object's X coordinate in pixels
number y Object's Y coordinate in pixels
number layer

Object's layer (limited support)

Common Object Fields (Read-Only)

These fields can be accessed, but not updated.

object class Reference to object's associated Class object
number classID Object's instance identifier (shared by all creation instances of object)
string className Object's instance name (as defined in the frame editor)
number fixed Object's unqiue fixed value (unique to every creation instance)
number height Object's height in pixels
number hotX X coordinate of object's hotspot, relative to object origin
number hotY Y coordinate of object's hotspot, relative to object origin
number type Object's extension id (unique to each MFX extension file)
number width Object's width in pixels
number xLeft X coordinate of left edge of object
number xRight X coordinate of right edge of object
number yBottom

Y coordinate of bottom edge of object

number yTop Y coordinate of top edge of object

Common Object Methods

These methods may be called by any object.  They are protected, so they cannot be overwritten.  The colon operator, which is used by most Lua object tables, is optional here.  Click on each function for more information.

void destroy()

Example

-- Assume we have a table of objects indexed by ID
object = mmf.objects[1]
 
-- Verify the distance between object edges matches
-- width and height
local w = object.xRight - object.xLeft
local h = object.yBottom - object.yTop
assert(object.width == w and object.height == h)
 
-- Swap an object's X and Y coordinates using a
-- neat Lua trick
object.x, object.y = object.y, object.x
 
-- We can also assign our own fields to the object,
-- as long as they don't conflict with predefined
-- fields and methods
object.color = "green"
object.bogey = true
object:setColor = function (c) self.color = c end
 
-- This will throw an error (trying to mutate a
-- read-only field)
object.hotX = 0
 
-- This will throw an error (trying to overwrite
-- an object method)
object.destroy = "not a function"


See also:
     Object API, Display Traits, Movement Traits, Animation Traits, Value Traits

Copyright 2010 Justin Aquadro