A callback function is a function called by a function pointer. If you pass the pointer (address) of a function to another function as an argument, when the pointer is used to call the function it points to, we say this is a callback function. The callback function is not called directly by the implementation method of the function, but is called by another method when a particular event or condition occurs, and is used to correspond to the event or condition.
Below or through the way of the Code, to implement a callback function application.
Flexcallback.mxml
Copy Code code as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<s:application xmlns:fx= "http://ns.adobe.com/mxml/2009"
Xmlns:s= "Library://ns.adobe.com/flex/spark"
xmlns:mx= "Library://ns.adobe.com/flex/mx" width= "100%" height= "100%" >
<fx:Script>
<! [cdata[
Import Flash.external.ExternalInterface;
Import flash.system.Security;
Import Mx.controls.Alert;
Import mx.events.FlexEvent;
public var callbackinfo:string = "";
Public Function Dosend (): void{
var Call:flexapp = new Flexapp ("Hello", callBack);
}
Public function CallBack (info): void{
Alert.show (info);
}
]]>
</fx:Script>
<fx:Declarations>
<!--place non-visual elements (such as services, value objects) here-->
</fx:Declarations>
<s:panel width= "100%" height= "100%" >
<s:button label= "Send" click= "Dosend ()" >
</s:Button>
</s:Panel>
</s:Application>
Flexapp class of your own definition
Copy Code code as follows:
Package
{
public class Flexapp
{
Public Function Flexapp (param:string,func:function)
{
Func.call (NULL, "received");
}
}
}