Posted by: Petit Dec 5 2006, 04:33 PM
Well, as a matter of act, it was my own fault.
Some of you will recognize this with a smile, others may benefit, so I'll give you the story.
My tool is Flash 8
I was using a MixedSkin on a Box primitive, and I wanted to change its alpha value at run time. Here is the skin:
CODE
var skin:Skin = new MixedSkin(0x00FF00, 20, 1, 10, 1);
So the alpha value is 20, a fairly transparent skin
Then I tried this:
CODE
skin.alphaBkg = 60;
It wouldn't compile. I got the prompt complaint from the compiler:
There is no property with the name 'alphaBkg'I
searched, as the say, high and low. I checked the Sandy documentation,
I checked the MixedSkin source code, and there it was, a pretty getter
and a well formed setter for alphaBkg, the value stored in a private
variable _alphaBkg.
I googled the great web for properties and
for the error message, and I found lots of information, but no
solution. I even went to Adobe to search for updates to Flash 8.
All to no avail.
Suddenly, in a short and frustrated coffee break, it hit me. Ha, stupid!
It's a good thing with object oriented languages, encapsulation, inheritance and polymorphism.
You
define all that is common in a base class, and the subclasses inherits
all public members, and are given more specialized additions. A Box for
example is an Object3D, with a special signature for the constructor.
The type of a Box is Box, but it is also Object3D, so you can declare
and define a reference like this.
CODE
var cube:Object3D = Box(50, 50, 50, 'tri');
One
common method is the setSkin() method, which can be used for any
Object3D. So when you define a Box, that can use any Skin, you just use
the inherited setSkin() method.
In fact, this is the recommended
way of typing, and has the advantage, that you can switch in a Pyramid,
or Sphere dynamically. Oh yes, I know all this - ain't I clever?
In
the Sprite2D class, which cannot take all kinds of Skin's, you override
the setSkin() method to accept just a TextureSkin, like this
CODE
public function setSkin( s:TextureSkin ):Boolean{}
Although the type of the reference variable is still Object3D, due to polymorphism, the correct setSkin() method will be used.
So far, so good. But what if I want to call a method, that only exists within the Sprite2D class and not in its super class?
Exactly!
You can't.
I
declared the type of the skin reference variable to be of type Skin,
the highest level, and hang a MixedSkin on it. Then I tried to call a
setter, that was never declared in the Skin class. The compiler
correctly regard this object to be of type Skin, and could not see any
alphaBkg property.
In other word, this works:
CODE
var skin:MixedSkin = new MixedSkin(0x00FF00, 20, 1, 10, 1);
skin.alphaBkg = 60;
Long story, happy ending

Thanks for listening!
Posted by: fjr Dec 5 2006, 10:47 PM
=) something to learn... thank you for sharing it, Petit!