Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Correct way to close session

Avatar

Level 2

Hi,

I'm working with flash, not flex. I want to be able to

1. add an afcs object to stage,

2. subscribe to a baton property,

3. unsubscribe

4. remove the afcs object

5... repeat

1 to 4 are working, but when I try and repeat the process, I can't seem to subscribe.

I have three buttons on stage to add, logout and remove

function onLogin(e:MouseEvent):void
{
cocomo = new CocomoTest();
addChild(cocomo);
cocomo.login();
}

function onLogout(e:MouseEvent):void
{
cocomo.destroy();
}

function onRemove(e:MouseEvent):void
{
removeChild(cocomo);
}

And this is the Class

package
{
import flash.display.*;
import flash.events.*;

import com.adobe.rtc.session.ConnectSession;
import com.adobe.rtc.authentication.AdobeHSAuthenticator;
import com.adobe.rtc.authentication.LocalAuthenticator;

import com.adobe.rtc.events.SessionEvent;

import com.adobe.rtc.sharedModel.SharedProperty;
import com.adobe.rtc.sharedModel.BatonProperty;
import com.adobe.rtc.events.SharedPropertyEvent;
import com.adobe.rtc.events.SharedModelEvent;

public class CocomoTest extends MovieClip
{
 
  private var auth:AdobeHSAuthenticator;
  private var authL:LocalAuthenticator;
  private var session:ConnectSession;
 
  public var table1_northPlayer:BatonProperty;

  private var LOGINSYNCTYPE:String;
  
  public function Cocomo()
  {
  
  }

  //so step[ 1 is to log in...

  //after login and subscribing, I get notified:

  //RECEIVENODES table1_northPlayer
  //receiveAllSynchData table1_northPlayer

  public function login():void
  {
   auth      = new AdobeHSAuthenticator();
   auth.userName     = "myname";
   session     = new ConnectSession();
   session.roomURL   = "myroomurl";
   session.authenticator  = auth;
   session.addEventListener(SessionEvent.SYNCHRONIZATION_CHANGE, onLogin);
  
   try
   {
    LOGINSYNCTYPE    = "login";
    session.login();  
   }
   catch(e:Error)
   {
    trace (e.toString());
   }
  }

  //then i logout, close, any number of combinations i've tried

  //and remove the object from stage

  public function destroy():void
  {
   table1_northPlayer.close();

   LOGINSYNCTYPE    = "logout";
   session.logout();
  }


  private function onLogin(p_evt:SessionEvent):void
  {
  
   switch (LOGINSYNCTYPE)
   {
    case "login":
    
     trace ('login');
     table1_northPlayer     = new BatonProperty();
     table1_northPlayer.sharedID      = "table1_northPlayer";
     table1_northPlayer.subscribe();

    break;
   
    case "logout":
     trace ('logout');
     LOGINSYNCTYPE    = "close";
     session.close();
    break;


   }
  }
}
}

finally, when I try and repeat the process, i log in ok, but don't get the

RECEIVENODES table1_northPlayer
receiveAllSynchData table1_northPlayer

It seems like I'm not claring something properly but I'm not sure what.

Any help appreciated.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Mr. Turtle,

In this case, you're unwittingly taking advantage of the fact that LCCS objects, by default, subscribe themselves to the first ConnectSession you create. However, because you're creating fresh ConnectSessions each time, the objects are still grabbing an old ConnectSession, so they never succeed in synching past the first time. 2 ways you can remedy this :

1. Explicitly bind your LCCS objects to the correct ConnectSession. (ie. table1_northPlayer.connectSession = session;)

2. Instead of creating new ConnectSessions each time, re-use the original one.

Either approach should work.

hope that helps,

nigel

View solution in original post

0 Replies

Avatar

Correct answer by
Level 10

Hi Mr. Turtle,

In this case, you're unwittingly taking advantage of the fact that LCCS objects, by default, subscribe themselves to the first ConnectSession you create. However, because you're creating fresh ConnectSessions each time, the objects are still grabbing an old ConnectSession, so they never succeed in synching past the first time. 2 ways you can remedy this :

1. Explicitly bind your LCCS objects to the correct ConnectSession. (ie. table1_northPlayer.connectSession = session;)

2. Instead of creating new ConnectSessions each time, re-use the original one.

Either approach should work.

hope that helps,

nigel

Avatar

Level 2

Yep, that did the trick nicely.

Thanks for the helpful and speedy reply.

Graeme