|
|
public function callWrapper(id:String, url:String):void {
var f:String = "changeMainContent";//Javascript function
ExternalInterface.call(f,id, url);
}
Now a call this method when a button is clicked is as follows:
|
|
public function callWrapper(id:String, url:String):void {
var f:String = "changeMainContent";//Javascript function
ExternalInterface.call(f,id, url);
}
Posted by Jon at 4:21 AM
Labels: Flex Vs JAVA
|
|
Accessing the Throwable object in Flex
RemoteObject component invokes the fault event when an error occurs while remote method invocation. The fault event handler is provided with the FaultEvent object. This FaultEvent object has property named message of type mx.messaging.messages.ErrorMessage. The message property holds the Throwable object from the Java method in the rootCause property. We need to use this rootCauseproperty to retrieve the properties which are set to the Throwable object in Java. All the public properties from the Throwable object are available.
We will see a sample application. In this application I am creating a custom Exception and adding a getter method to that, which will return my custom data. From the Flex application I will access both the error message and the custom data.
MyException.java
public class MyException extends Exception {
public MyException(String message) {
super(message);
}
public String getMyName(){
return “Sujit Reddy G”;
}
}
Method throwing exception
This method will throw the custom exception created above, add this method to a Java class. Invoke the below method using RemoteObject component in Flex.
public void throwCheckedException() throws Exception{
throw new MyException(”This is a checked exception”);
}
Reading values in Flex application
We add the method below as the fault event handler to the RemoteObject component in the Flex application. You can see that we accessed the rootCause object to retrieve the properties of the custom Exception object returned from the Java method.
private function handleException(event:FaultEvent):void{
var errorMessage:ErrorMessage = event.message as ErrorMessage;
Alert.show(errorMessage.rootCause.message);
Alert.show(errorMessage.rootCause.myName);
}
We are adding the above method as fault event handler to the RemoteObject component.
fault=”handleException(event)”/>
Invoking the method in the Java class on button click
You can also use the flex.messaging.MessageException. This class is packaged in the flex-messaging-core.jar. You should throw MessagException instead of MyException or any custom exception created. MessageException provides a property named extendedData, which is a HashMap. You can add any data to this property and access it from the Flex application using ErrorMessage(event.message).extendedData.
Posted by Jon at 1:54 AM
Labels: Flex Vs JAVA
|
|
Posted by Jon at 1:52 AM
Labels: Flex Vs JAVA
|
|
I want to get the first element of my "tmps" xml document. Casting the string to a XML document and work on it as a XMLList prevents me from getting the first element in the XMLList as long as the element doesn't contain a child! That simply must be a bug. |
| <?xml version="1.0"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" initialize="init()"> <mx:Script> <![CDATA[ import mx.controls.Alert; import mx.events.*; import flash.events.*; private var work:String = "<tmps><tmp att=\"abc\"><dummy/></tmp></tmps>"; private var wontWork:String = "<tmps><tmp att=\"abc\" /></tmps>"; private function init() : void { result.text = work; } private function clickHandler(event:ItemClickEvent):void { if (event.label == "OK") { result.text = work; } else { result.text = wontWork; } } private function printResult(event:MouseEvent):void { var list :XMLList = XML(result.text).tmp; Alert.show(list[0]); // should print first element in the list - the tmp element } ]]> </mx:Script> <mx:Panel title="Flex bug example" height="100%" width="100%"> <mx:ButtonBar itemClick="clickHandler(event);"> <mx:dataProvider> <mx:Array> <mx:String>OK</mx:String> <mx:String>not OK</mx:String> </mx:Array> </mx:dataProvider> </mx:ButtonBar> <mx:TextArea id="result" editable="false" height="100" width="100%"/> <mx:Button id="evaluate" label="evaluate result" click="printResult(event)"/> </mx:Panel> </mx:Application> |
Posted by Jon at 2:42 AM
Labels: Flex Vs JAVA
|
|
Posted by Jon at 5:34 AM
Labels: Flex Vs JAVA
|
|
Posted by Jon at 5:24 AM
Labels: Flex Vs JAVA