Flash 包中的“GATracker”应使用什么上下文?
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:听起来我需要传递一个displayObject
,http://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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这是因为您在创建 DetailView 之前使用了
this
关键字。现在,您可以在声明类变量的上下文中(不在任何函数内)使用
this
关键字。您可能应该在构造函数中(或者可能在Event.ADDED_TO_STAGE
事件的处理函数中)执行此操作。另外,您确定要将
tracker
声明为AnalyticksTracker
而不是GATracker
吗?通常,您对存储使用new
关键字创建的实例的变量使用相同的类型(并非总是如此,但通常如此)。所以你可以尝试这样的事情:
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 theEvent.ADDED_TO_STAGE
event).Also, are you sure you want to declare
tracker
as aAnalyticksTracker
and not aGATracker
? Normally, you use the same type for the variable that stores the instance that you create using thenew
keyword (not always, but normally).So you could try something like this: