出差了好长时间,终于要回京了! :lol:
在开发过程中Flex 与 JavaScript 相互调用是在所难免,在国内很少有单纯的Flex Web应用。
Flex内建了ExternalInterface提供与Javascript的互操作。示例程序为ExternalInterface的应用,还包括了弹出窗口是否被拦截的判断。
文档可以在下面的地址查看:
[url]http://livedocs.adobe.com/flex/3/langref/index.html[/url]
[url=http://myflex.googlecode.com/svn/trunk/flexTips/bin-debug/DetectPopupBlocked.html]查看示例[/url]
[url=http://code.google.com/p/myflex/source/browse/#svn/trunk/flexTips]查看示例源码[/url]
将Flex方法暴露给JavaScript
src/DetectPopupBlocked.mxml
JavaScript调用Flex方法
html-template/index.template.html
Flex调用Javascript 函数,弹出窗口,并且判断弹出窗口是否被拦截。
src/DetectPopupBlocked.mxml
html-template/index.template.html
-------------------------------------
It's Neal Mi. I'm a man of my world.
在开发过程中Flex 与 JavaScript 相互调用是在所难免,在国内很少有单纯的Flex Web应用。
Flex内建了ExternalInterface提供与Javascript的互操作。示例程序为ExternalInterface的应用,还包括了弹出窗口是否被拦截的判断。
文档可以在下面的地址查看:
[url]http://livedocs.adobe.com/flex/3/langref/index.html[/url]
[url=http://myflex.googlecode.com/svn/trunk/flexTips/bin-debug/DetectPopupBlocked.html]查看示例[/url]
[url=http://code.google.com/p/myflex/source/browse/#svn/trunk/flexTips]查看示例源码[/url]
将Flex方法暴露给JavaScript
src/DetectPopupBlocked.mxml
[Bindable]
private var greeting:String="What?";
private function init():void{
if(ExternalInterface.available){
ExternalInterface.addCallback("saySomething", saySomething);
}
}
public function saySomething(_greeting:String):void{
trace(_greeting);
greeting = _greeting;
}
JavaScript调用Flex方法
html-template/index.template.html
function saySomethingToFlex(bla){
${application}.saySomething(bla);
}
Flex调用Javascript 函数,弹出窗口,并且判断弹出窗口是否被拦截。
src/DetectPopupBlocked.mxml
private function openNewBrowserWindow(url:String, name:String):void{
if(ExternalInterface.available){
var opened:Boolean = ExternalInterface.call("openPopup", url, name);
if(!opened){
Alert.show("Popup Blocked!");
}
}
}
html-template/index.template.html
function openPopup(url, name){
var popwindow;
popwindow = window.open(url, name, "menubar=false,resizable=false,width=790,height=500");
// detect popup blocked
if (popwindow==null || typeof(popwindow)=="undefined"){
return false;
}
return true;
}
-------------------------------------
It's Neal Mi. I'm a man of my world.