Expand my Community achievements bar.

Still struggling

Avatar

Level 3
I have have been trying to use the sharedmodel to add a users
location name and avatar imagebut I have not been able to get it
working. So I have starting from scratch and I hope somene can
help. I have attached the code.



Thanks
15 Replies

Avatar

Former Community Member
Hi ukkpower,



Sorry, don't want you to think we're ignoring you. All I can
say is, wait a couple of days, and we'll get back to you, in a
better way than I could by debugging your code =).

Avatar

Level 3
Thanks Nigel, really appreciate it. We are looking forward to
completing our first cocomo project.

Avatar

Former Community Member
Hi,

Just to give you a heads up.

With the new version of AFCS 0.91 , customUserField is
working and you can use the API's of UserManager directly for
registering and accessing customUserFields.

While you use the new afcs.swc , please also make the
necessary change in the namespace for smooth compiling( see release
notes for details).



Thanks

Hironmay Basu

Avatar

Level 2
Hi people

i don't get how to use customFields ?

how to use it to store a property and put it in dataGrid
Column?





var ud:UserDescriptor =
cSession.userManager.getUserDescriptor(cSession.userManager.myUserID);

ud.customFields.someProperty = 7;





<mx:DataGrid id="datag"
dataProvider="{cSession.userManager.userCollection}" >

<mx:columns>

<mx:DataGridColumn headerText="Column 1"
dataField="displayName" />

<mx:DataGridColumn headerText="Column 2"
dataField="????????" />

</mx:columns>

</mx:DataGrid>

Avatar

Former Community Member
Hi,



You need to first call the registerCustomUserField API in
UserManager to register the field. After that you can set the
customField by calling setCustomUserField API.

For e.g.

_userManager.registerCustomUserField (myfield);

For setting the value,

_userManager.setCustomUserField(userID,myfield,value);

Here userID denotes the userID of the user whose descriptor
should have this value.



Then while accessing the value, you will do
userDescriptor.customFields[myfield] .



Hope this helps.



Thanks

Hironmay Basu

Avatar

Level 2
Thank you that was helpful

but how can i put the results in a list or dataField?



cSession.userManager.registerCustomUserField("score");

cSession.userManager.setCustomUserField(cSession.userManager.myUserID,"score",7);

var ud:UserDescriptor =
cSession.userManager.getUserDescriptor(cSession.userManager.myUserID);

Alert.show(ud.customFields["score"]);



<mx:DataGrid id="datag"
dataProvider="{cSession.userManager.userCollection}" >

<mx:columns>

<mx:DataGridColumn id="c1" headerText="Column 1"
dataField="displayName" />

<mx:DataGridColumn id="c2" headerText="Column 2"
dataField="customFields['score']" />// if there is an easy way
to put the results here it will be good for newbie.

</mx:columns>





Avatar

Former Community Member
Hi,



For the list, you need to assign dataProvider to the
Usermanager's usercollection and the labelField could be the field
you want to display. For datagrid, I think what you are doing is
correct. And you will have to assign the datagridcolumn's dataField
to whichever field of usercollection you want to display in that
column.



Thanks

Hironmay Basu

Avatar

Level 3
Thanks very much guys for the fix. I got it towork, but not
without some issues.



I have noticed that when the
cSession.userManager.registerCustomUserField("score"); is called in
a function. The function just ends and anything after it is not
run.



For example when I have the line
cSession.userManager.setCustomUserField(cSession.userManager.myUserID,"score",7);
after the register it will not run. I even put a simple line of
Alert.show('Ready') and that wont call.



The way I got around was put put two buttons in my app which
calls two different functions. One to register and teh other to
set.



Any thoughts? Thanks.

Avatar

Former Community Member
Hi,

I will try to run it myself and update as it should work.
Also, we will have a custom fields example for users to follow
easily in the coming releases.



Thanks

Hironmay Basu

Avatar

Level 2


<mx:DataGridColumn id="c2" headerText="Column 2"
dataField="customFields['score']" />

doesn't work?

an example of putting customFileds inside a DataGridColumn
will be nice ...

Thank you

Avatar

Former Community Member
Hi,



Sure. I will run it and post it here



Thanks

Hironmay Basu

Avatar

Former Community Member
Hi,

here is the small app i wrote using your example. In the
DataGridColumn's dataField function, even though the dataField is
there, in the label it doesn't show up if we assign such complex
objects directly through dataField. So, you can use labelFunction
(callback function) to show like what i did below for any label you
want to show for customFields.



<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="absolute" xmlns:rtc="AfcsNameSpace" >

<mx:Script>

<![CDATA[

import com.adobe.rtc.sharedManagers.UserManager;



private var _userManager:UserManager ;

public function onCreationComplete():void

{

_userManager = cSession.userManager ;



if (!_userManager.isCustomFieldDefined('score')) {

_userManager.registerCustomUserField('score');

}




_userManager.setCustomUserField(_userManager.myUserID,'score','7');

}



private function
scoreLabelFunction(item:Object,column:DataGridColumn):String

{

return item.customFields['score'] ;

}



]]>

</mx:Script>

<rtc:ConnectSessionContainer id="cSession" roomURL="Your
Room Url">

<rtc:authenticator>

<rtc:AdobeHSAuthenticator userName="Your UserName"
password="Your Password" />

</rtc:authenticator>

<mx:DataGrid id="datag"
dataProvider="{cSession.userManager.userCollection}"
creationComplete="onCreationComplete()" >

<mx:columns>

<mx:DataGridColumn id="c1" headerText="Name"
dataField="displayName" />

<mx:DataGridColumn id="c2" headerText="Score"
dataField="customFields['score']"
labelFunction="scoreLabelFunction" />

</mx:columns>

</mx:DataGrid>

</rtc:ConnectSessionContainer>

</mx:Application>



Thanks

Hironmay Basu

Avatar

Level 2

Thank you for the example

I want to sort the DataGrid by the score.

When I click on the DataGrid score column head to sort it, It throws error:

ReferenceError: Error #1069: Property customFields['score'] not found on com.adobe.rtc.sharedManagers.descriptors.UserDescriptor and there is no default value.

Avatar

Former Community Member

Hi Isa,

It's possible that this line was written with a typo :

<mx:DataGridColumn id="c2" headerText="Score" dataField="customFields['score']" labelFunction="scoreLabelFunction" />

Try removing the dataField included there, so :

<mx:DataGridColumn id="c2" headerText="Score" labelFunction="scoreLabelFunction" />

Check out the docs here :

http://livedocs.adobe.com/flex/3/langref/mx/controls/dataGridClasses/DataGridColumn.html#dataField

  Which say that you need to build a sortCompareFunction on the DataGridColumn for this kind of case.


  hope that helps

   nigel

Avatar

Level 2

Thank you for the tips,

i removed the dataField and wrote a sortCompareFunction.
The DataGrid is sortable now :-)

<mx:DataGridColumn id="c2" headerText="Score" sortCompareFunction="sortMe" labelFunction="scoreLabelFunction" />

import mx.utils.ObjectUtil;

private function sortMe(obj1:Object, obj2:Object):int{
return ObjectUtil.compare(obj1,obj2)
}

But this works only when the dataFileds are not changing.
When the dataFileds are changing the DataGrid overwrite the rows.
It seems that the DataGrid don't know where the new rows position after the sort.
It puts the rows on the same old position?