First, there is a SWF file, test.swf, and there is also an automatically generated HTML file, test.html.
Then, in another file, test.jsp, through the IFRAME, the introduction of the test.html, that is, the introduction of SWF.
Now I want to pass the argument to flex in test.jsp, and call the methods in Flex, and I'm going to use the following method:
First, write a method to invoke flex in the JSP, as follows
Copy Code code as follows:
function initswf () {
Get the object of the SWF
var obj = window.frames["Rightframe"]. Reversequery; Rightframe is the name of the IFRAME, Reversequery is in test.html, introducing the ID of the SWF as object.
How to call it
var start = "<%=startPoint%>";
var end = "<%=endPoint%>";
Obj.showparams (Start,end);
}
In HTML, there are methods
/* In Flex can only call the JS method of this page * *
function initswf () {
Parent.initswf ();
}
In Flex, there are the following methods:
Public Function Showparams (start:string,end:string): void{
Alert.show (start);
Alert.show (end);
}
At this point, you need to create a bridge between them to open communication, in flex initialization, to use
Externalinterface.addcallback ("Showparams", showparams); The former is the name of the method it exposes to JS, and the latter is its method name in Flex.
In this way, it is theoretically possible to implement the call. The Initswf method can be implemented in the OnLoad method of the page.
However, a problem arises that if Flex does not load successfully on the page, it will report an error that does not find the object. Therefore, we need to make sure that the SWF file is loaded and then invoke the method in the SWF.
But listening to it loaded completed obviously a little wasteful feelings, so, we adopt the strategy is, and so it loaded, and then call JS initswf method, you can get through all the links.
So, in the case of flex initialization, join
Invoke the Initswf method of a loaded page
Externalinterface.call ("initswf"); It is to be placed after registering the external method.
Done.
There are areas to be noted:
In the flex Call JS method, this method can only write in the introduction SWF file, but I introduced the JSP in the HTML, so can only be in the HTML of JS, is called the parent page of the JS method.
In the JSP for the SWF file reference, with the help of window.frames["Rightframe"]