A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: calculation of frames in onEnterFrame loop

  1. #1
    Member
    Join Date
    Sep 2004
    Posts
    44

    calculation of frames in onEnterFrame loop

    Hey all,

    I'm trying to work this out if anyone can help. I have a function:

    Actionscript Code:
    function formatSeconds(num):String {
         var min = (Math.floor(num / 60));
         var sec = (Math.floor(num % 60));
         var frame = (Math.floor(num * 30));
         if ((sec + "").length == 1)     {
             sec = "0" + sec;     }
         if ((min + "").length == 1)     {
             min = "0" + min;     }
         if (frame == "30")     {
         frame = "0";     }
             frame++;
         return min + " : " + sec + " : " + frame;
     }

    the problem is it is called with this function:

    Actionscript Code:
    function resetTime() {
         mc.onEnterFrame = function()     {
             currentTime.text = formatSeconds(mc._currentframe / 30);     };
    }

    when I pause the movieclip set at 30fps the sec,min stop but the frame var keeps running in the onEnterFrame loop. I'm trying to get the framecount to go up to 29 then reset to 0 then flip to 1 second, currently when you pause the framecount it just keeps running. Can anyone point me in the right direction? Any help appreciated

    A

  2. #2
    Member
    Join Date
    Sep 2004
    Posts
    44
    Still trying to work on a solution if anyone can help.

    A

  3. #3
    Junior Member
    Join Date
    Jun 2010
    Location
    Toronto
    Posts
    28
    "delete mc.onEnterFrame" to stop the reiteration.
    M@UZ

  4. #4
    Member
    Join Date
    Sep 2004
    Posts
    44
    Thanks for the replies all, After working through this I came up with a solution, but need help on one part

    Actionscript Code:
    function formatSeconds(num):String
    {
       var min = (Math.floor(num / 60));
       var sec = (Math.floor(num % 60));
       var frame = (Math.floor(num * 24));
       if ((sec + "").length == 1)
       {
          sec = "0" + sec;
       }
       if ((min + "").length == 1)
       {
          min = "0" + min;
       }
       if ((frame >= 24))
       {
          frame = "0";
       }
       return min + " : " + sec + " : " + frame;
    }

    function resetTime()
    {
       mc.onEnterFrame = function()
       {
          currentTime.text = formatSeconds(mc._currentframe / 24);
       };
    }

    with this line
    Actionscript Code:
    if ((frame >= 24))
       {
          frame = "0";
       }


    i would like to count every 24 frames in the movie (24,48,72,96 etc) regardless of the length of the movieclip and reset to 0 each time.

    Any thoughts? getting closer just need to work the math out

    Thanks,

    A

  5. #5
    var x:Number = 1; x /= 0;
    Join Date
    Dec 2004
    Posts
    549
    replace this:
    Actionscript Code:
    if ((frame >= 24))
       {
          frame = "0";
       }
    with this:
    Actionscript Code:
    frame%=24;
    Z¡µµ¥ D££

    Soup In A Box

  6. #6
    Member
    Join Date
    Sep 2004
    Posts
    44
    thanks zippy, put me on track and I worked out a solution.

    A

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