JavaScript Alert in ActionScript

actionscriptactionscript-3flashjavascript

We can easily alert anything in java script. Is it possible to get this or similar alert in ActionScript ?

I have below test Class in Action Script. Trace does same as console.log() in java script. Is it possible to display messages in action script ?

package  {
    import flash.display.MovieClip; 
    public class ooas3 extends MovieClip{
        public var color:String = "red";
        public var num:Number = 100;
        public function ooas3() {
            theMovie_DoFSCommand(color,"ooas3 num is "+num);
        }


        function theMovie_DoFSCommand(color, args) {
                if (command == "red") {
                 trace(command + " - " + args);
        // Can above line is replaced by Alert similar to java Script Alert ?        
                }
        }       
    }   
}

As per the philipp's adivice I tested the below class on actionscript docs:

package {
       import flash.text.TextField;
       import flash.display.MovieClip;
       import flash.external.ExternalInterface;

       public class extint_test extends MovieClip {
         public function extint_test() {
           var isAvailable:Boolean = ExternalInterface.available;
           var availTxt:TextField = new TextField();
           availTxt.text = isAvailable.toString();
           addChild(availTxt);
         }
       }
     }

Above code alerts the "test" similar to javascript. This is a Flash Window that shows the message. But How to integrate similar code in my Class. i.e. How to do repalce trace ("something") with this Flash Alert window ?

Best Solution

Alerts can be done in Flash environment in 2 ways :

1. The best way is to use ExternalInterface. It calls up the javascript alert function and displays content accordingly. For example,

import flash.external.ExternalInterface;

ExternalInterface.call("alert", "Hello ExternalInterface");

The swf when loaded in html shall invoke the alert window.


2. The second way is to write your own customized flash component/class which displays some movieclip with textfield . You need to write the functions to handle its visibility on button click("OK")

Something like alert.show is not possible in flash cs3 and above as the component mx.controls.Alert is available only in flash mx2004 and flex environment.