连接到kongregate api

时间:2010-02-06 18:25:09

标签: flash actionscript-3 actionscript

只是检查是否有人使用kongregate。如果是这样,我有问题。

当我在调试模式下本地连接到kongregate时,它工作正常。但是当我将游戏上传到他们的服务器时,我收到以下错误。

TypeError: Error #1010: A term is undefined and has no properties.
at com.objects::Engine/GameMenu()
at Function/http://adobe.com/AS3/2006/builtin::apply()

以下是我使用的代码。和我设置的类属性

// Kongregate API reference
        private var kongregate:*;

public function Engine(sr:Stage):void
        {
            // Pull the API path from the FlashVars
            var paramObj:Object = LoaderInfo(sr.loaderInfo).parameters;

            // The API path. The "shadow" API will load if testing locally. 
            var apiPath:String = paramObj.kongregate_api_path || 
              "http://www.kongregate.com/flash/API_AS3_Local.swf";

            // Allow the API access to this SWF
            Security.allowDomain(apiPath);

            // Load the API
            var request:URLRequest = new URLRequest(apiPath);
            var loader:Loader = new Loader();
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
            loader.load(request);
            this.addChild(loader);

            var music:MusicBackGround = new MusicBackGround();
            music.play(0,int.MAX_VALUE);
            this.sr = sr;
            init();
        }

这是处理程序

// This function is called when loading is complete
        function loadComplete(event:Event):void
        {
            // Save Kongregate API reference
            kongregate = event.target.content;

            // Connect to the back-end
            kongregate.services.connect();

            // You can now access the API via:
            // kongregate.services
            // kongregate.user
            // kongregate.scores
            // kongregate.stats
            // etc...
        }
下面的

是触发错误的代码行

var isGuest:Boolean = kongregate.services.isGuest();
            var username:String = kongregate.services.getUsername();
            menu.MenuInfo.text = "Kongregate Edition\nWelcome, "+username;

1 个答案:

答案 0 :(得分:1)

我认为可能是这一行:

var paramObj:Object = LoaderInfo(sr.loaderInfo).parameters; Kong将您的电影加载到他们的swf中,因此参数可能不存在于该级别。 尝试:

var paramObj:Object = LoaderInfo(root.loaderInfo).parameters;

更改是对root的引用,我希望找到参数。

另外:你可以发布你的错误信息吗?