Expand my Community achievements bar.

sharedproperty initial value

Avatar

Level 4

i've created a SharedProperty instance.  i've already created a CollectionNode and a nodeName for it in the Room.  i can update this SharedProperty value and read it, and with the Room console i can see that it is indeed being set.

however, when i first .subscribe() to this SharedProperty and try to trace its SharedProperty.value after the SYNCHRONIZATION_CHANGE event, the value is undefined, even when i can see in the Room console that it is set.  it's just a number.

do i have to wait for some other event to complete before i can get a SharedProperty's value? it seems like i'm missing something very simple here.

1 Reply

Avatar

Employee

Hi,

It did work for me. Can you share your code... I pasted the code I used to test...

It would be undefined the first time you run. Click on the button to set some value. Close the app, and run the second time, and I see the sharedProperty value on just subscribing.

Thanks

Arun

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:rtc="http://ns.adobe.com/rtc" xmlns:authentication="com.adobe.rtc.authentication.*" xmlns:session="com.adobe.rtc.session.*" xmlns:collaboration="com.adobe.rtc.collaboration.*">

     <mx:Script>
          <![CDATA[
               import com.adobe.rtc.events.CollectionNodeEvent;
               import com.adobe.rtc.events.SharedPropertyEvent;
               import com.adobe.rtc.sharedModel.SharedProperty;
              
               import flashx.textLayout.tlf_internal;
              
               import mx.controls.Alert;
               import mx.events.FlexEvent;
              
               [Bindable]
               protected var _sharedProperty:SharedProperty ;
              
               protected function cSession_creationCompleteHandler(event:Event):void
               {
                    if (cSession.isSynchronized) {
                         _sharedProperty = new SharedProperty();
                         _sharedProperty.sharedID = "sProp" ;
                         _sharedProperty.connectSession = cSession ;
                         _sharedProperty.addEventListener(SharedPropertyEvent.CHANGE,onChange);
                         _sharedProperty.addEventListener(CollectionNodeEvent.SYNCHRONIZATION_CHANGE, onSyncChange);
                         _sharedProperty.subscribe();
                    }
                   
               }
              
               protected function startBtn_clickHandler(event:Event):void
               {
                    // TODO Auto-generated method stub
                    Alert.show(sPText.text);
                    trace("Settinga random value");
                    _sharedProperty.value = (Math.random()*1000).toString();
                   
               }
              
               protected function onChange(p_evt:SharedPropertyEvent):void
               {
                    if (sPText) {
                         sPText.text += p_evt.value;
                    }
               }
              
               protected function onSyncChange(p_evt:CollectionNodeEvent):void
               {
                    if (sPText) {
                         sPText.text += _sharedProperty.value;
                    }
               }

          ]]>
     </mx:Script>
    
     <!--
     You would likely use external authentication here for a deployed application;
     you would certainly not hard code Adobe IDs here.
     -->
     <authentication:AdobeHSAuthenticator
          id="auth"
          userName="xyz@xyz.com"
          password=""
          />
     <session:ConnectSessionContainer id="cSession" authenticator="{auth}" width="100%" height="100%" roomURL="https://collaboration.adobelivecycle.com/uName/roomName" creationComplete="cSession_creationCompleteHandler(event)">
          <mx:VBox width="100%" height="100%">
               <mx:Button  id="startBtn" label="Get value"  click="startBtn_clickHandler(event)" height="20" enabled="{_sharedProperty.isSynchronized}"/>
               <mx:Label text="SharedProp Value" id="sPText" />
          </mx:VBox>
     </session:ConnectSessionContainer>
</mx:Application>