Adding a link into the game...part 2


(billy2000) #1

Posted recently in this thread:the part 1 Well it still happends sometimes to get the same bug.Everywhere i click on the game it gets me to the specific URL. Any idea what could it be? thx. Heres what i use:

//constructor
pubLogoContainer.addEventListener ( MouseEvent.MOUSE_DOWN, OnMouseDown);
public function OnMouseDown(e:Event = null): void
	{
	    if(mouseX<68 && mouseY<-10)
	    {
	         pubLogoContainer.addEventListener( MouseEvent.MOUSE_DOWN, goToTheURL);
	    }
    }
	public function goToTheURL(e:Event):void
	{
		if( pubLogoContainer.hasEventListener(MouseEvent.MOUSE_UP))
		{
			 pubLogoContainer.removeEventListener(MouseEvent.MOUSE_UP, goToTheURL);
		}
		
		if(mouseX<68 && mouseY<-10)
		navigateToURL(new URLRequest("link"), "_blank");
	}
//and when i change world
pubLogoContainer.removeEventListener( MouseEvent.MOUSE_DOWN, OnMouseDown);
pubLogoContainer.removeEventListener(MouseEvent.MOUSE_UP, goToTheURL);
FP.stage.removeChild(pubLogoContainer);

(billy2000) #2

Could it be because is in publogocontainer and not in fp.stage(the event listener)?


(billy2000) #3

Finally found how it appears …so i click on a button that change the game world and when the animation is working i instantly click on the link button.


(billy2000) #4

What i found is that the event listener is somehow not being removed when i do the above…but idk why cuz i try to remove it in 2 different places. So the question is…How do i ensure myself the event listener is removed from stage?


(Ultima2876) #5
if(mouseX<68 && mouseY<-10)
	    {
	         pubLogoContainer.addEventListener( MouseEvent.MOUSE_DOWN, goToTheURL);
	    }

That bit needs to add a MOUSE_UP event listener:

if(mouseX<68 && mouseY<-10)
	    {
	         pubLogoContainer.addEventListener( MouseEvent.MOUSE_UP, goToTheURL);
	    }

Does that help?


(billy2000) #6

Thx @Ultima2876 for the replay .Managed to get it working :smile: