Working with exceptions with Adobe Flex and Zend AMF

Some programming languages have the capability of working with exceptions such as PHP, ActionScript 3.0, Java, C # etc.. It is a resource that if properly used, it is powerful and help prevent future headaches for your system. An exception is nothing more than the possibility of treating an error without necessarily stop completely your program.
Support for exceptions was added in PHP since version 5, and may be using in conjunction with Adobe Flex, this case will use the Zend AMF, an implementation of the AMF protocol for working together with the Flash Platform and its server- side running PHP as part of ZendFramework.
It is considered a best practice you create your exception class extending the class Zend_Exception.
[PHP]

[/PHP]
In Flex we usually call the method using the RemoteObject class.
[ACTIONSCRIPT3]
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
ro = new RemoteObject();
ro.destination = “nao faz diferença nenhuma usando com Zend AMF”;
ro.endpoint = “http://localhost:81/ZendAmf/teste_exception.php”;
ro.source = “br.com.leonardofranca.HelloException”;
ro.addEventListener(ResultEvent.RESULT, handlerResult);
ro.addEventListener(FaultEvent.FAULT, handlerFault);
ro.dispatchException();
}
[/ACTIONSCRIPT3]
Our attention will turn to the FaultEvent, he is responsible for catching exceptions coming from the server. Basically just need to show the user the faultString.
[ACTIONSCRIPT3]
private function handlerFault(fault:FaultEvent):void
{
trace(fault.fault.faultCode);
trace(fault.fault.faultDetail);
trace(fault.fault.faultString);
Alert.show(fault.fault.faultString,”Atenção”);
}
[/ACTIONSCRIPT3]
We have the following result:

Exception


Code completion:
Download PHP
Download Flex

Was this article helpful? feel free to make a donation and help keep the blog in the air
ActionScript 3.0, Flex, PHP, ZendAMF

1 comment


  1. Hi – I am really delighted to discover this. cool job!

Leave a Reply