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 SWF's Object
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.
//Call it by Method
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 establish a bridge between them, using
Externalinterface.addcallback ("Showparams", Showparams) when Flex initializes; 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.
But there is a problem that if Flex does not load successfully on the page, it will report an error that cannot 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.
Therefore, in the initialization of flex, add the
//Call initswf method
Externalinterface.call ("initswf") to load the page;
you are done.
There is a need to note:
in the Flex call JS method, this method can only be written in the SWF file, but I introduced in the JSP HTML, so can only be in the HTML JS, is called the parent page of the JS method.
The reference to the SWF file in the JSP, with the help of window.frames["Rightframe"]