Question
Class Coding Problems
ok, JESUS this is pissing me off sooo much!
so i made this thing (i wont post it all here) and it works perfectly.
it uses an init() function, which sets the Interval for the test() function. now the test() function requires an outside variable, which is defined earlier, and it can easily get it. then when its done, it uses the clearInterval() function and it stops it. No Problems!
Now i try to make it into a class!
there are two MAJOR problems:
1) the process() function run by itself CAN grab any variable, example: trace(this.testvariable); would output "asd123". but the process() function run by the init() using the interval, can NOT grab any variables. the previous code would output "undefined". i can pass variables through the setInterval code, and that has worked up until problem #2
2) clearInterval() does NOT work at all. using hold, this.hold, or hold2 (a variable passed throught the setInterval code), it will not clear the interval.
can someone please help me with this?
so i made this thing (i wont post it all here) and it works perfectly.
it uses an init() function, which sets the Interval for the test() function. now the test() function requires an outside variable, which is defined earlier, and it can easily get it. then when its done, it uses the clearInterval() function and it stops it. No Problems!
quote:
var hold;
function init()
{
hold = setInterval(process, 200);
}
function process()
{
trace("ok");
clearInterval(hold);
}
init();
Now i try to make it into a class!
quote:
class demo
{
var hold;
var testvaribale = "asd123";
function init()
{
this.hold = setInterval(process, 200, this.testvaribale);
}
function process(testvar)
{
trace(testvar);
clearInterval(this.hold);
}
}
import demo;
var Demo = new demo();
Demo.init();
there are two MAJOR problems:
1) the process() function run by itself CAN grab any variable, example: trace(this.testvariable); would output "asd123". but the process() function run by the init() using the interval, can NOT grab any variables. the previous code would output "undefined". i can pass variables through the setInterval code, and that has worked up until problem #2
2) clearInterval() does NOT work at all. using hold, this.hold, or hold2 (a variable passed throught the setInterval code), it will not clear the interval.
can someone please help me with this?