1 Reply Latest reply on Aug 29, 2006 4:36 AM by blemmo

    errors in code, please help

    singru
      I am trying to generate random motion in flash and can't seem to make it work.
      Any help will be much appreciated



      newpos = function () {
      ranx = Math.random ()*250)
      rany = Math.random ()*250)
      }

      this.onEnterFrame = function() {
      newpos ()
      this._x = ranx;
      this._y = rany;
      }

      acceleration = 10
      newpos = function () {
      ranx = Math.round((Math.random ()*250));
      rany = Math.round ((Math.random ()*250));
      }
      newpos();
      this.onEnterFrame = function() {
      this._x += ((ranx-this._x)/ acceleration);
      this._y += ((rany-this._y)/ acceleration);
      };

      acceleration = 10
      newpos = function () {
      ranx = Math.round((Math.random ()*250));
      rany = Math.round ((Math.random ()*250));
      }
      newpos();
      this.onEnterFrame = function() {
      this._x += ((ranx-this._x)/acceleration);
      this._y += ((rany-this._y)/acceleration);
      if (Math.round(this._x) == ranx || Math.round(this._y) == rany) {
      newpos();
      }
      };
        • 1. Re: errors in code, please help
          blemmo Level 1
          Try this:

          newpos = function () {
          acceleration = 10;
          ranx = Math.round((Math.random()*250));
          rany = Math.round((Math.random()*250));
          this._x += ((ranx-this._x)/acceleration);
          this._y += ((rany-this._y)/acceleration);
          };
          this.onEnterFrame = function() {
          newpos();
          };

          cheers,
          blemmo