Skip navigation
RituKnowsFlex
Currently Being Moderated

Using the customFields in the user descriptor within an item renderer

Oct 11, 2011 11:14 AM

Hello,

 

I am trying to use the customFields in the user descriptor as additional data to be bound to a component in an item renderer. I have some data that is tied to every user in the roster and I would like it to be displayed and modified at runtime based on user interaction. Here is the code I wrote for setting the customFields.

 

protected function eGamingSession_creationCompleteHandler(event:FlexEvent):void

                              {

                   // TODO Auto-generated method stub

                   for(var i:int=0;i<eGamingSession.userManager.userCollection.length;i++)

                                        {

                                                  eGamingSession.userManager.userCollection.ge tItemAt(i).customFields['score'] = 10;

 

                                                  trace("Value of stepper is: "+eGamingSession.userManager.userCollection.getItemAt(i).customFields .score);

                    }

 

                              }

 

Then in the item renderer, the code is as follows:

 

<s:List id="userList"

                                                                      dataProvider="{eGamingSession.user Manager.userCollection}"

                                                                      labelField="displayName"

                                                                      width="100%" height="100%">

 

                                                            <s:itemRenderer>

                                                                      <fx:Component>

                                                                                <s:ItemRenderer>

                                                                                          <fx:Script>

                                                                                                    <![CDATA[

                                                                                                              import mx.events.FlexEvent;

 

                                                                                                                        // TODO Auto-generated method stub

 

                                                                                                              override public function set data(value:Object):void {

                                                                                                                        super.dat a = value;

 

                                                                                                                        // Check to see if the data property is null.

                                                                                                                        if (value== null)

                                                                                                                                  retu rn;

                                                                                                                        // If the data property is not null, 

                                                                                                                        // set the CheckBox control appropriately..

                                                                                                                        if (value.customFields.score == 10) {

                                                                                                                                  user Stepper.value = 10;

                                                                                                                        }

                                                                                                                        else {

                                                                                                                                  user Stepper.value = 0;

                                                                                                                        }

                                                                                                              }

 

                                                                                                    ]]>

                                                                                          </fx:Script>

 

                                                                                          <s:HGroup width="100%">

 

                                                                                                    <s:Label text="{data.displayName}" paddingTop="5" width="60%"/>

 

                                                                                                    <s:NumericStepper id="userStepper" width="10%" value="{data.customFields['score']}"/>

 

                                                                                          </s:HGroup>

 

                                                                                </s:ItemRenderer>

                                                                      </fx:Component>

                                                            </s:itemRenderer>

                                                  </s:List>

 

 

The problem is I don't see the customFields property set in the item renderer. I see it in the creationCompleteHandler, but it is not passed to the item renderer. Is the customFields not intended to be used this way?

 

Will appreciate any insight,

Thanks!

 
Replies
  • Currently Being Moderated
    Oct 14, 2011 8:51 AM   in reply to RituKnowsFlex

    Hi there,

     

    In order to set a custom user field, you have to round-trip it through the service - the line you've got in the creationComplete handler won't be enough. In general, the "descriptor" classes are meant to describe the state of the app, but can't be manipulated directly - you refer to the appropriate manager class' APIs to make changes (which will then be reflected in updates to the descriptors).

     

    In this case, the API you want is here : http://livedocs.adobe.com/labs/acrobatcom/com/adobe/rtc/sharedManagers /UserManager.html#setCustomUserField()

     

    (Note that you have to set up your custom fields ahead of time by registering them at developer time - either use the Room Console for this, or use the registerCustomUserField method in userManager).

     

    hope that helps

      nigel

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 18, 2011 5:25 PM   in reply to RituKnowsFlex

    Hi Ritu,

     

    My guess in this case is that the data binding you're doing in the stepper doesn't work with objects 2-levels deep (data.customFields.score). Could you add an eventlistener to userManager for UserEvent.CUSTOM_FIELD_CHANGE, and see if your changes are actually being round-tripped to the service? What evidence do you have that the userCollection is being updated? I don't see anything in the code above (the trace there happens too soon to tell).

     

    If your changes are generating events, the next thing I'd check is to see whether this is causing your itemRenderer's set data function to be triggered. If that's the case, then at least you could manually assign the value to the numeric stepper.

     

      hope that helps

       nigel

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 19, 2011 10:06 AM   in reply to RituKnowsFlex

    Hi Ritu,

     

    So, you're saying you don't see a custom field change handler get fired? If that's the case, it's the code that's calling setCustomUserField which isn't working. Are you running this application with developer credentials? If you step into that code, do you see it succeeding in doing anything in the LCCS codebase?

     

      nigel

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 19, 2011 10:54 AM   in reply to RituKnowsFlex

    Sorry, this is really confusing. You say you *are* seeing the event handler fire when you start up the app? And now, you're somehow causing the numeric stepper to trigger further setCustomUserField calls, but you're not seeing that fire events? How are you hooking up the stepper to the setCustom call? I don't see any code for that.

     

      nigel

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points