Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 05-11-2012, 08:00 PM   #1
JeTSpice
Senior Member
 
Join Date: Apr 2009
Posts: 114
Default virtual threading?

I've got a function like this:

private function stopGame():void
{
save();
clear();
}

I'm pretty sure that if save() takes 10 seconds and clear() takes 5, some things might be cleared before they are saved.

But if those functions are chained together...

private function stopGame():void
{
save();
}

private function save():void
{
for (i = 0; i < numGameObjects; i++){//save a game object}
clear();
}

private function clear():void
{
for (i = 0; i < numGameObjects; i++){//clear a game object}
}

...is it possible that the loop in save() is still executing while clear() is called?

In other words, are the lines of code within a function executed procedurally, one after the other? Does Flex wait for the loop to complete before calling clear()?
JeTSpice is offline   Reply With Quote
Old 05-12-2012, 02:53 AM   #2
tadster
tadster
 
tadster's Avatar
 
Join Date: Feb 2009
Location: Texas
Posts: 2,111
Default

Quote:
In other words, are the lines of code within a function executed procedurally, one after the other? Does Flex wait for the loop to complete before calling clear()?
Yes.

And in your first example I think clear only gets called after save is finished.
Here's an example of the single thread nature of AS3

ActionScript Code:
var status:Boolean; private function one(forever:Boolean = true):void {   while(forever) {      three();   }   three(); } private function two():Boolean {   if(status) {      return true;   } return false; } private function three():void {   status = true; } //... case 1 one(true); trace(two()); //the trace is never called and the Flash Player freezes up. //.. case 2 one(false); trace(two()); //traces true.
__________________
www.actiontad.com - ActionScript and JavaScript sitting in a tree...

Last edited by tadster; 05-12-2012 at 03:02 AM.
tadster is offline   Reply With Quote
Old 05-14-2012, 04:44 PM   #3
JeTSpice
Senior Member
 
Join Date: Apr 2009
Posts: 114
Default

Excellent, problem solved. Thank you.
JeTSpice 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 On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:18 AM.

///
Follow actionscriptorg on Twitter

 


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