ActionScript 中的 JavaScript 警报

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9769831/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 07:46:48  来源:igfitidea点击:

JavaScript Alert in ActionScript

javascriptactionscript-3flashactionscript

提问by Umesh Patil

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

我们可以轻松地在 java 脚本中提醒任何事情。是否有可能在 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 ?

我在动作脚本中有以下测试类。Trace 与 java 脚本中的 console.log() 相同。是否可以在动作脚本中显示消息?

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:

根据 philipp 的建议,我在actionscript 文档上测试了以下课程

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 ?

上面的代码提醒类似于 javascript 的“测试”。这是一个显示消息的 Flash 窗口。但是如何在我的班级中集成类似的代码。即如何trace ("something")使用此 Flash Alert 窗口进行替换?

回答by philipp

you can use the ExternalInterface.call() method... look here

您可以使用 ExternalInterface.call() 方法...看这里

f.e.:

铁:

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

回答by philipp

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,

警报可以通过两种方式在 Flash 环境中完成:

1.最好的方式是使用ExternalInterface。它调用 javascript 警报功能并相应地显示内容。例如,

import flash.external.ExternalInterface;

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

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

加载到 html 中的 swf 应调用警报窗口。


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.Alertis available only in flash mx2004 and flex environment.


2.第二种方法是编写您自己的自定义 Flash 组件/类,它显示一些带有 textfield 的影片剪辑。您需要编写函数来处理按钮单击(“确定”)时的可见性。

像 alert.show 这样的东西在 flash cs3 及更高版本中是不可能的,因为组件mx.controls.Alert仅在 flash mx2004 和 flex 环境中可用。

回答by sush

try adding the following line of code. alert.show("alerts")method

尝试添加以下代码行。 alert.show("alerts")方法