> ActionScript, being a programming language for non-programmers, makes no > mention whatsoever of threads, nor do I see any way to call a sleep function > or > a yeild function on the current thread (i.e., some way to tell 'this' thread > to > just chill for a sec and let other threads do what they need to do). >
Flash is single threaded.. It sounds like you simply want to call another function when the LoadVars.onLoad event is called. Or maybe you want to perform an onEnterFrame while the data is getting loaded.. And nested functions are a no-no.. Just google "actionscript nested functions" and "actionscript activation object" Also look into the Delegate proxy util class. import mx.utils.Delegate; var _lv:LoadVars; function loadvarsLoadHandler(success:Boolean):Void { if (success) { rv_obj.status = _lv.status; // stop enterframe this.onEnterFrame = undefined; delete this.onEnterFrame; // call some other method here?? } } function enterFrameHandler() { // do something here? check for timeout? } function getLessonStatus(userid, courseid) { // loop while loading data this.onEnterFrame = this.enterFrameHandler; this._lv.userid = userid; this._lv.courseid = courseid; this._lv.sendAndLoad(LESSON_STATUS_URL, this._lv); } this._lv:LoadVars = new LoadVars(); this._lv.onLoad = Delegate.create(this, this.loadvarsLoadHandler); this.getLessonStatus(val1, val2); Not sure if this is what you're after though.. regards, Muzak ----- Original Message ----- From: "ej" <[EMAIL PROTECTED]> To: <flashcoders@chattyfig.figleaf.com> Sent: Thursday, May 24, 2007 8:09 PM Subject: [Flashcoders] LoadVars and (non)blocking behavior > > > Here is the problem: I want to write a function that makes an outside > communication with a web server and exhibits to the caller blocking bahavior. > That is, I call something like getUserStatus(userid), and it either returns > with the value I want from my database (ColfFusion page), or after some > reasonable amount of time, if I'm not able to communicate with that page, it > returns a special value indicating so. > > As best as I can tell, what is happening behind the scenes for a LoadVars > object is it is essentially forking a new thread to handle this communication > asynchronously from what the thread that invoked LoadVars.sendAndLoad() is > doing. > > ActionScript, being a programming language for non-programmers, makes no > mention whatsoever of threads, nor do I see any way to call a sleep function > or > a yeild function on the current thread (i.e., some way to tell 'this' thread > to > just chill for a sec and let other threads do what they need to do). > > There is the setInterval() function, but again this appears to simply be > forking another thread to periodically call another callback - the code that > is > calling setInterval() itself essentially returns immediately and then proceeds > to do whatever it is doing. But what I want to do next depends on the value I > am trying to read. > > So, I figured, "Fine!" I'll just busy wait until my callback has done what it > needs to do. But the problem is that my busy waiting seems to be blocking my > callback from doing what it needs to do. > > Below is my attempt at a blocking function. On the stage I simply have a > bunch > of dynamic text fields that I set the values of to see what is going on. > Regardless of what I set the timeout value to, shortly after that that > result_lv.onLoad gets called, I get back a 200 HTTP status, and my expected > value is returned from ColdFusion. Unfortunately, my main thread has already > seen the timeout by then. > > So... I'm not seeing how to get this to work right. This must be a common > problem people are handling some other way - can someone help me out? > > > // Wouldn't it be nice if Flash's editor were smart enough to auto-indent > // with spaces instead of tabs? Then this code would look right when I > // paste it. > _______________________________________________ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com