[英]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 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.这完全有道理,因为this
引用了type Class
。 But - if I can't pass a type Class
, what should I pass?但是 - 如果我不能通过type Class
,我应该通过什么?
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编辑#1 :听起来我需要传递一个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.我认为这是因为您在创建 DetailView 之前使用了this
关键字。
You now use the this
keyword in a context where class variables are declared (not inside any function).您现在在声明 class 变量的上下文中使用this
关键字(不在任何函数内)。 You should probably do it in a constructor (or possibly in a handler function for the Event.ADDED_TO_STAGE
event).您可能应该在构造函数中执行此操作(或者可能在Event.ADDED_TO_STAGE
事件的处理程序 function 中)。
Also, are you sure you want to declare tracker
as a AnalyticksTracker
and not a GATracker
?另外,您确定要将tracker
声明为AnalyticksTracker
而不是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).通常,您对存储使用new
关键字创建的实例的变量使用相同的类型(并非总是如此,但通常如此)。
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 );
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.