/ Published in: ActionScript 3
There are many ways to tweak this code but hopefully this will get you all started. Whenever I'm tracking PageViews or Events for something like Google Analytics, I don't want navigateToURL() to interfere while I'm developing. These two functions will keep navigateToURL() from trying to load a Browser page until the SWF is loaded into an HTML page
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var mc:MovieClip = new MovieClip(); mc.buttonMode = true; mc.addEventListener( MouseEvent.CLICK, trackEventHandler, false, 0, true ); function isProductionMode():Boolean { var runtimeEvironment:String = Capabilities.playerType; if (runtimeEvironment == "External" || runtimeEvironment == "StandAlone"){ return false; } else { return true; } } function trackEventHandler( e:Event ):void { //If the Complied Flash Player is on the HTML page, give it a Page View if( isProductionMode() ){ navigateToURL(new URLRequest("analytics._trackPageView()"), '_self'); } }