Search code examples
javascriptactionscript-3flashflash-cs6

Cant see Alert Box after clicking a button


function showAlert():void
{
    var alert:URLRequest = new URLRequest("javascript:alert('Please enter your User name')");
    navigateToURL(alert, "");
}

I can't see the alert box (pop-up) after clicking button. What is the source of the problem? Even if I tried 3 different browser it doesn't work.


Solution

  • ExternalInterface is the standard way of communicating between AS3 and JS (see documentation):

    import flash.external.ExternalInterface;
    
    function showAlert() 
    {
        // Check ExternalInterface is available
        if (ExternalInterface.available) 
        {
            ExternalInterface.call("alert", "Please enter your User name");
        }
    }