简体   繁体   中英

How to create an Alert Dialog in Actionscript 3 without the Flex Framework in a standalone AIR application designed to run on Windows

I've got a project, written in Actionscript 3, built using Flash CS5. In it, there are sections that require a microphone to be plugged in and the programmer who preceded me notified the user of the lack of microphone by throwing an Error. This causes the program to stop running, a behavior which in undesirable.

The question: How to create a popup alert dialog in as pure as possible Actionscript. I've found the Alert class in mx.controls, but I can't find a way to add it to the project. I found the Yahoo AlertManager class, but couldn't get it to work properly and it looks like the framework around it is larger than I need.

This is deployed on touchscreens as a standalone application on a Windows 7 Environment using AIR 2.5, Flash CS5, Actionscript 3.0. I use FlashDevelop as the AS editor.

You'll have to make your own alert box, either by making NativeWindow instance and editing it, or (what I would recommend) making your own custom class that extends NativeWindow .

This is a simple generalized version of one that I made for one of my apps:

package  
{
    import flash.display.*;
    import flash.geom.*;

    public class AlertWindow extends NativeWindow 
    {

        public function AlertWindow(owningWindow:NativeWindow, windowTitle:String) 
        {
            var initOptions:NativeWindowInitOptions = new NativeWindowInitOptions();
            initOptions.maximizable = false;
            initOptions.minimizable = false;
            initOptions.resizable = false;
            initOptions.owner = owningWindow;
            initOptions.type = NativeWindowType.UTILITY;

            super(initOptions);

            title = windowTitle;
            alwaysInFront = true;
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;

            bounds = new Rectangle(owner.x + owner.width - (owner.width / 2) - 125, owner.y + owner.height - (owner.height / 2) - 75, 250, 150);
        }
    }
}

I whipped it up fairly quickly so it might not be as clean or efficient as it could be but it should be a good base to start on. Obviously you can add stuff like messages, buttons, event listeners, and anything else.

If you don't understand all of the code you should check out the NativeWindow and NativeWindowInitOptions documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM