Skip navigation
Currently Being Moderated

how to detect browser & version?

Apr 24, 2012 12:03 AM

how to detect browser & version in as3?

 
Replies
  • Currently Being Moderated
    Apr 24, 2012 1:15 AM   in reply to Venkom

    Hi Venkon,

     

     

    You can use ExternalInterface.call("window.navigator.userAgent") with this u can detect the browser details.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 24, 2012 9:11 PM   in reply to Venkom

    Use this code

     

    package

    {

        import flash.display.Sprite;

        import flash.external.ExternalInterface;

        import flash.events.MouseEvent;

        import fl.transitions.Tween;

        import fl.motion.easing.Elastic;

     

        public class Main extends Sprite

        {

            private var userAgent:String;

     

            public function Main():void

            {

                more.addEventListener(MouseEvent.MOUSE_UP, showFull);

                browserTxt.text = getUserAgent();

           

            }

     

            private function getUserAgent():String

            {

                try

                {

                    userAgent = ExternalInterface.call("window.navigator.userAgent.toString");

                    var browser:String = "[Unknown Browser]";

     

                    if (userAgent.indexOf("Safari") != -1)

                    {

                        browser = "Safari";

                    }

                    if (userAgent.indexOf("Firefox") != -1)

                    {

                        browser = "Firefox";

                    }

                    if (userAgent.indexOf("Chrome") != -1)

                    {

                        browser = "Chrome";

                    }

                    if (userAgent.indexOf("MSIE") != -1)

                    {

                        browser = "Internet Explorer";

                    }

                    if (userAgent.indexOf("Opera") != -1)

                    {

                        browser = "Opera";

                    }

                }

                catch (e:Error)

                {

                    //could not access ExternalInterface in containing page

                    return "[No ExternalInterface]";

                }

     

                return browser;

            }

     

            private function showFull(e:MouseEvent):void

            {

                info.fullInfo.text = userAgent;

                var tween:Tween = new Tween(info,"y",Elastic.easeOut,info.y-10,180,0.5,true);

            }

        }

    }

     

     

    place a textfield on stage with instance browserTxt and a button with instance more and movieclip with instance info inside movieclip place a textfield with instance fullInfo. Test it

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points