Welcome, Guest
  • Author Topic: setInterval loop positioning  (Read 796 times)

    Algreco

    • Seasoned Programmer
    • ***
    • Posts: 123
    • If it 'aint workin blame Flash!
      • View Profile
      • Line Dezine
      • Email
    setInterval loop positioning
    « on: 07/26/04, 04:23 »
    I am experimenting with setInterval and trying to set a delay (of 1 millisecond) on the increment of a variable (i), but i'm not sure where to position the script (and have doubts the setInterval script is correct).

    here's the script (summary):
    var int_x=100
    var int_y=0
    var right_x = int_x+200;
    var down_y = int_y+200;

    //start setInterval loop
    i = new Object();
    i.interval = function(){
    trace(i)
    }
    setInterval( i, "interval", 1);

    //increment statement (a loop)
    for (var i=0; i<=100; i++ //this is the variable i want to delay){
    var movie = _root.createEmptyMovieClip("square", 1);
    with (movie) {
          moveTo (int_x,int_y);
          lineStyle(2, 0x04263E, 100);
          beginFill (0x0C6AAF, 70);
          lineTo(right_x + i, int_y);
          lineTo(right_x + i, down_y + i);
          lineTo (int_x, down_y + i);
          lineTo (int_x, int_y);
          endFill;
          }
    }

    It seems that setInterval comes as an addition to a function, I wish it was just an addition to a variable...
    Hope you understand me and hope you can give me a hand with this.
    Greetz

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re:setInterval loop positioning
    « Reply #1 on: 07/26/04, 06:40 »
    Hi Algreco,
    setInterval does not need a loop ;)

    The idea of event driven computing is, that you do not run loops for testing a situation, but rather set events to do things.

    setInterval sets a time interval to call a function.
    You only set the interval once in the program, and should not do it again anymore (unles you clered it, and need to reset it again).

    The function will then be called every so many milliseconds. Dont forget, milliseconds means 1 second=1000 milliseconds ;).

    The function will be called, wherever youre frame pointer is.
    happy flashing
    8)
    Ronald

    Algreco

    • Seasoned Programmer
    • ***
    • Posts: 123
    • If it 'aint workin blame Flash!
      • View Profile
      • Line Dezine
      • Email
    Re:setInterval loop positioning
    « Reply #2 on: 07/26/04, 07:46 »
    ok. i understood. thnx ;)
    « Last Edit: 07/26/04, 11:47 by Algreco »