9 Replies Latest reply on Sep 15, 2009 3:31 PM by kglad

    Get URL

    Ron Colmen Level 2

      1. How to receive the browser URL? I'd like to have the AS 2.0 code.

       

      2. In a form - how to avoid "required fields" been sent blank (E.g. Hitting the space key)? ANy perticular script.

        • 1. Re: Get URL
          kglad Adobe Community Professional & MVP

          1.  use getURL() if you want to open a new browser window or change what's loaded into the current browser window.  and use the _url property of the main timeline if you want to know the swf's url.  if you want to know the embedding html's url, use javascript and the externalinterface class.

           

          2.  i have no idea what you're asking.

          • 2. Re: Get URL
            Ron Colmen Level 2

            1. Embedding html's url - Could you show me a sample code?

             

            2. In a FORM - I have several fields as "REQUIRED FIELDS". I dont want someone just pressing the space bar for those REQUIRED FIELDS and hitting the submit button. How to make sure the REQUIRED FIELDS are filled with charactors rather than *,#,%,^, spaces ?

            • 3. Re: Get URL
              kglad Adobe Community Professional & MVP

              1.  in your html:

               

              <script language="JavaScript">

              function urlF(){
              return location.href;

              }
              </script>

               

              in your flash:

               

              import flash.external.*;

              var urlS:String = String(ExternalInterface.call("urlF"));

              trace(urlS)

               

               

              2. use testF() to test if any string contains, at least, n alpha-numeric characters by using testF(anystring,n)

               

              var alphaNumS:String = "0123456789abcdefghijklmnopqrstuvwxyz";

               

              testF(s:String,n:Number):Boolean{

              var num:Number=0;

              for(var i=0;i<s.length;i++){

              if(alphaNumS.indexOf(s.substr(i,1).toLowerCase())>-1){

              num++;

              }

              (num<n) ? return false: return true;

              }

              • 4. Re: Get URL
                Ron Colmen Level 2

                 

                Could the actionscript code be asigned to a dynamic text box? I need the URL to show in a dynamic text box at runtime.

                • 5. Re: Get URL
                  kglad Adobe Community Professional & MVP

                  then assign urlS to a textfield's text property:

                   

                  urlTF.text=urlS;

                   

                  and testF() should have another curly bracket:

                   


                   

                  var alphaNumS:String = "0123456789abcdefghijklmnopqrstuvwxyz";

                   

                  testF(s:String,n:Number):Boolean{

                  var num:Number=0;

                  for(var i=0;i<s.length;i++){

                  if(alphaNumS.indexOf(s.substr(i,1).toLowerCase())>-1){

                  num++;

                  }

                  }

                  (num<n) ? return false: return true;

                  }

                  • 6. Re: Get URL
                    Ron Colmen Level 2

                    CORRECT?

                     

                    1.  Add to html:

                     

                    <script language="JavaScript">

                    function urlF(){
                    return location.href;

                    }
                    </script>

                     

                    in flash - main timeline:

                    import flash.external.*;

                    var urlS:String = String(ExternalInterface.call("urlF"));

                    trace(urlS)

                    theurl.text=urlS;

                     

                    ------------------------------------------------------------------------------------------ --------------------------------------------------

                     

                     

                    var alphaNumS:String = "0123456789abcdefghijklmnopqrstuvwxyz";


                    testF(s:String,n:Number):Boolean{

                    var num:Number=0;

                    for(var i=0;i<s.length;i++){

                    if(alphaNumS.indexOf(s.substr(i,1).toLowerCase())>-1){

                    num++;

                    }

                    }

                    (num<n) ? return false: return true;

                    }

                    • 7. Re: Get URL
                      kglad Adobe Community Professional & MVP

                      yes

                      • 8. Re: Get URL
                        Ron Colmen Level 2

                        Thanks!!

                         

                        • 9. Re: Get URL
                          kglad Adobe Community Professional & MVP

                          you're welcome.