Posted By

IsoJon on 07/02/10


Tagged

clickTag


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

Demian
adrianparr
tspitzr


AS3 Clicktag - Works for Multiple ClickTag Variables


 / Published in: ActionScript 3
 

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.

  1. // clickTag code ------------------------------------------------------------
  2.  
  3. var url : String;
  4. var btn : Sprite;
  5.  
  6. createBanner();
  7.  
  8. function createBanner() : void
  9. {
  10. btn = new Sprite();
  11.  
  12. with ( btn.graphics )
  13. {
  14. beginFill( 0x000 );
  15. drawRect(0,0,stage.stageWidth,stage.stageHeight + 100);
  16. endFill();
  17. }
  18.  
  19. with ( btn )
  20. {
  21. alpha = 0;
  22. buttonMode = true;
  23. addEventListener( MouseEvent.MOUSE_UP, handleMouse );
  24. }
  25.  
  26. addChild( btn );
  27.  
  28. if ( LoaderInfo(root.loaderInfo).parameters.clickTag )
  29. {
  30. url = String( LoaderInfo(root.loaderInfo).parameters.clickTag );
  31. btn.addEventListener( MouseEvent.MOUSE_UP, handleMouse );
  32.  
  33. } else if ( LoaderInfo(root.loaderInfo).parameters.clicktag )
  34. {
  35. url = String( LoaderInfo(root.loaderInfo).parameters.clicktag );
  36. btn.addEventListener( MouseEvent.MOUSE_UP, handleMouse );
  37. }
  38.  
  39. // use this if you are adding other things to the displaylist dynamically,
  40. // so that the button is always on top.
  41. //stage.addEventListener( Event.ENTER_FRAME, bringBtnToTop );
  42. }
  43.  
  44. function bringBtnToTop( evt:Event ) : void
  45. {
  46. addChild( btn );
  47. }
  48.  
  49. function handleMouse( evt : MouseEvent ) : void
  50. {
  51. if ( url != null )
  52. {
  53. navigateToURL( new URLRequest(url), "_blank" );
  54.  
  55. } else {
  56.  
  57. trace("There was an error, or you have clicked the button in the Flash IDE.");
  58. }
  59. }

Report this snippet  

You need to login to post a comment.