Expand my Community achievements bar.

Can a guest send a message?

Avatar

Level 3

public function sendMessage(str:String):void

{

var chat:ChatMessageDescriptor = new ChatMessageDescriptor();

chat.msg = str;

var nodeName:String = "history";

var msg:MessageItem = new MessageItem(nodeName,

chat.createValueObject());

chat.displayName = ModelLocator.getInstance().chatModel.user.nickName; //_connectSession.userManager.getUserDescriptor(_connectSession.userManager.myUserID).displayName;

msg.body = chat.msg;

chat.timeStamp = (new Date()).getTime();

_collection.publishItem(msg);

}

Having issue when I login as a Guest (Compiler throws an error saying it's undefined (bolded statement);

This works fine when I log in as a host.

Thanks for your help!

Babo

11 Replies

Avatar

Level 3

Here is my onSyn handler.

private function onSynchronizeChange(event:CollectionNodeEvent):void

{

if(_collection.isSynchronized)

{

if(!collection.isNodeDefined("histroy") && _collection.canUserConfigure(_connectSession.userManager.myUserID))

{

_collection.createNode("history",

new NodeConfiguration(UserRoles.VIEWER, UserRoles.VIEWER, true, false, false,

false, NodeConfiguration.STORAGE_SCHEME_QUEUE, true));

_collection.createNode("host_history",

new NodeConfiguration(UserRoles.OWNER, UserRoles.VIEWER, true, false, false,

false, NodeConfiguration.STORAGE_SCHEME_QUEUE, true));

_collection.createNode("participant_history",

new NodeConfiguration(UserRoles.OWNER, UserRoles.VIEWER, true, false, false,

false, NodeConfiguration.STORAGE_SCHEME_QUEUE, true));

}

else

{

trace("guest");

}

}

traces "guest" ...

Avatar

Employee

hi Babo_ya,

Can you paste the actual compiler error you get. Assuming that its _collection that is undefined, there might be an issue the way you create and initailize your _collection.

As far as I know, I dont see an issue with the code you pasted. Also in your onSynchronizeChange method, Does it always trace as guest even when you login as host ?

Also a quick check, do you set the connectsession and the sharedId to your _collection ?

Thanks

Avatar

Level 3

hi Babo_ya,

Can you paste the actual compiler error you get. Assuming that its _collection that is undefined, there might be an issue the way you create and initailize your_collection.


TypeError: Error #1009: Cannot access a property or method of a null object reference.

at DATA.Shared::AbstractShared/sendMessage()[/Users/seyunee/Desktop/Seyunee/AIR/Picasso/src/DATA/Shared/AbstractShared.as:223]

at DATA.ChatUser::AbstractChatUser/sendMessage()[/Users/seyunee/Desktop/Seyunee/AIR/Picasso/src/DATA/ChatUser/AbstractChatUser.as:94]

at CONTROL.Message::SendChatMessage/execute()[/Users/seyunee/Desktop/Seyunee/AIR/Picasso/src/CONTROL/Message/SendChatMessage.as:19]

at VIEW.Chat::ChatMessageWindow/onChatMessageEnter()[/Users/seyunee/Desktop/Seyunee/AIR/Picasso/src/VIEW/Chat/ChatMessageWindow.mxml:149]

at VIEW.Chat::ChatMessageWindow/__txt_enter()[/Users/seyunee/Desktop/Seyunee/AIR/Picasso/src/VIEW/Chat/ChatMessageWindow.mxml:170]

at flash.events::EventDispatcher/dispatchEventFunction()

at flash.events::EventDispatcher/dispatchEvent()

at mx.core::UIComponent/dispatchEvent()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:9298]

at mx.controls::TextInput/keyDownHandler()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\controls\TextInput.as:2179]


As far as I know, I dont see an issue with the code you pasted. Also in youronSynchronizeChange method, Does it always trace as guest even when you login as host ? (If I log in as a host then "NO")

Also a quick check, do you set the connectsession and the sharedId to your _collection ?

(YES)

Thanks

Avatar

Employee

Hi Babo_ya,

Can you double check your code in AbstractShared.as . The stack trace doesnt hit AFCS source/class files. Seems like _collection itself is null.(probably not instantiated when the user is not an owner)

Thanks

Avatar

Level 3

Both guest and host user object has instance of the AbstractShared.

if(_collection.isSynchronized)

{

if(!collection.isNodeDefined("histroy") && _collection.canUserConfigure(_connectSession.userManager.myUserID))

{

_collection.createNode("history",

new NodeConfiguration(UserRoles.VIEWER, UserRoles.VIEWER, true, false, false,

false, NodeConfiguration.STORAGE_SCHEME_QUEUE, true));

_collection.createNode("host_history",

new NodeConfiguration(UserRoles.OWNER, UserRoles.VIEWER, true, false, false,

false, NodeConfiguration.STORAGE_SCHEME_QUEUE, true));

_collection.createNode("participant_history",

new NodeConfiguration(UserRoles.OWNER, UserRoles.VIEWER, true, false, false,

false, NodeConfiguration.STORAGE_SCHEME_QUEUE, true));

}

else

{

trace("guest" + " : " + _connectSession.userManager.myUserRole);

}

HOst user has the right access level to create node but, guest user do NOT have the right access level. 

But, publish access is set to "Viewer" and every user should have the right access level to publish message.

Thanks,

Babo

Avatar

Employee

Hi Babo,

This part of the code that you already posted is correct. As you rightly said guests/viewers should be able to publish messages to the history node. The issue seems to be a problem with null _collection (CollectionNode that has the history node is itself null, when u r not logging in as an owner)

Another obeservation unrerlated to the error is that , can you change if(!collection.isNodeDefined("histroy") && to if(!_collection.isNodeDefined("histroy") && in your code. (missing an underscore)

Thanks

Avatar

Level 3

public function subscribe():void

{

_collection = new CollectionNode();

_collection.sharedID = "XXX";

_collection.connectSession = this._connectSession.connectSession;

_collection.addEventListener(CollectionNodeEvent.SYNCHRONIZATION_CHANGE,

onSynchronizeChange);

_collection.addEventListener(CollectionNodeEvent.ITEM_RECEIVE, onItemReceive);

_collection.subscribe();

}

I believe above code works fine for both host/guest users and I strongly believe that _collection is NOT null.

When I log in as a guest the below code doesn't work because of permission issue which I'm not sure why...

_collection.createNode("history",

new NodeConfiguration(UserRoles.VIEWER, UserRoles.VIEWER, true, false, false,

false, NodeConfiguration.STORAGE_SCHEME_QUEUE, true));

So, I think the node itself is NOT there. but, I'm not sure.

Babo,

Avatar

Former Community Member

Hi,

You need to be an owner to create a node. The createNode call would not work when you first enter as guest without owner setting up the room. As an owner, model needs to be first set up i.e. collectionNode and nodes created, then as guests you can publish an Items on the nodes.

If you feel you don't want to set up the room as an owner first, you can also create a particular collectionNode and its underlying nodes using the developer console.

Thanks

Hironmay Basu

Avatar

Level 3

Sorry guys.. works fine.. now. .

it was null

BaBo

Avatar

Level 3

Sorry guys.. works fine.. now. .

it was null

BaBo

Avatar

Level 3

Sorry guys.. works fine.. now. .

it was null

BaBo