Google Analytics for Flex - Support for Flex 4.5

While trying to use Google Analytics Tracking for Adobe Flash it turned out that it does not support Flex 4.5.

It throws the following exception:
ReferenceError: Error #1065: Variable Application is not defined.
       at global/flash.utils::getDefinitionByName()
Looking at the project's issue tracker, we found the unresolved bug (88) with this same exception.
Looking at the code, the solution was quite simple – The original FlexTracker was looking for the mx.core::Application class in order to get a reference to the Application instance:


 var appclass:Object = getDefinitionByName( "mx.core::Application" );
 _app = appclass.application;


Now, Flex 4.5 no longer uses this class of course; it is now using FlexGlobals.topLevelApplication for getting a reference to the Application instance.
Wrapping the code with a try/catch with supporting Flex 4.5 resulted with the following code which resolved the issue:
var appclass:Object;
try{//Flex 3
    	appclass = getDefinitionByName( "mx.core::Application" );
	_app = appclass.application;
catch (e:Error)
{//Flex 4.5
      appclass = getDefinitionByName( "mx.core::FlexGlobals" );
      _app = appclass.topLevelApplication;

Thank you for your interest!

We will contact you as soon as possible.

Send us a message

Oops, something went wrong
Please try again or contact us by email at