PDA

View Full Version : __proto__ and prototype..?


ryuyu
07-20-2002, 04:44 AM
hello~


I want to know a difference of __proto__ and prototype?

and usage ^_^


I'll wait you reply.. thanks for reading

xxlm
07-20-2002, 05:50 AM
I'll try to answer you clearly...
First you have to have a little knowledge on class and object (so in OOP).

In flash you can use now OOP.
FIRST prototype:
This property is used to affect some methods to a class you've made. i.e:

//class constructor
function Cycle (longueur, couleur) {
this.longueur = longueur;
this.couleur = couleur;
}

Cycle.prototype.roule = function() {this._x = _x + 20;}


and use too to tell that your class is a lower class of another i.e:

Myclass.prototype = new MovieClip(); //or what you want...button..comboBox...


So now to explain the __proto__ property I have to make a lower class from the Cycle Class.

VTT.prototype = new Cycle();


Ok, now I create an instance of my class VTT;
FirstVTT = new VTT();

Then if I write
FirstVTT.roule;
it works... Why?
Simply because if the __proto__ property. This property give the class of the object... OK?
Flash look for the FirstVTT class so it look on the __proto__ property and find VTT. But it can't find the "roule" method. So it look in FirstVTT.__proto__.__proto__ and find Cycle. It look for the roule and find it... execute the code.

__proto__: which class
prototype: define lower class and class methods.

Hope it's not too confused!

;)

Mortimer Jazz
07-21-2002, 12:47 AM
Just incase you don't know too much about OOP......... this still isn't going to be easy in under 500 words but I'll give it a go!

Objects have properties, such as color, width, height etc. They also have MethODs [stuff they DO] such as play(),stop(),goto.... etc. They inherit these from the template they were made from (their Class).

For example all movieclips have the same properties (_x, _y, _alpha, _rotation.......) and the same methods (play(), stop()......) because they inherited them from the 'movieClip Class'.

If you make your own object then you have to create the Class (template) for it. When you create a Class, Flash automatically assigns that class a property of its own called prototype.
Prototype holds a generic object, onto which you can attach any methods or properties that you want all instances of that object to share.

Confused by that last bit? Well read on, it might clarify things.......

You can also give existing objects new methods, so in more simple terms if you wanted to give every movieclip a new method called boogie (which would be accessed like this: movieClipName.boogie() ), you would add your method on to the prototype of the 'movieclip Class' so it can be shared by all instances
______________________________________________
__proto__ is a reference to the prototype property.

I'm not so clear on this but I believe that if you have an instance of a movieclip called "Fred" then fred.__proto__ will equal: movieClip.prototype

This allows the instance to check what inherited properties it should have.

Hope this helps :D

ryuyu
07-21-2002, 03:09 PM
I really thanks for your good reply ^_^

have a good time

xxlm
07-21-2002, 04:14 PM
:) :p :D

Jesse
07-22-2002, 03:13 AM
Everyone should read this ( http://www.debreuil.com/docs/ ) at least once.

tg
07-22-2002, 04:02 PM
jesse, we should all read it at least twice.
heh.

Ricod
07-23-2002, 01:56 PM
I did read it twice ... maybe I should read it a third time and make notes ... cuz its clear when I read it, but once I'm looking at that empty actions window ... *quiver*

tg
07-23-2002, 03:19 PM
ha!. believe me. i've read it more than twice also.

pandareum
07-23-2002, 03:59 PM
There's a very good book : 'ActionScriptiong' written by Colin Moock.
Object are explained very easy.

reùm