Sie sind auf Seite 1von 3

Flex Main points

Using compiler tags


Compiler tags are tags that do not directly correspond to ActionScript objects or properties. The
names of the following compiler tags have just the first letter capitalized:

 <mx:Binding>
 <mx:Component>

 <mx:Metadata>

 <mx:Model>

 <mx:Script>

 <mx:Style>

 <mx:XML>

 <mx:XMLList>

The following compiler tags are in all lowercase letters:

 <mx:operation>
 <mx:request>

 <mx:method>

 <mx:arguments>

MXML tag rules


MXML has the following syntax requirements:

 The id property is not required on any tag.


 The id property is not allowed on the root tag.

 Boolean properties take only true and false values.

 The <mx:Binding> tag requires both source and destination properties.

 The <mx:Binding> tag cannot contain an id property.

 The <mx:WebService> tag requires a wsdl value or destination value, and does
not allow both.
 The <mx:RemoteObject> tag requires a source value or a named value, and does
not allow both.
 The <mx:HTTPService> tag requires a url value or a destination value, and
does not allow both.
 The <mx:operation> tag requires a name value, and does not allow duplicate name
entries.
 The <mx:operation> tag cannot contain an id property.

 The <mx:method> tag requires a name value and does not allow duplicate name
entries.
 The <mx:method> tag cannot contain an id property.

Sometimes it might be necessary to call a Javascript function from your Flex application.
The technique is quite simple. It involves sending the Javascript function name along with
any parameters to the ExternalInterface class. For example, let's assume that a Javascript
function called changeMainContent was defined to take a tag name (id) and a url. Normally
using Javascript the functions is called this way: changeMainContent(id, url). Let's define a
Flex method that invokes this Javascript method:

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:

Handling Java Exceptions in Flex


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.

Das könnte Ihnen auch gefallen