Return to Snippet

Revision: 28155
at August 31, 2012 12:54 by IsoJon


Updated Code
// clickTag code ------------------------------------------------------------

var url : String;
var btn : Sprite;

createBanner();

function createBanner() : void
{
	btn = new Sprite();
	
	with ( btn.graphics ) 
	{
		beginFill( 0x000 );
		drawRect(0,0,stage.stageWidth,stage.stageHeight + 100);
		endFill();
	}
	
        with ( btn ) 
	{
	    alpha = 0;
	    buttonMode = true;
	    addEventListener( MouseEvent.MOUSE_UP, handleMouse );	
	}
	
        addChild( btn );	

	if ( LoaderInfo(root.loaderInfo).parameters.clickTag ) 
	{
		url = String( LoaderInfo(root.loaderInfo).parameters.clickTag );
		btn.addEventListener( MouseEvent.MOUSE_UP, handleMouse );
		
	} else if ( LoaderInfo(root.loaderInfo).parameters.clicktag )
	{
		url = String( LoaderInfo(root.loaderInfo).parameters.clicktag );
		btn.addEventListener( MouseEvent.MOUSE_UP, handleMouse );
	}
	
	// use this if you are adding other things to the displaylist dynamically,
	// so that the button is always on top.
    //stage.addEventListener( Event.ENTER_FRAME, bringBtnToTop );
}

function bringBtnToTop( evt:Event ) : void
{
	addChild( btn );
}

function handleMouse( evt : MouseEvent ) : void 
{
	if ( url != null ) 
	{
		navigateToURL( new URLRequest(url), "_blank" );
		
	} else {
		
		trace("There was an error, or you have clicked the button in the Flash IDE.");
	}
}

Revision: 28154
at July 2, 2010 09:23 by IsoJon


Updated Code
// clickTag code ------------------------------------------------------------

var url : String;
var btn : Sprite;

createBanner();

function createBanner() : void
{
	btn = new Sprite();
	
	with ( btn.graphics ) 
	{
		beginFill( 0x000 );
		drawRect(0,0,stage.stageWidth,stage.stageHeight + 100);
		endFill();
	}
	
        with ( btn.graphics ) 
	{
	    alpha = 0;
	    buttonMode = true;
	    addEventListener( MouseEvent.MOUSE_UP, handleMouse );	
	}
	
        addChild( btn );	

	if ( LoaderInfo(root.loaderInfo).parameters.clickTag ) 
	{
		url = String( LoaderInfo(root.loaderInfo).parameters.clickTag );
		btn.addEventListener( MouseEvent.MOUSE_UP, handleMouse );
		
	} else if ( LoaderInfo(root.loaderInfo).parameters.clicktag )
	{
		url = String( LoaderInfo(root.loaderInfo).parameters.clicktag );
		btn.addEventListener( MouseEvent.MOUSE_UP, handleMouse );
	}
	
	// use this if you are adding other things to the displaylist dynamically,
	// so that the button is always on top.
    //stage.addEventListener( Event.ENTER_FRAME, bringBtnToTop );
}

function bringBtnToTop( evt:Event ) : void
{
	addChild( btn );
}

function handleMouse( evt : MouseEvent ) : void 
{
	if ( url != null ) 
	{
		navigateToURL( new URLRequest(url), "_blank" );
		
	} else {
		
		trace("There was an error, or you have clicked the button in the Flash IDE.");
	}
}

Revision: 28153
at July 2, 2010 09:07 by IsoJon


Initial Code
// clickTag code ------------------------------------------------------------

var url : String;
var btn : Sprite;

createBanner();

function createBanner() : void
{
	btn = new Sprite();
	
	with ( btn.graphics ) 
	{
		beginFill( 0x000 );
		drawRect(0,0,stage.stageWidth,stage.stageHeight + 100);
		endFill();
	}
	
	btn.alpha = 0;
	btn.buttonMode = true;
	btn.addEventListener( MouseEvent.MOUSE_UP, handleMouse );
	addChild( btn );
	
	if ( LoaderInfo(root.loaderInfo).parameters.clickTag ) 
	{
		url = String( LoaderInfo(root.loaderInfo).parameters.clickTag );
		btn.addEventListener( MouseEvent.MOUSE_UP, handleMouse );
		
	} else if ( LoaderInfo(root.loaderInfo).parameters.clicktag )
	{
		url = String( LoaderInfo(root.loaderInfo).parameters.clicktag );
		btn.addEventListener( MouseEvent.MOUSE_UP, handleMouse );
	}
	
	// use this if you are adding other things to the displaylist dynamically,
	// so that the button is always on top.
    //stage.addEventListener( Event.ENTER_FRAME, bringBtnToTop );
}

function bringBtnToTop( evt:Event ) : void
{
	addChild( btn );
}

function handleMouse( evt : MouseEvent ) : void 
{
	if ( url != null ) 
	{
		navigateToURL( new URLRequest(url), "_blank" );
		
	} else {
		
		trace("There was an error, or you have clicked the button in the Flash IDE.");
	}
}

Initial URL


Initial Description
This snippet will place a button the size of your stage (actually 100 px taller to take care of a flash bug) as well as look for clickTag and clicktag variables, you can always change it so that it looks for whatever variable you want.  I purposely left it a little verbose so that its easy to see what the application is looking for. When you're done using it, try using the Banner Flow clickTest to check that it works. http://bannerflow.com/clicktest/

Clicking this in the IDE will not return a blank window like an as2 clickTag, instead you will see a notification in the trace window.

Initial Title
AS3 Clicktag - Works for Multiple ClickTag Variables

Initial Tags


Initial Language
ActionScript 3