这个问题让我撕裂了我的头发。
症状:从外部界面和navigateToURL组合间歇性地阻止/通过弹出窗口。
问题:Flash(或浏览器......不确定)不会在时间范围和/或事件持续时间之外触发弹出窗口。
环境:我有一个需要通过zendAMF发送数据的应用,做一些处理并发送回flash播放器。在响应上,如果满足某些条件,则触发弹出窗口。在响应中被阻止的相同代码直接从鼠标事件触发器开始工作。
所以我设置了一个基本情况:6个按钮,调用3个方法。 3个按钮将直接调用该方法(全部完全打开窗口),其他三个将获得数值步进器的值,并使用setTimeout(openWinMethod,NumericStepper.value)来模拟来自zendAMF响应的延迟调用。
UPDATE :如果我首先选择'navigateToURL,no delay'按钮,关闭该窗口,然后尝试任何其他延迟调用 - 它们可以正常工作。它就像浏览器接受你在某个时候点击打开一个窗口,因此可以从延迟然后打开。 (仅限firefox)
所有三个使用延迟都将被阻止(firefox和chrome),而所有三个直接打开。 Safari - 以及已记录的内容,仅适用于使用navigateToURL
的2种方法感兴趣:html包装器中的js函数将被称为外部接口以打开一个窗口。没有延迟,这工作。延迟时,将调用js函数(由某些警报语句验证),但从未生成新窗口。
我面临两种选择: 1 - 当我从zenAMF收到我的回复时,更改流程以要求用户单击继续,或 2 - 找出发生这种情况的原因并加以解决(最好)
可以在此处找到演示:http://www.digital.leskiwis.com/as3/popup/
这是我的as3课程:
package
{
import fl.controls.Button;
import fl.controls.NumericStepper;
import flash.display.Sprite;
import flash.events.*;
import flash.text.TextField;
import flash.utils.*;
import flash.net.*;
import flash.external.ExternalInterface;
public class Main extends Sprite
{
private var but1:Button;
private var but2:Button;
private var but3:Button;
private var but4:Button;
private var but5:Button;
private var but6:Button;
private var reporting:TextField;
private var dlay:NumericStepper;
private var url:String = 'http://www.google.com';
private var target:String = "_blank";
public function Main()
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
dlay = new NumericStepper()
dlay.minimum = 0
dlay.maximum = 5
dlay.stepSize = 0.1
addChild(dlay)
but1 = new Button()
but1.label = "External interface window.open, use delay"
but1.addEventListener(MouseEvent.CLICK, onOpenDelay, false, 0, true);
addChild(but1)
but1.width = 300
but1.y = 50;
but2 = new Button()
but2.label = "External interface window.open, no delay"
but2.addEventListener(MouseEvent.CLICK, onOpen, false, 0, true);
addChild(but2)
but2.width = 300
but2.y = 80;
but5 = new Button()
but5.label = "External interface JS, use delay"
but5.addEventListener(MouseEvent.CLICK, onJSOpenDelay, false, 0, true);
addChild(but5)
but5.width = 300
but5.y = 110;
but6 = new Button()
but6.label = "External interface JS, no delay"
but6.addEventListener(MouseEvent.CLICK, onJSOpen, false, 0, true);
addChild(but6)
but6.width = 300
but6.y = 140;
but3 = new Button()
but3.label = "Navigate to url, use delay"
but3.addEventListener(MouseEvent.CLICK, onNavUrlDelay, false, 0, true);
addChild(but3)
but3.width = 300
but3.y = 170;
but4 = new Button()
but4.label = "Navigate to url, no delay"
but4.addEventListener(MouseEvent.CLICK, onNavUrl, false, 0, true);
addChild(but4)
but4.width = 300
but4.y = 200;
reporting = new TextField;
reporting.y = 230
reporting.width = 300;
reporting.height = 170
addChild(reporting);
}
private function onOpen(e:MouseEvent = null):void {
ExternalInterface.call('window.open',url, 'myWin','height=700,width=900,toolbar=no,scrollbars=yes');
tracer('opening window with window.open')
}
private function onOpenDelay(e:MouseEvent):void {
tracer(('opening window in ' + dlay.value + ' seconds...'))
setTimeout(onOpen, dlay.value * 1000)
}
private function onJSOpen(e:MouseEvent = null):void {
tracer('opening window with external js function ...')
var success : Boolean = ExternalInterface.call( "openURL", url, target );
if (!success) tracer('pop up blocked..');
}
private function onJSOpenDelay(e:MouseEvent):void {
tracer(('opening js external in ' + dlay.value + ' seconds...'))
setTimeout(onJSOpen, dlay.value * 1000)
//setTimeout(function():void { ExternalInterface.call( "openURL", url, target ); }, dlay.value * 1000)
}
private function onNavUrl(e:MouseEvent = null):void {
tracer('opening with navigateToURL')
try {
navigateToURL( new URLRequest(url), '_blank');
} catch (e:Error) {
tracer("Error occurred! " + e);
}
}
private function onNavUrlDelay(e:MouseEvent):void {
tracer(('opening navigateToURL in ' + dlay.value + ' seconds...'))
setTimeout(onNavUrl, dlay.value * 1000)
//setTimeout(function():void { navigateToURL( new URLRequest(url), '_blank'); }, dlay.value * 1000)
}
private function tracer(msg:String):void {
trace(msg)
reporting.appendText(msg + '\n');
}
}
}
这是html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>popup test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script script language='JavaScript' type='text/javascript'>
function openURL( url, target )
{
try
{
var popup = window.open( url, target );
if ( popup == null )
return false;
if ( window.opera )
if (!popup.opera)
return false;
}
catch(err)
{
alert('errr...');
return false;
}
return true;
}
</script>
<script type="text/javascript" src="js/swfobject.js"></script>
<script type="text/javascript">
var flashvars = {};
var params = {wmode:"opaque",allowScriptAccess:"always"};
//var params = {allowScriptAccess:"sameDomain"};
var attributes = {};
attributes.id = "popupTest";
attributes.name = "popupTest";
swfobject.embedSWF("swf/popup2.swf", "altContent", "400", "400", "9.0.0", "swf/expressInstall.swf", flashvars, params, attributes);
</script>
</head>
<body>
<div id="altContent">
</div>
</body>
</html>
答案 0 :(得分:0)
请阅读:User Interaction Requirements
您会注意到,在“弹出窗口”下,externalInterface和navigatetoURL都列为仅响应用户交互。如果你运行一个花费太长时间的脚本,基本上你正在做的事情将被阻止。
如果你想做这样的事情,那么id要么使用ExternalInterface调用一个javascript来调用和响应外部页面信息,然后用布尔值回复到flash或打开弹出窗口然后让它调用并回复外部页面(如果没有,则显示错误信息等)。
确切地取决于你对zend的所作所为。