dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Repeating or reseting an AS code infinitely??

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    23

    Repeating or reseting an AS code infinitely??

    I'm hoping this is a very basic answer, but since I'm VERY new to AS, I can't for the life of me, figure it out.

    Currently, I have a figure (example here being "man") that I'm looking to simply have pace back and forth in the scene. My code is as follows on the MC of the man:

    onClipEvent (load) {
    manSpeed = 2;
    walkdistance = 50;
    this.gotoAndStop(1);
    }
    onClipEvent (enterFrame) {
    this._x -= manSpeed;
    walkcount += 1;
    if (walkcount>walkdistance) {
    this._x += manSpeed*2;
    this._xscale = -100;
    }
    if (walkcount>walkdistance*2) {
    this._x -= manSpeed*2;
    this._xscale = 100;
    }
    }


    Right now, I have him pace 50 to the left, then turn around, pace 50 back to the right, then at 100 steps (or pixels), he turns back to the left. That's where the problem arises. At this point, he will just continue to the left. I'm guessing I could theoritically, just keep increasing the "walkdistance*2" number, but that obviously isn't practical if I want this to go indefinately.

    My question is...is there a way to repeat this script? Or reset? Or whatever the terminology is. I even thought that maybe there is a way to automatically increase the variable "walkdistance" is being multiplied by each time, but alas, I'm so new, I don't know the code.

    Thank you in advance.

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    onClipEvent (load) {
    	manSpeed = 2;
    	walkdistance = 50;
    	walkcount = 0;
    	dir = -1;
    	this.gotoAndStop(1);
    }
    onClipEvent (enterFrame) {
    	if (walkcount>walkdistance) {
    		this._xscale = 0-this._xscale;
    		walkcount = 0;
    		dir = 0-dir;
    		//walkdistance += walkdistance;
    	}
    	this._x += manSpeed*dir;
    	walkcount += 1;
    }

  3. #3
    Junior Member
    Join Date
    Jul 2010
    Posts
    23
    Thank you VERY much!! I've been messing with this for the last day or so. VERY MUCH APPRECIATED!!

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