SelectPubNub Flash SDK 3.7.12

Latest stable version


Latest stable minified version


Development version



You must include the PubNub JavaScript SDK in your code before initializing the client
 
Pubnub Flash SDK is a proxy/wrapper, it doesn't contain any logic for methods, but delegates calls to JavaScript SDK. In Pubnub Flash SDK you should specify each argument explicitly, even if you don't intend use it. Alternatively you can use '...args' statement.
  1. Add swc file to you Flash project:
    To use Pubnub, simply copy the pubnublib.swc file into your project's libs directory from https://github.com/pubnub/flash/tree/master/pubnublib/bin
  2. Add as2js proxy helper and JavaScript SDK to your html page
    <html>
       <body>
          <script src="http://cdn.pubnub.com/pubnub-3.7.12.min.js"></script>
          <script src="http://cdn.pubnub.com/pubnub-as2js-proxy.min.js"></script>
       </body>
    </html>
    
var pubnub:PubNub = new PubNub({
    publish_key: 'demo',
    subscribe_key: 'demo'
});

trace("Subscribing...");

pubnub.subscribe({
    channel: "hello_world",
    message: function (message:Object, envelope:Object, groupOrChannel:String, time:Number, channel:String):void {
        trace(
                "Message Received." + "\n" +
                "Group or Channel: " + groupOrChannel + "\n" +
                "Message: " + JSON.stringify(message) + "\n" +
                "Raw Envelope: " + JSON.stringify(envelope) + "\n" +
                "Channel: " + JSON.stringify(channel)
        )
    },
    connect: publish
});

function publish():void {
    trace("Since we’re publishing on subscribe connectEvent, we’re sure we’ll receive the following publish.");
    pubnub.publish({
        channel: "hello_world",
        message: "Hello from PubNub Docs!",
        callback: function (message:Object):void {
            trace(message)
        }
    })
}
In addition to the Hello World sample code, we also provide some copy and paste snippets of common API functions:
Instantiate a new Pubnub instance. Only the subscribe_key is mandatory. Also include publish_key if you intend to publish from this instance, and the secret_key if you wish to perform PAM administrative operations from this Flash instance.
 

It is not a best practice to include the secret key in client-side code for security reasons.

When you init with secret_key, you get root permissions for the Access Manager. With this feature you don't have to grant access to your servers to access channel data. The servers get all access on all channels.

var pubnub:PubNub = new PubNub({
    publish_key: "my_pubkey",
    subscribe_key: "my_subkey"
});
Call time() to verify the client connectivity to the origin:
pubnub.time(function (time:String):void {
    trace(time);
});
Subscribe (listen on) a channel (it's async!):
pubnub.subscribe({
    channel: 'my_channel',
    message: function (message:Object, envelope:Object, groupOrChannel:String, time:Number, channel:String):void {
        trace(JSON.stringify(message))
    },
    error: function (error:Object):void {
        trace(JSON.stringify(error))
    }
});
Publish a message to a channel:
pubnub.publish({
    channel: 'my_channel',
    message: 'Hello from the PubNub Flash SDK!',
    callback: function (message:Object):void {
        trace(JSON.stringify(message))
    }
});
Get occupancy of who's here now on the channel by UUID:
Requires that the Presence add-on is enabled for your key. How do I enable add-on features for my keys? - see http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys
pubnub.here_now({
    channel: 'my_channel',
    callback: function (message:Object):void {
        trace(JSON.stringify(message))
    }
});
Subscribe to realtime Presence events, such as join, leave, and timeout, by UUID. Setting the presence attribute to a callback will subscribe to presents events on my_channel:
Requires that the Presence add-on is enabled for your key. How do I enable add-on features for my keys? - see http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys
pubnub.subscribe({
    channel: 'my_channel',
    message: function (message:Object, envelope:Object, groupOrChannel:String, time:Number, channel:String):void {
        trace(JSON.stringify(message))
    },
    presence: function (message:Object, envelope:Object, groupOrChannel:String, time:Number, channel:String):void {
        trace(JSON.stringify(message));
    }
});
Retrieve published messages from archival storage:
Requires that the Storage and Playback add-on is enabled for your key. How do I enable add-on features for my keys? - see http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys
pubnub.history({
    channel: 'history_channel',
    count: 100, // 100 is the default
    reverse: false, // false is the default
    callback: function (message:Object):void {
        trace(JSON.stringify(message))
    }
});

Stop subscribing (listening) to a channel.
pubnub.unsubscribe({
    channel : 'my_channel'
});