Skip to main content
Inspiring
September 15, 2009
Answered

Get URL

  • September 15, 2009
  • 1 reply
  • 1363 views

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.

This topic has been closed for replies.
Correct answer kglad

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;

}


yes

1 reply

kglad
Community Expert
Community Expert
September 15, 2009

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.

Inspiring
September 15, 2009

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 ?

kglad
Community Expert
Community Expert
September 15, 2009

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;

}