There are cases where Incidents are not yet ready to play or they are still loading. An example might be an Incident that plays a video or an audio file or a custom Clip that needs some time to render before being able to play.
MotorCortex provides to its developers a convenient way to block and unblock the Clip’s execution via the Incident’s code.
At any point on your Incident you can call the
**this.block()** method which takes just one optional parameter, a string with the description of the block. For example if we were developing an Incident that needs a resource (video, sound, image, whatever else) in order to get executed we would have:
This way, during Clip’s execution if the Incident enters the onProgress method before being ready to get executed it will block the full Clip execution and the Clip will remain halted on the blocking state until it the same Incident unblocks it.
Unblocking the Clip is as simple as blocking it. On our example our Incident can unblock the Clip whenever it’s ready for execution:
As you can see in the example, the only thing we need is to, once our Incident is ready for execution, call the
**this.unblock()** method which will unblock the Clip from the blocking waiting we’ve set before.
In the case of Clips blocking or unblocking can only be related with the readiness of the Clip’s context. A Clip has no execution logic itself, it just sets the context and accepts other Incidents on its timeline so blocking or unblocking the Clip from a Clip can only relate with the Clip being ready or not ready in terms of its context and rendering.
ExtendableClip and DOMClip are equipped with two special blocking / unblocking methods:
By calling the this.contextLoading() method the Clip declares that is in the process of loading its context so if the Clip needs to be executed before this process ends the root Clip will block.
When the Clip is ready (the context has loaded and all rendering and other preparations have been completed, so it’s ready for execution) the Clip can call the this.contextLoaded() method which will unblock the root Clip.