A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: old prototypes on MX?

  1. #1
    Hi there!!!

    this works well when published with Flash 5 but not with Flash MX, any one knows how to fix this and keep it compatible, or how to do the same but in MX style?
    //
    MovieClip.prototype.randomizer = function(ancho,alto) {
    this.nextX = Math.round(Math.random()*ancho);
    this.nextY = Math.round(Math.random()*alto);
    }
    //
    MovieClip.prototype.goInertia = function(nextX,nextY,vel) {
    this._x += ( nextX - this._x ) / vel ;
    this._y += ( nextY - this._y ) / vel ;
    if (this.hitTest(nextX, nextY)) {
    randomizer(ancho,alto);
    }
    }
    //
    and on mc:
    onClipEvent (load) {
    ancho=450;
    alto=250;
    // randomizer = stage size _x and _y
    randomizer(ancho,alto);
    }
    onClipEvent (enterFrame) {
    goInertia(nextX, nextY, 10);
    }

    is weird, other prototypes work well, like this one:

    //
    MovieClip.prototype.LookAt=function (x,y){
    Xdiff = x-this._x;
    Ydiff = y-this._y;
    radAngle = Math.atan2(Ydiff, Xdiff);
    this._rotation = radAngle*360/(2*Math.PI);
    }
    //
    onClipEvent (enterFrame) {
    LookAt(_parent.something._x, _parent.something._y);
    }
    any help is apreciated.

  2. #2
    Senior Member
    Join Date
    Feb 2001
    Posts
    1,835
    The problem is in the way that Flash MX resolves variable references.

    So, change goInertia to:

    Code:
    MovieClip.prototype.goInertia = function(nextX,nextY,vel) { 
       this._x += ( nextX - this._x ) / vel ; 
       this._y += ( nextY - this._y ) / vel ; 
       if (this.hitTest(nextX,nextY,true)) { 
          this.randomizer(this.ancho,this.alto); 
       }
    }
    
    // or, more convenient
    MovieClip.prototype.goInertia = function(nextX, nextY, vel) {
       with (this) {
          _x += (nextX-_x)/vel;
          _y += (nextY-_y)/vel;
          if (hitTest(nextX, nextY, true)) {
             randomizer(ancho, alto);
          }
       }
    };
    and everything will be ok.

    - n.

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