0

I'll have some task for the user to do, so I'll make an Array(false, false, false, ... number of tasks) and each element will become true when completed, so I'll know when all will be completed and witch one is still incomplete. Usually I create an int to count the tasks when created, and that decrease, but I need to control each item this time (you didn't complete this one...), not only the global progress.

So, I got only the number of tasks:

var Ctrl:Array = new Array();
for(var i=0; i<numberOfTasks; i++){ Ctrl.push(false); }

If I have a lot of tasks, this way may take a while freezing the execution. Is there some "automatic" way?

2 Answers 2

2

You can also create array and verify if array[task] is undefined , it was not set and its for You equal false .

var ctrl:Array = new Array();
var maxTasks:int = 100;// doesnt matter here
var tasksComplete:int = 0;// if You dont like to loop each time
function completeTask(id:int):void{
    ctrl[id] = true;
    tasksComplete ++;
}
function isTaskComplete(id:int):Boolean{
    return ctrl[id]?true:false;
}
Sign up to request clarification or add additional context in comments.

1 Comment

This is working in my tests, and is a simple way, the best solution IMO.
1

You can use dictionary instead of Array.

Like this

var dic:Dictionary = new Dictionary();

var task:Task = new Task();
task.addEventListener(Event.Complete, onTaskComplete);
dic[task] = false; //you will set false value only the task executes
task.execute();

private function onTaskComplete(e:Event):void {

  var task:Task = e.target as Task;

  dic[task] = true;

  //check the dic if all tasks are finished
}

1 Comment

Where did you get Task from? And the last comment about checking the 'dic' isn't it the same as what the OP is trying to avoid?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.