【问题标题】:How to position all alert messages in a particular position of the screen?如何将所有警报消息定位在屏幕的特定位置?
【发布时间】:2013-03-16 05:24:39
【问题描述】:

我开发了一个应用程序,其中包含许多警报消息,我想在屏幕的特定位置显示所有警报消息。我尝试了以下代码,但它适用于单个警报消息。有什么方法可以申请我的应用程序中的所有警报消息。

  myAlert = Alert.show('Hello World');
  PopUpManager.centerPopUp(myAlert);
  myAlert.x = 0;
  myAlert.y = 0;

提前致谢

【问题讨论】:

  • 我认为您不能在 ActionScript 中设置 Alert 消息的位置。相反,您应该创建自己的组件并在 PopupManager 的帮助下显示它。然后,您就可以将其放置在您想要的位置。而是 y
  • 看看这篇文章。在这里,您可以通过自定义实现来控制很多 Alert 的属性。 stackoverflow.com/questions/13775163/…
  • @duTr 为什么不能在 ActionScript 中设置警报的位置? ramesh reddy 如果您显示的代码有效;为什么不直接删除“centerPopUp”并直接设置 x 和 y 值?您可以轻松地将该代码封装到方法中。您可以将其创建为静态方法或将其放在某个共享类中以便在任何地方轻松访问它。
  • 在我的应用程序中有很多警报消息,我不想单独设置 x 和 y 属性,我希望它在全局范围内发生。有没有办法做到这一点?
  • 对不起,我不知道该怎么说:“您可以轻松地将该代码封装到方法中。您可以将其创建为静态方法或将其放入某个共享类中以在任何地方都可以轻松访问它”。如果您将 Alert 的创建和定位封装到静态方法中。而不是调用 Alert.show() 你可以做 MyClassWithStaticMethod.StaticMethodToCreateAlert()。

标签: actionscript-3 apache-flex flex4 flex3 flex4.5


【解决方案1】:

就像 www-flextras.com 建议的那样,您可以使用这样的类来放置您的逻辑以定位您的警报消息。

您需要等待CREATION_COMPLETE 事件才能设置警报的位置。请注意,您也可以在以下示例中使用_alert.move(_nextX, _nextY)。

package
{
    import flash.display.Sprite;

    import mx.controls.Alert;
    import mx.core.IFlexModuleFactory;
    import mx.events.FlexEvent;

    public class MyAlertFactory
    {
        private static const MAX_WIDTH:uint = 320;
        private static const MAX_HEIGHT:uint = 280;

        private static var _nextX:int = 0;
        private static var _nextY:int = 0;

        public static function show(text:String, title:String = "",
                                    flags:uint = 4, parent:Sprite = null,
                                    closeHandler:Function = null,
                                    iconClass:Class = null,
                                    defaultButtonFlag:uint = 4,
                                    moduleFactory:IFlexModuleFactory = null):Alert {

            var alert:Alert = Alert.show(text, title, flags, parent,
                closeHandler, iconClass, defaultButtonFlag, moduleFactory);
            alert.addEventListener(FlexEvent.CREATION_COMPLETE, handleAlertCreation);

            return alert;
        }

        private static function handleAlertCreation(event:FlexEvent):void
        {
            _nextX = (_nextX + 20) % MAX_WIDTH;
            _nextY = (_nextY + 15) % MAX_HEIGHT;

            var alert:Alert = Alert(event.currentTarget);
            alert.x = _nextX;
            alert.y = _nextY;
            alert.removeEventListener(FlexEvent.CREATION_COMPLETE, handleAlertCreation);
        }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-24
    • 1970-01-01
    • 1970-01-01
    • 2015-10-08
    • 2021-12-14
    • 1970-01-01
    相关资源
    最近更新 更多