A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: OnHit, move one frame forward.

  1. #1
    Senior Member
    Join Date
    Jul 2003
    Posts
    119

    OnHit, move one frame forward.

    Hey, looking for some help with a simple script i have. This is the script i have.

    Code:
    onClipEvent (enterFrame) {
    	if ((this.hitTest(_root.XXX))) {
    		_root.YYY.nextFrame();
    	}
    }
    Basically what this does is that once XXX hits YYY it continously goes to the next frame over and over again (basically a play effect)
    Could someone help me modify this so that once XXX hits YYY it only goes to the next frame and then stops?

  2. #2
    Senior Member
    Join Date
    Jul 2003
    Posts
    119
    I might as well post the .fla to clarify, this is a version of my previous thread in wich i had problems with the fireball effect. That's fixed by now thanks

    To put it into the context of the .fla whenever the wizard (here named man) gets hit by the White spell effects that in the middle of the arena (in the final Product the monster will shoot these, but its here as an example) the Health Movieclip moves forward one step, so the exact script is:

    Code:
    onClipEvent (enterFrame) {
    	if ((this.hitTest(_root.man))) {
    		_root.health.nextFrame();
    	}
    }
    As you can see when the wizard walks on the spell the Health instantly goes down to zero. I'd like it so that when he steps on it (and remains on it) it only goes forward one frame in the Health movieclip (but if he moves out of it and then on it again, it goes down one step again so you can get hit multiple times)

    Hope that i make it clear what i mean! Thanks!
    Attached Files Attached Files

  3. #3
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Hi, in order to achieve this effect, you'd need to make a boolean variable (which can either be true or false) and toggle the value as the wizard hits the white spell. Here, replace your code with this:

    PHP Code:
    onClipEvent(load){
        
    hitting false;
    }

    onClipEvent (enterFrame) {
        if ((
    this.hitTest(_root.man))) {
            if(
    hitting == false) {
                
    _root.health.nextFrame();
                
    hitting true;
            }
        } else {
            if(
    hitting == true){
                
    hitting false;
            }
        }

    We make a boolean variable with the starting value of false. If the man is hitting the white spell, THEN we check if hitting variable is equals to false -- and all of this is true, THEN we execute the code where the health is set to go to the next frame, but we also set hitting to true, as to not repeat the same code over and over again. In the else part of the if statement, that is when the man is NOT hitting the white spell, we first check if hitting is equals to true, and if it is (which means that we've hit the spell already, but are not on it anymore), THEN we reset hitting to false -- thus continuing the cycle to achieve the desired effect

    Hope this helps ^^
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

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