我正在开发一个使用 Adobe flash Builder 的应用程序,一旦触发特定事件,它就会弹出一个警报窗口。 当警报框关闭时需要调用另一个事件。但我在 mx.controls 库中没有看到 Alert 类。似乎该类(存在于 AS2 中)已从 AS3 中删除。有没有其他方法可以实现相同的功能?
谢谢, 普里泰什
您需要为您的警报控件定义 closeHandler。从此处查看 ActionScript 3.0 参考 api http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/Alert.html#show()
使用外部接口。
import flash.external.ExternalInterface;
// tell flash what javascript function to listen for, and what flash function to call in response
ExternalInterace.addCallback('onAlertWindowClosed', onPopupClosed);
function openPopUp():void
{
// this conditional prevents errors when running local (yes, this needs uploaded to work)
if(ExternalInterface.available)
{
// this calls a javascript function in your html
ExternalInterface.call('myJavascriptAlertFuntion');
}
}
// this function is called from the javascript callback **onAlertWindowClosed**
function onPopupClosed():void
{
// do something when your popup closes
}
在 html 中:
<script type="text/javscript>
// this chunk gets the flash object so you can call its methods
function getFlashMovieObject(movieName)
{
if (window.document[movieName])
{
return window.document[movieName];
}
if (navigator.appName.indexOf("Microsoft Internet") == -1)
{
if (document.embeds && document.embeds[movieName])
return document.embeds[movieName];
}
else
{
return document.getElementById(movieName);
}
}
// function that is called from flash
function myJavascriptAlertFuntion()
{
alert("Hey! Yeah you there!");
}
// call this when you want to tell flash you are closing your popup
function tellFlashMyPopupWindowClosed()
{
// **flashContainer** should be replaced by the name parameter of your flash embed object
var flashMovie = getFlashMovieObject("flashContainer");
flashMovie.onAlertWindowClosed();
}
</script>
要在使用 MXML 和 AS3 的移动项目中拥有弹出警报,您需要创建一个基于 Sparks 组件中的 SkinnablePopUpContainer 的组件。 (因为已经方便地排除了简单的警报。)
我在此处的文档中阅读了 SkinnablePopUpContainer 并学到了很多:
Spark SkinnablePopUpContainer 容器
总而言之,我在 MXML 中创建了一个以 SkinnablePopUpContainer 作为基类的组件。在我想要添加弹出窗口的视图中,我在 Actionscript 中创建了该类的一个新实例。我监听组件中的按钮将在用户响应时触发的自定义事件。要显示新的弹出组件,只需调用静态方法 open(); 即可。 open() 方法需要一个父容器,并且弹出窗口是否应该是模态的。模态意味着组件下的任何内容都不能接收用户输入。
var alert:SkinnablePopUpContainer = new SkinnablePopUpContainer;
alert.addEventListener( "OK", onOK );
alert.open( this, true );
function onOK(e:Event):void{ trace("User said OK") };
稍后我会尽可能提供一些示例文件。