interval function not working

Ask a Question related to Macromedia Flash Actionscript, Design and Development.

  1. #1

    Default interval function not working

    Hello,
    Does anybody have an idea why the delay function in the script below is not
    working?
    I'm trying to slowly move an image horizontally.
    Another movie generates the value for "p'".
    If p==2, the trace "test 01" is executed, so that's all right. After that, the
    delay function should be executed (and I should see the trace "test 02", but is
    isn't.
    Funny thing is, if I put the interval call and the delay function outside the
    if-construction, it works.
    Any ideas?
    Thanks,
    Wim

    onClipEvent (enterFrame) {
    //P1
    if (_root.p == 1) {
    _root.screen._x = 100;
    //P2
    } else if (_root.p == 2) {
    intID = setInterval(delay, 100);
    _root.x = 100;
    trace ("test 01")
    function delay() {
    trace ("test02")
    _root.x = _root.x-1;
    _root.screen._x = _root.x;
    updateAfterEvent();
    if (_root.screen._x<=-500) {
    clearInterval(intID);
    _root.pfree = true;
    }
    }
    //P3
    } else if (_root.p == 3) {
    _root.screen._x = -1100;
    //P4
    } else if (_root.p == 4) {
    _root.screen._x = -1700;
    //P5
    } else if (_root.p == 5) {
    _root.screen._x = -2300;
    }
    }


    wimw Guest

  2. Similar Questions and Discussions

    1. Using the interval data type
      I'm using a query that returns a value as an 'interval' data type. When I run that query through CF only an is returned. I've tried casting the...
    2. to_char(interval, text) deprecated in future - how do we getconsistent interval output without it?
      I saw the note in the docs that to_char(interval, text) is deprecated, and will be removed. I searched the archives and saw more mentions of this,...
    3. Interval Question
      Greetings: I am working on a function which returns an interval value. The work of the function is to calculate the difference between the...
    4. Date Interval Functions
      On a form I have Date_Start Date_End I have a new Date_Start1 Date_End1 which the use...
    5. INTERVAL FUNCTION
      On Wed, 23 Jul 2003 12:44:47 -0400, tomL wrote: Because you did not specify the resolution/size of the seconds interval which defaults to 2...
  3. #2

    Default Re: interval function not working

    do not declare functions inside an event.

    declare the function separately and preferably before the event.

    The problem is more specifically that you are using the function 'delay'
    before you have defined it.


    Jeckyl Guest

  4. #3

    Default Re: interval function not working

    Yes, I expected something like that. Wat would be the best place for the function? Should it be in the same movie as frome where it is called?
    Thx,
    Wim
    wimw Guest

  5. #4

    Default Re: interval function not working

    also consider declaring your functions as local my means of 'var' like:

    var f = function () {
    trace("test");
    }
    setInterval(...

    Also, less readable for non coders, u can exploit lexical closure like:

    setInterval(function f() {
    trace("test");
    },
    100);

    HTH,

    -c.


    CesareRocchi Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139