This is G o o g l e's cache of http://www.flashsandy.org/forum/index.php?act=Print&client=printer&f=9&t=217 as retrieved on 18 Jul 2007 17:05:44 GMT.
G o o g l e's cache is the snapshot that we took of the page as we crawled the web.
The page may have changed since that time. Click here for the current page without highlighting.
This cached page may reference images which are no longer available. Click here for the cached text only.
To link to or bookmark this page, use the following url: http://www.google.com/search?q=cache:M8mx0QK4ELQJ:www.flashsandy.org/forum/index.php%3Fact%3DPrint%26client%3Dprinter%26f%3D9%26t%3D217+act%3DPrint+%22index+php%22+-lofiversion+site:www.flashsandy.org&hl=en&ct=clnk&cd=98


Google is neither affiliated with the authors of this page nor responsible for its content.
These terms only appear in links pointing to this page: act print index php

Printable Version of Topic

Click here to view this topic in its original format

Sandy's Forum _ Discussion _ This property direves me in sane

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 wink.gif
Thanks for listening!

Posted by: fjr Dec 5 2006, 10:47 PM

=) something to learn... thank you for sharing it, Petit!

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)