What context should be used for `GATracker` in a Flash package?
package {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.external.ExternalInterface;
import com.google.analytics.AnalyticsTracker;
import com.google.analytics.GATracker;
public class DetailView extends MovieClip {
var tracker:AnalyticsTracker = new GATracker( this, "UA-BLABLA", "AS3", true );
I get this:
1067: Implicit c开发者_JAVA技巧oercion of a value of type Class to an unrelated type flash.display:DisplayObject.
This totally makes sense, because this
reference a type Class
object. But - if I can't pass a type Class
, what should I pass?
The documentation is here but I can't find any reference to what I should pass as the first argument to the constructor method.
Edit #1: Sounds like I need to pass a displayObject
, http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/GATracker.as?r=398
I think that is because you use the this
keyword before the DetailView is created.
You now use the this
keyword in a context where class variables are declared (not inside any function). You should probably do it in a constructor (or possibly in a handler function for the Event.ADDED_TO_STAGE
event).
Also, are you sure you want to declare tracker
as a AnalyticksTracker
and not a GATracker
? Normally, you use the same type for the variable that stores the instance that you create using the new
keyword (not always, but normally).
So you could try something like this:
public class DetailView extends MovieClip {
private var tracker:GATracker;
public function DetailView() {
// Since this is the constructor, the this keyword will refer to the DetailView instance being created
tracker = new GATracker( this, "UA-BLABLA", "AS3", true );
}
}
精彩评论