Details
-
Improvement
-
Status: Open
-
Major
-
Resolution: Unresolved
-
Adobe Flex SDK Previous
-
None
-
None
-
Language Found: English
Description
Currently the call to uiComponent.callLater can't be canceled (it returns void).
It would be nice if it can be canceled the same way setInterval() can be canceled.
It is useful in the following use case:
1. Some method of a component is called. Let's name it fillContents(contents)
2. Component is not yet initialized, so it postpones the call using callLater: callLater(fillContents, [contents]);
3. The component becomes initialized somehow (it doesn't matter how - it may be .validateNow(), switching the state of the component to allow its usage or something else).
4. fillContents is called again with another argument: fillContents(anotherContents);
5. Component is initialized now, so fillContents is executed to the end, applying anotherContents
6. ENTER_FRAME fires, postponed call to fillContents(contents) is performed, making the component filled with the older contents.
Now devs should handle this situation deliberately (with flags, for example). It will be easier for developer to cancel the last callLater like this, if it returned some sort of id:
private var lastCallId:int;
function fillContents(contents):void
{
cancelCallLater(lastCallId);
if (!initialized)
// perform actual work
}
It seems to me that this use case of callLater is quite frequent and the solution I propose is very easy to implement and will make the code cleaner and more error-prone.