navigateToURL popup blocking?


(Justin Wolf) #1

Greetings! This may or may not pertain to FlashPunk, but after some research I think it may. According to a few blogs and articles I’ve read, if you use navigateToURL in anything other than an mouse/keyboard event listener, that url will be blocked by a popup blocker. So I went ahead and tried it. I have a regular mouse_down event listener attached to the main stage, and whenever I click it takes me to a URL without the popup being blocked.

However, if I roll with FlashPunk’s system (Input.mousePressed), the popup is blocked. Basically I have a Button class:

override public function update():void 
{
	if (collidePoint(x, y, world.mouseX, world.mouseY)) 
	{
		if (Input.mousePressed) click();
	}
	
	super.update();
}

That is attached to all of my buttons in game by simply extending the class and overriding the click function, and of course when the mouse is pressed while hovering over one of these buttons (via hitbox) the click function is called. This poses a problem as browsers are apparently not detecting any sort of keypress/mouse press at this point and thus blocks the url from opening. Apparently, if the browser does not detect any sort of input from the user, then it blocks popups to prevent spamming popups, etc.

Does anyone know any way around this? I’ve read about using the ExternalInterface class but I’m not sure that’s the best way to go about it, and not sure it would work efficiently on everyone’s browsers.


(Abel Toy) #2

You’ll haver to use Event Listeners. It’s not that hard.


(Justin Wolf) #3

Of course it’s “not that hard”. But it’s also a pain in the ass as I have a kajillion buttons (that require opening URLs [sponsor crap]) in-game already extending this class, figured I’d ask.


(Jacob Albano) #4

While Flashpunk does use event listeners to handle input, it does so indirectly. There’s no way around using event listeners directly short of redesigning the whole way the Input system works, unfortunately.


(Justin Wolf) #5

Dang, that’s unfortunate. Ah well, thanks for the actual reply and explanation and not “do this, it’s not that hard”. Appreciate it!


(Jacob Albano) #6

Glad I could help! I feel like I should just say I don’t think AbleToy was being intentionally short with you. A lot of Flashpunk users don’t have any experience with the traditional Flash way of doing things (I know I didn’t for a while), so if anything I took it as a reassurance. It’s hard to judge tone from text, but I try to give people the benefit of the doubt when I can. :slight_smile:


(Justin Wolf) #7

In retrospect, I’ll agree that he probably wasn’t trying to come off the way I took it. I suppose I may just be a little stressed now - sponsors are beyond ridiculous. Thanks again!


(Abel Toy) #8

Hey, I’m sorry if I sounded bad. That wasn’t my intention. I just was trying to tell you Event Listeners were the best route to go in order to achieve this.

You can take a look at how I created a Button class for Punk.UI 1.0, which used Event Listeners. Just ignore the skinning parts (and I wouldn’t recommend using the library. I did it myself, and I don’t really like it. I’m preparing a 2.0 version):


(Justin Wolf) #9

Hey,

No sweat. Like I said, I definitely don’t think you meant any malice after looking back. I’ve just been having a rough couple days, haha. :grin:

And thanks for sharing this. I’ll definitely look over it and prepare future games properly. Weird, I’ve been working with FlashPunk for years and have sold several FlashPunk games to sponsors and only today did I realize there was a problem with popup blockers blocking links!

Thanks again!

  • Justin

(Zachary Lewis) #10

@justinwolf @AbelToy