Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 08-26-2004, 04:44 PM   #1
emsee
bonafide braindead
 
Join Date: Aug 2004
Posts: 25
Default setInterval scope

Hello!

I'm trying to get to grips with as2, but I'm having problems with setInterval. Anyone know what I'm doing wrong?

Code:
//Class
class Test {
     
     private var intervalID:Number;
     
     function Test() {
          loadFile();
     }
     
     private function loadFile():Void {
          intervalID = setInterval(this, "readTrack", 1000, "foo");
     }
     
     private function readTrack(sString:String):Void {
          trace(sString);
          var myThing:String = "bar";
          displayThing(myThing);
     }
     
     private function displayThing(vThing:String):Void {     
          trace(vThing);
     }
     
}


//Code in movie
stop();
function init() {
     var thing:Test = new Test();
}
init();
Any help you can give me is appreciated - thanks!
emsee is offline   Reply With Quote
Old 08-26-2004, 05:01 PM   #2
senocular
six eyes
 
senocular's Avatar
 
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,758
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular
Default

dont make your class instance a local (i.e. temporary) variable.

ActionScript Code:
stop(); var thing:Test; function init() {      thing = new Test(); } init();
__________________
(6)
senocular is offline   Reply With Quote
Old 08-26-2004, 05:13 PM   #3
deQue
unRegistered User
 
deQue's Avatar
 
Join Date: Aug 2004
Posts: 286
Send a message via ICQ to deQue
Default

You have an error in your interval deffinision:
PHP Code:
intervalID setInterval(this"readTrack"1000"foo"); 
Should be:
PHP Code:
intervalID setInterval(readTrack1000"foo"); 
deQue is offline   Reply With Quote
Old 08-26-2004, 05:16 PM   #4
emsee
bonafide braindead
 
Join Date: Aug 2004
Posts: 25
Default

ActionScript Code:
var emsee:Dumbness; function init() {   emsee = new Dumbness(); } init()

Thanks senocular, I think I must be going blind!
emsee is offline   Reply With Quote
Old 08-26-2004, 05:19 PM   #5
emsee
bonafide braindead
 
Join Date: Aug 2004
Posts: 25
Default

deQue: actually, that's to provide the readTrack function with scope. Otherwise it can't call the displayThing method.
emsee is offline   Reply With Quote
Old 08-26-2004, 08:35 PM   #6
senocular
six eyes
 
senocular's Avatar
 
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,758
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular
Default

Quote:
Originally Posted by emsee
ActionScript Code:
var emsee:Dumbness; function init() {   emsee = new Dumbness(); } init()

Thanks senocular, I think I must be going blind!

Its actually a very common problem. Whether you meant to make it a local variable or not, its not too intuitive that an interval in such a situation will fizzle as a result of the containing objects destruction in memory. Used to get similar questions a bit, but I haven't seen one in a while
__________________
(6)
senocular is offline   Reply With Quote
Old 08-26-2004, 08:37 PM   #7
deQue
unRegistered User
 
deQue's Avatar
 
Join Date: Aug 2004
Posts: 286
Send a message via ICQ to deQue
Default

Yeah, I got that. thx.
deQue is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:53 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.