Not receiving onSync delete events for multiple SharedObjects in same SWF
Asked Answered
R

3

14

I have an application that uses Remote SharedObjects and I am seeing some strange behaviour. I am writing an ActionScript application in AS3 using Flash Builder and connecting to Wowza Media Server 2.

My application is working just fine but I am now trying to write unit tests for it using FlexUnit. My unit tests involve creating multiple connections to the same remote SharedObject and making sure that I am getting updates correctly. Everything seems to be working well except that I am not getting any of the SyncEvent.SYNC events with an info.code of "delete". When I run my applications independently in separate tabs or even separate swfs embedded in the same page it works fine. For some reason though it does not work when inside a unit test. I have also found that if I load the swfs using a Loader inside the same SWF then I get the same behaviour. It seems to me to be something strange about the way multiples of the same SharedObject behave within the same SWF. I have had to work around other strange behaviour in the unit tests such as oldValues not being set properly in the onSync events too.

Anyone have any ideas how I can work around this? Is this a known issue? Am I crazy? :)

Would appreciate any help!

Rusert answered 27/2, 2011 at 6:27 Comment(2)
You are not crazy! Same happened to me today, I lost 8 hours finding out that this happens. I was using more references to one remote SO and when I removed event listener I removed all of them, or when I closed one reference to SO, I closed all.. SharedObject seems to be very buggy singleton.Kelseykelsi
I realise this is an old thread but it's 2016 and I'm getting this problem - was this ever resolved?Constantino
C
0

I also faced this problem before when I was working on some Flex application using some coding frameworks like Cairngorm, and connecting to AMFPHP with multi remote objects.

At that time what I come up with to resolve the issue is to make sure that those remote objects won't be fired at the same time. That is trying to make some so called "sequential chain" to fire those remote objects one after another.

In order to achieve this it may be difficult if you do it from scratch, you may consider making use of those modern ActionScript framework 2.0 to help you (e.g. SWIZ or Robotlegs). This may be too complex to handle in the very beginning. I suggest you can just place the remote object parts to be handled by the framework while keeping other things intact.

Chlorohydrin answered 19/10, 2011 at 8:6 Comment(0)
R
0

To get your sharedObject instance, you are using the static method SharedObject.getRemote(). I believe this method will always return the same instance for a given name (and if the persistence parameter has the same value).

You can have the same kind of issue when you remove a SharedObject from your app (mySO = null) and you reinstantiate it before the garbage collector did its job).

This kind of behavior makes sense to me, but it can sometimes be a problem I must admit. Anyway it should be easy to test in a debug session (Have a look at your objects instance number).

Now talking about unit tests, what are you testing? The SharedObjects behavior? If so, I believe there is some misconception here. It you really want to test this kind of behavior (and I would be interested in the reason behind), then I guess you will need some more complex tests that run two separate applications.

Hope it helps!

Refrigerant answered 6/6, 2013 at 3:13 Comment(0)
A
0

We had similar behavior with deletes in our project. When we call so.close(). Then delete some key in shared object. Then connect SO again - it still see deleted key alive.

Workarounds: do not close SO or update deleted keys with some constants values (-2 for example) to mark them deleted.

Wowza 3 was used.

Aubert answered 10/6, 2014 at 14:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.