How can i use 3rd library in cocos creator

i got some js file like this and marked at import as plugin

org.cometd.CallbackPollingTransport = function()
{
var _super = new org.cometd.RequestTransport();
var _self = org.cometd.Transport.derive(_super);
var _maxLength = 2000;

_self.accept = function(version, crossDomain, url)
{
    return true;
};
_self.jsonpSend = function(packet)
{
    throw 'Abstract';
};

}
module.exports = org.cometd.CallbackPollingTransport;

and

org.cometd.RequestTransport = function()
{
var _super = new org.cometd.Transport();
var _self = org.cometd.Transport.derive(_super);
var _requestIds = 0;
var _metaConnectRequest = null;
var _requests = [];
var _envelopes = [];

function _coalesceEnvelopes(envelope)
{
    while (_envelopes.length > 0)
    {
        var envelopeAndRequest = _envelopes[0];
        var newEnvelope = envelopeAndRequest[0];
        var newRequest = envelopeAndRequest[1];
        if (newEnvelope.url === envelope.url &&
                newEnvelope.sync === envelope.sync)
        {
            _envelopes.shift();
            envelope.messages = envelope.messages.concat(newEnvelope.messages);
            this._debug('Coalesced', newEnvelope.messages.length, 'messages from request', newRequest.id);
            continue;
        }
        break;
    }
}

}
module.exports =org.cometd.RequestTransport;

and i wrote my manager:

var ipconnect = “…”;
var Port= 4123;
var SSL= false;
Window.prototype.connectCubeia = function () {
connector = new FIREBASE.Connector(packetCallback, lobbyCallback, loginCallback, statusCallback);
connector.connect(“FIREBASE.WebSocketAdapter”, ipconnect, Port, “/socket”, SSL, function () {
return $.cometd
});
console.log("Connected using cometd…! ");
};

and i call that when load scene:

onLoad: function () {
window.prototype.connectCubeia();
},

but when run in browser it got many error

> Uncaught ReferenceError: org is not defined

how can i use that without error :frowning:

I’d like to know that too. I planning on implementing some Facebook stuff and normally I would put that in the Index.html but I don’t know how to work with it while developing in Cocos Creator.

The feature mark your js file as plugin is no magic here but evaluate this Javascript file before your game logic code is evaluated.

In your Js file, the symbol org is indeed not defined.

You could import your js file into Creator editor and change this js script into a plugin.

please refer to this document for more information.

http://cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/plugin-scripts/index.html

1 Like

@owen thanks for the suggestion. I’ll try it out asap.