Cascading Properties 101 - F5,F6,F7
DIGG IT!
0
Comments
Published
Friday, August 15, 2003
at
1:01 PM
.
I was working on a problem recently with properties. I needed a way to encapsulate a set of properties so that they could be used via inheritance in many different instances and methods. Ideally, the system needed to support levels of properties via a class based system. The result shocked me as it was right in front of me the whole time. Hopefully you will find it useful too, here is a sample.
rootProperties = {x:2, y:34, width:23, height:43, faceColor:0x343434,backColor:0x333333}
properties = {faceColor:0x222222,backColor:0x444444, __proto__:rootProperties }
windowProperties= {x:34,y:45,__proto__:properties }
buttonProperies = {x:0, y:0, width:100, height:20,backColor:0x888888,__proto__:properties }
buttonProperties.faceColor // returns 0x222222 via the "properties" object
windowProperties.height // returns 43 via the "rootproperties" object
Essentially this creates a set of objects that inherit from one another. If you look up a property in one, it will cascade to another when that property is absent via the __proto__ chain. __proto__ is the primary ingredient in inheritance support in Flash. Typically, an instance contains a __proto__ that is a reference to a {Class}.prototype and that prototype typically contains another __proto__ property defining a superclass. In this case we are using __proto__ to provide inheritance from instance to instance vs from class to class but it works the same way.
This is a handy patterns for dealing with property data as each object can have properties that layer into a tree structure. It is very close to how CSS works but is compatible in F5,F6,F7 players.
Useful, clean, easy!
Cheers,
ted ;)

0 Responses to “ Cascading Properties 101 - F5,F6,F7 ”
Post a Comment