views:

118

answers:

1

I'll consider myself a newbie,

I've made buttons in a flash menu to play animation and go to a url on click, and I've made it so that the url page loads in an iframe.

Everything works fine on Safari, but it ends up loading the url page in a new tab for Firefox.

If anyone has a solution, it'll be really appreciated. Thanks so much.

Here is the actionscript and the iframe is named "myframe":

present_btn.addEventListener(MouseEvent.CLICK,goPresent);
function goPresent(evt:MouseEvent):void {

  // play();

  present_btn.gotoAndPlay("present");

  var url:String = "http://www.ecuad.ca/~vlo/corelam/blank.html";
  var request:URLRequest = new URLRequest(url);
  try {
    navigateToURL(request, "myframe");
  } catch (e:Error) {
    trace("Error occurred!");
  }
}
A: 

I've had this code snippet to handle opening windows using as3 that seems to work in most cases:

private function getBrowserName():String
{
    var browser:String;
    //Uses external interface to reach out to browser and grab browser useragent info.
    var browserAgent:String = ExternalInterface.call("function getBrowser(){return navigator.userAgent;}");
    //Determines brand of browser using a find index. If not found indexOf returns (-1).
    if(browserAgent != null && browserAgent.indexOf("Firefox")>= 0) 
    {
        browser = "Firefox";
    }
    else if(browserAgent != null && browserAgent.indexOf("Safari")>= 0)
    {
        browser = "Safari";
    }
    else if(browserAgent != null && browserAgent.indexOf("MSIE")>= 0)
    {
        browser = "IE";
    }
    else if(browserAgent != null && browserAgent.indexOf("Opera")>= 0)
    {
        browser = "Opera";
    }
    else 
    {
        browser = "Undefined";
    }
    return (browser);
}

function openWindow(url:String, target:String='_blank', features:String=""):void
{
    const WINDOW_OPEN_FUNCTION:String = "window.open";
    var myURL:URLRequest = new URLRequest(url);
    var browserName:String = getBrowserName();
    switch(browserName)
    {
        //If browser is Firefox, use ExternalInterface to call out to browser
        //and launch window via browser's window.open method.
        case "Firefox":
            ExternalInterface.call(WINDOW_OPEN_FUNCTION, url, target, features);
        break;
        //If IE,
        case "IE":
            ExternalInterface.call("function setWMWindow() {window.open('" + url + "', '"+target+"', '"+features+"');}");
        break;
        // If Safari or Opera or any other
        case "Safari":
        case "Opera":
        default:
            navigateToURL(myURL, target);
        break;
    }
}

private function handleMouseClick(event:MouseEvent):void
{
    var sURL:String;        
    if((sURL = root.loaderInfo.parameters.clickTag))
    {
        openWindow(sURL);
    }
}

It isn't my code originally and I've lost the link. It would have come from an ad banner website (like doubleclick) so if I find the attribution (or someone can find the relevant source) I'll add it.

James Fassett
http://www.codeweblog.com/flex-open-ie-window-and-call-the-javascript/ I think.
phwd