开发者

What context should be used for `GATracker` in a Flash package?

开发者 https://www.devze.com 2023-03-17 06:00 出处:网络
package { import flash.display.MovieClip; import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent;
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 );
   }

}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号