Articles Archive
Director Forums
Director Wiki
Job Board
Search
 
 Director Online WikiMain Page | About | Help | FAQ | Special pages | Log in | Printable version | Disclaimers

Ancestor

From Director Online Wiki

Ancestors can be used to inherit functionality from other scripts, but Director also allows ancestors to be [Director Types]. With this you can inherit entire chunks of functionality, expand them and override them. For example, lets say that you want an image object that will allow extractAlpha() to work on an 8 bit image rather than giving an error. You can do this like this...

on new me, vWidth, vHeight, vDepth, vPalette
 if vPalette = void then
   me.ancestor = image(vWidth, vHeight, vDepth)
 else
   me.ancestor = image(vWidth, vHeight, vDepth, vPalette)
 end if
 return me
end


on extractAlpha me
 if me.ancestor.depth = 32 then
   return me.ancestor.extractAlpha()
 else
   iAlpha = image(me.ancestor.width, me.ancestor.height, 8, #grayscale)
   iALpha.fill(iALpha.rect, rgb(0,0,0))
   return iAlpha
 end if
end


So instead of creating a new image like this...

i = image(100,100,16)

use

i = script("superimage").new(100,100,16)
a = i.extractAlpha()

This can be used to expand any major functions as needed and make some very powerful script controllers.

See also Single Inheritance

Retrieved from "http://www.director-online.com/dougwiki/index.php/Ancestor"

This page has been accessed 1839 times. This page was last modified 17:23, 7 Jul 2006.