为什么在Flash ide中可以使用ExternalInterface

ant*_*paw 1 javascript flash actionscript actionscript-3

嘿我正在尝试构建这个简单的调试器类,所以我可以在浏览器控制台中看到flash变量,如果我在flash ide中测试它,我会得到好的旧跟踪器.但由于某种原因ExternalInterface.available返回trueFlash ide!

package libs
{
    import flash.external.ExternalInterface;

    public class debug
    {
        public function tracer(variable:*):void
        {
            if(ExternalInterface.available)
            {
                if(variable is String)
                {
                    variable = '"'+variable+'"';
                }
                ExternalInterface.call('console.log(' + variable + ')');
            }
            else
            {
                trace(variable);
            }   
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

kky*_*kyy 5

您可以使用flash.system.Capabilities.playerType来确定您是否处于flash ide ...

import flash.system.Capabilities;

if (Capabilities.playerType == 'External')
  trace("you're in the ide");
else
  trace("you're not in the ide");
Run Code Online (Sandbox Code Playgroud)