Professional Web Applications Themes

interval function not working - Macromedia Flash Actionscript

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 ...

  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. #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

  3. #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

  4. #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

Similar Threads

  1. Replies: 1
    Last Post: January 15th, 09:13 AM
  2. Scroll function not working
    By AndieFL in forum Macromedia Freehand
    Replies: 0
    Last Post: August 3rd, 03:11 PM
  3. Function Calls not working
    By Johnny in forum ASP Database
    Replies: 2
    Last Post: March 2nd, 05:38 AM
  4. 3d text function is not working
    By Hakan K in forum Macromedia Director 3D
    Replies: 1
    Last Post: February 25th, 02:06 PM
  5. INTERVAL FUNCTION
    By Art S. Kagel in forum Informix
    Replies: 2
    Last Post: July 24th, 09:46 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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