Skip to main content
Inspiring
June 12, 2024
Question

simple buttons to control timeLine confusion

  • June 12, 2024
  • 4 replies
  • 1313 views

Hi guys back again already. So I have a button, fire16, controlling the frames of another movieClip on the timeLine, instance named score, which is simply 0-1-2-3-4-5 dots over 6 frames to show the score.

 

this.fire16.addEventListener("click", fireSweet.bind(this));
function fireSweet()
{
var TP = this.score.timeline.position++;
this.score.gotoAndPlay(TP);
}

Well this code works well for first click, goes from frame 0 to frame 1 every time but after that it almost seems to go off random each new click. Any help would be much appreciated!

    This topic has been closed for replies.

    4 replies

    nurba
    Participating Frequently
    June 13, 2024

    Hi,

    I think it will be simpler to understand your full code.

    fix looks simple,

    but  structure of your code and movieclips are not clear

    Can you share your file?

    JoãoCésar17023019
    Community Expert
    June 12, 2024

    Hi.

     

    It's because when you run var TP = this.score.timeline.position++, the timeline's position is offset by 1 immediately but TP doesn't get the timeline's position + 1 in return because you're using ++ in the end.

     

    Also, you should use gotoAndStop.

     

    Anyway, it's just easier to run this.score.gotoAndStop(this.score.currentFrame + 1), as suggested by k.

     

    Regards,

    JC

    Inspiring
    June 13, 2024

    Also, this is not just off by one frame, it's random after the first click. It's some kind of timing issue. seems to depend when i click the button

    Inspiring
    June 13, 2024

    no :(( thought it was for a sec there. As long as I shoot while I'm still on the correct button, ( which i know i am because i've only written code for that 1 button so far, then it shouldn't matter where he is in that 4 or so frame rotation. Dang I was just grasping at straws i guess. Still not sure what's wrong..


    kglad
    Community Expert
    June 12, 2024

    by timeline.position do you mean currentFrame?

    Inspiring
    June 12, 2024

    yes, i found it somewhere. I tried current frame it does the same thing.

    kglad
    Community Expert
    June 12, 2024

    it's nonsense.

     

    use

     

    this.score.gotoAndPlay(this.score.currentFrame+1)

    kglad
    Community Expert
    June 12, 2024

    what's this.score.timeline.position??