Flash 包中的“GATracker”应使用什么上下文?

发布于 2024-11-18 17:16:50 字数 1268 浏览 2 评论 0原文

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 ); 

我明白了:

1067: Implicit coercion of a value of type Class to an unrelated type flash.display:DisplayObject.

这完全有道理,因为 this 引用了 type Class 对象。但是 - 如果我无法传递 type Class,我应该传递什么?

该文档位于此处,但我找不到任何关于我应该作为第一个传递的内容的参考构造函数方法的参数。

编辑#1:听起来我需要传递一个displayObjecthttp://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/GATracker.as?r=398

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 coercion 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白况 2024-11-25 17:16:50

我认为这是因为您在创建 DetailView 之前使用了 this 关键字。

现在,您可以在声明类变量的上下文中(不在任何函数内)使用 this 关键字。您可能应该在构造函数中(或者可能在 Event.ADDED_TO_STAGE 事件的处理函数中)执行此操作。

另外,您确定要将 tracker 声明为 AnalyticksTracker 而不是 GATracker 吗?通常,您对存储使用 new 关键字创建的实例的变量使用相同的类型(并非总是如此,但通常如此)。

所以你可以尝试这样的事情:

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 );
   }

}

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 );
   }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文