Home > Flash > AS3 text href to flash function

AS3 text href to flash function

February 23rd, 2010 jeff Leave a comment Go to comments

I’ve been setting up google analytics tracking in a flash project and wanted to track a mailto. The thing is i’m using a mailto link in a dynamic text field link. What i could do is create a separate button to handle the both tracking and mailto, but i need to match up styling.

I found a more elegent solution in AS2 where there was an undocumented class asfunction http://kb2.adobe.com/cps/156/tn_15639.html That meant you could use asfunction:myClick to pass the text click event to a function, then you can handle mutiple actions in a single event.

However this has been depreciated in AS3 in favour of TextEvent.LINK.
This is an example of my final tracking code:

import flash.events.TextEvent;
import flash.external.ExternalInterface;
import flash.net.URLRequest;
import flash.net.navigateToURL;

var linkstr:String = “xx@xx.com“;
TextMC.links_txt.htmlText = linkstr;
TextMC.links_txt.addEventListener(TextEvent.LINK, trackMail);

private function TrackMail(e:TextEvent = null):void
{
navigateToURL(new URLRequest(“mailto:xx@xx.com”), “_self”);
ExternalInterface.call(“pageTracker._trackPageview”, “/mailto/agent-email:xx@xx.com”);
}

Post to Twitter Post to Facebook

  1. No comments yet.
  1. No trackbacks yet.

Videos, Slideshows and Podcasts by Cincopa Wordpress Plugin