0

The ActionScript 3.0 code below works when tested in Adobe Flash CS6, however when tested in a browser the code does not work. Any ideas why this is happening?

buttonInstance.addEventListener(MouseEvent.CLICK,function(e:MouseEvent){
    flash.net.navigateToURL(new URLRequest("http://facebook.com"), "_blank"); 
    trace("link clicked");
},false,0,true);

2 Answers2

1

The event listener's probably being garbage-collected. You need to change your code to one of the following:

buttonInstance.addEventListener(MouseEvent.CLICK,function(e:MouseEvent){
    flash.net.navigateToURL(new URLRequest("http://facebook.com"), "_blank"); 
    trace("link clicked");
}); // (false, 0, false)

or:

    buttonInstance.addEventListener(MouseEvent.CLICK,onClick,false,0,true);
.
.
.
private function onClick(pEvent:MouseEvent):void
{
    flash.net.navigateToURL(new URLRequest("http://facebook.com"), "_blank"); 
    trace("link clicked");
}
Panzercrisis
  • 4,590
  • 6
  • 46
  • 85
  • I've tried both an neither works. I've event tried the code below and it does not work. buttonInstance.addEventListener(MouseEvent.CLICK, onClick); function onClick(e:MouseEvent):void{ navigateToURL(new URLRequest("http://facebook.com"), "_blank"); } –  Mar 21 '13 at 20:20
  • 1
    Does it go inside the event handler? Do you see the trace? – Barış Uşaklı Mar 21 '13 at 20:25
  • It was vulnerable to garbage collection and did need to be changed like that, but it sounds like there's another issue deeper in the context of your code. – Panzercrisis Mar 21 '13 at 20:26
0

The problem was I had 'Local playback security' set to 'Access local files only' I changed it to 'Access network on only' and it works. This post helped AS3 Flash URLRequest not working upon export

Community
  • 1
  • 1