Actionscript 3,flex:如何找出您目前所在的浏览器?

Rel*_*lla 0 browser apache-flex flash mxml actionscript-3

我需要检测通过AS3里面的flex mxml appication,这是我所在的浏览器 - FF,Chrome,IE等,只有名称和版本.怎么办这样的事情?

Nat*_*ate 8

是的,你将使用javascript,但你实际上并不需要在页面中放置javascript.

这是一个快速脚本示例,可以从您的Flex应用程序获取该信息,而无需向包含的html页面添加任何内容:

<?xml version="1.0"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" 
          creationComplete="creationCompleteHandler(event)">
<fx:Script>
    <![CDATA[
        import mx.events.FlexEvent;

        protected function creationCompleteHandler(event:FlexEvent):void
        {
            var appName : String  = String(ExternalInterface.call("function(){return navigator.appName}"));
            var appVersion : String  = String(ExternalInterface.call("function(){return navigator.appVersion}"));
            var userAgent : String  = String(ExternalInterface.call("function(){return navigator.userAgent}"));
            trace( appName ) ;
            trace( appVersion );
            trace( userAgent );
        }

    ]]>
</fx:Script>
Run Code Online (Sandbox Code Playgroud)

这会将信息跟踪到控制台,例如,当我运行它时,我得到:

Microsoft Internet Explorer
4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; GTB6.6; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; .NET4.0E)
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; GTB6.6; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; .NET4.0E)
Run Code Online (Sandbox Code Playgroud)

如果您有任何问题,请告诉我!