A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: functions and protoypes

  1. #1
    Senior Member
    Join Date
    Sep 2002
    Posts
    398

    functions and protoypes

    functions and protoypes.

    Can someone explain to me how to use the prototype function.

    I have built a game with a dog that slides to a target point when the mouse is clicked. I have done this with a function. At some point I am going to want to have 2 dogs and want to use the same function. Is this possible by making a prototype? And if so how?

    thanks

  2. #2
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    Hi,

    here you have a simple example:
    code:

    MovieClip.prototype.resize = function() {
    this._xscale = this._xscale * 2;
    this._yscale = this._yscale * 2;
    };
    //if you have a mc called ball_mc
    //this doubles its size:
    ball_mc.resize();


    now you can apply this method to any movie clip

    you can also have your own objects.
    for example a paper sheet with color and size:
    code:

    Paper = function (pColor, pSize) {
    this.pColor = pColor;
    this.pSize = pSize;
    };
    p1 = new Paper("white", "A4");
    trace(p1.pColor);
    Paper.prototype.changeColor = function(pColor) {
    this.pColor = pColor;
    };
    p1.changeColor("black");
    trace(p1.pColor);


    this is not the most correct way to modify an object properties... But as an example I think it will do

  3. #3
    Senior Member
    Join Date
    Sep 2002
    Posts
    398
    thanks for the reply!

    I am trying to force myself to get out of flash 5 --> MX. I have been using for a while but never bother to start using functions etc properly.

    I assume that by using e.g..

    MovieClip.prototype.resize = function() {
    this._xscale = this._xscale * 2;
    this._yscale = this._yscale * 2;
    };


    That this function will apply to all movieClips?
    whereas if I want to make just for a dog I would call it something like..

    dog.prototype.resize = function() {
    this._xscale = this._xscale * 2;
    this._yscale = this._yscale * 2;
    };

    thanks again... found a great site with advanced functions I should share as well http://proto.layer51.com/

  4. #4
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    if the dog is an object that you created, like my paper sheet, that is true.
    If it is a movie clip, it is not.

    this all has to do with oop in flash
    here's a tutorial
    http://www.debreuil.com/docs/

    also, Colin Mook's asdg2 is great...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center