Created
November 2, 2010 03:12
-
-
Save brian428/659216 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function doAsyncChain() : void | |
{ | |
var eventChain : EventChain = new EventChain( dispatcher ); | |
eventChain.addStep( new EventChainStep( new UserEvent( UserEvent.LOAD_USER ) ) ); | |
eventChain.addStep( new EventChainStep( new UserEvent( UserEvent.USER_PROCESSING_COMPLETE ) ) ); | |
eventChain.start(); | |
} | |
[EventHandler( event="UserEvent.LOAD_USER" )] | |
/** | |
* Since this event handler method returns an AsyncToken, Swiz automatically knows that | |
* if the method runs as part of an event chain, it should wait until the asyncronous call | |
* completes before proceeding to the next chain step. | |
*/ | |
public function loadUser() : AsyncToken | |
{ | |
return serviceHelper.executeServiceCall( service.loadUser(), handleUserLoadResult ); | |
} | |
private function handleUserLoadResult( event : ResultEvent ) : void | |
{ | |
// process the result | |
} | |
[EventHandler( event="UserEvent.USER_PROCESSING_COMPLETE " ) | |
public function userProcessingComplete() : void | |
{ | |
// perform logic or dispatch events when the processing finishes | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function doURLRequestChain() : void | |
{ | |
var eventChain : EventChain = new EventChain( dispatcher ); | |
eventChain.addStep( new EventChainStep( new UserEvent( UserEvent.LOAD_USER_IMAGE ) ) ); | |
eventChain.addStep( new EventChainStep( new UserEvent( UserEvent.USER_PROCESSING_COMPLETE ) ) ); | |
eventChain.start(); | |
} | |
[EventHandler( event="UserEvent.LOAD_USER_IMAGE" )] | |
/** | |
* Load an image. Since this event handler method returns an IAsynchronousOperation, | |
* Swiz automatically knows that if the method runs as part of an event chain, it should wait | |
* until the operation completes before proceeding to the next chain step. | |
*/ | |
public function loadUserImage( event : UserEvent ) : IAsynchronousOperation | |
{ | |
var request : URLRequest = new URLRequest( targetImagePath ); | |
var loader : URLLoader = urlRequestHelper.executeURLRequest( request, handleUserImageResult ); | |
return new AsynchronousIOOperation( loader ); | |
} | |
private function handleUserImageResult( event : Event ) : void | |
{ | |
// process the result | |
} | |
[EventHandler( event="UserEvent.USER_PROCESSING_COMPLETE " ) | |
public function userProcessingComplete() : void | |
{ | |
// perform logic or dispatch events when the processing finishes | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.swizframework.utils.async.AsynchronousEvent; | |
/** | |
* By extending AsynchronousEvent (or implementing IAsynchronousEvent), the event can keep track | |
* of the chain step it is associated with. This allows the event to participate in asynchronous | |
* event chains. | |
*/ | |
public class UserEvent extends AsynchronousEvent | |
{ | |
public static const LOAD_USER : String = "UserEvent.LOAD_USER"; | |
public static const LOAD_USER_IMAGE : String = "UserEvent.LOAD_USER_IMAGE"; | |
public static const USER_PROCESSING_COMPLETE : String = "UserEvent.USER_PROCESSING_COMPLETE"; | |
public function UserEvent( type : String ) | |
{ | |
super( type, true, false ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment