actionscript - Flash AS2 (CS4) - setInterval causing for loop to not work -


i have simple code:

    function testing(){        (a=1; a<=4; a++) {            this["btn"+a].enabled = true;        }     } 

if run function anywhere works fine. if run function mytimer = setinteval(testing, 3000); not work. if add other random code function (the newly added code only) work. have narrowed down this["btn"+a].enabled = true; causing not run.

i hope makes sense, appologies, it's 3am :(.

any ideas?

what makes sense. when call function normally, "this" object. when run using setinterval, lose reference "this."

- edited based on comments others -

here 3 ways solve problem:

this way involves passing in "this" function:

var = this; setinterval(function() {testing(that)}, 1000);  function testing(obj) {     (a = 1; <= 4; a++) {         obj["btn" + a].enabled = true;     } } 

this way involves passing in "this" setinterval:

setinterval(this, "testing", 1000);  function testing() {     (a = 1; <= 4; a++) {         this["btn" + a].enabled = true;     } } 

the third way involves delagate class:

import mx.utils.delegate;  setinterval(delegate.create(this, testing), 1000);  function testing() {     (a = 1; <= 4; a++) {         this["btn" + a].enabled = true;     } } 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

linq to sql - Linq2EF: Return DateTime with a TimeZone Offset -

gdi+ - WxWidgets draw a bitmap with opacity -