If you ask me two of the most painful things while moving from as2 to as3 have been button actions and hyperlinking to a website.. and ironically those are the most common tasks for a flash designer/developer.
According to most of the blogs, forums and even the adobe site the way to code button actions with a hyperlink is like so
myButton_btn.addEventListener(MouseEvent.MOUSE_OVER, mysite);
function mysite(event:MouseEvent) {
var req1:URLRequest=new URLRequest("http://www.mysite.com");
navigateToURL(req1,"_self");
}
While this works great for a button or two, but if you have say a navigation bar of buttons or say hot spots on a map you are going to have to copy paste that whole code multiple times and keep changing the function name and url for each of them, which is totally going against DRY
In such situations I usually prefer to create a single function and pass the site link as a parameter to the function. The new code could look something like this
function siteLink (myurl:String):Function{
return function():void{
var req1:URLRequest=new URLRequest(myurl);
navigateToURL(req1,"_self");
}}
myButton_btn.addEventListener("mouseDown",siteLink("www.mysite.com"));
yourButton_btn.addEventListener("mouseDown",siteLink("www.yoursite.com"));
You could have this function on the first keyframe on the root and reuse the same function for buttons that you’d have within movieclips , you’ll need to slightly modify the code to this
var myroot = root;
ourButton_btn.addEventListener("mouseDown",myroot.siteLink("www.oursite.com"));
and if you need to call a function on a Mouse Over then the code would look like this
ourButton_btn.addEventListener("mouseOver",siteLink("www.oursite.com"));
Hope this helps



