# Help with automatically generating URLs

**URL:** <https://forum.kirupa.com/t/help-with-automatically-generating-urls/307112>\
**Category:** flash\
**Created:** [March 28, 2010, 6:20pm UTC](https://forum.kirupa.com/t/help-with-automatically-generating-urls/307112 "2010-03-28T18:20:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ikerson](https://avatars.discourse-cdn.com/v4/letter/i/b782af/32.png) [@ikerson](https://forum.kirupa.com/u/ikerson)\
**Post date:** [March 28, 2010, 6:20pm UTC](https://forum.kirupa.com/t/help-with-automatically-generating-urls/307112/1 "2010-03-28T18:20:43Z")

</div>

Does the code I’ve written to automatically generate URLs work?  
I am creating a duel-language website and I am trying to create flash buttons which switch between the Korean and English pages.

The Korean pages all end with “\_kr.html”  
The English pages end with “\_en.html”

Below is the code I’ve come up with. Can you tell me if it will work? And, if not, how would you recommend I fix it?

```auto
import flash.external.*;
var currentUrl:String = String( ExternalInterface.call(" function(){ return document.location.href.toString();}"));
	//function uses java script to get current url from browser

var englishUrl:String = currentUrl;
var englishReplace:RegExp = /_kr/gi;
trace(englishUrl.replace(englishReplace, "_en"));
    //replaces "kr" in current url with "en"
	
var koreanUrl:String = currentUrl;
var koreanReplace:RegExp = /_en/gi;
trance(koreanUrl.replace(koreanReplace, "_kr"));
	//replaces "en" in current url with "kr"
	
engSwitch.addEventListener(MouseEvent.MOUSE_DOWN, mouseEngHandler);
function mouseEngHandler(event:MouseEvent):void {
    navigateToURL(new URLRequest(englishUrl));
}
	//navigates to English version of current page
	
koreanSwitch.addEventListener(MouseEvent.MOUSE_DOWN, mouseKoreanHandler);
function mouseKoreanHandler(event:MouseEvent):void {
    navigateToURL(new URLRequest(koreanUrl));
}
	//navigates to Korean version of current page

```

I am totally new to ActionScript 3.0 and this is basically a cut-and-past job from posts from three different sources: [Flashthusiast.com, [URL=“http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs\_Parts&file=00000076.html”]AdobeLiveDocs, and [URL=“http://www.actionscript.org/forums/showthread.php3?t=150218”]ActionScript.org](http://flashthusiast.com/2008/03/13/adding-more-than-one-button-to-a-fla-file-while-rocking-it-in-actionscript-30/http:/flashthusiast.com/2008/03/13/adding-more-than-one-button-to-a-fla-file-while-rocking-it-in-actionscript-30/). I would greatly appreciate any help you can provide a struggling novice.

Thank you in advance.
