Expand my Community achievements bar.

Odd double updates

Avatar

Level 1

Hi there!

I'm pretty new with AFCS and I'm trying to create something for moving images together.

Simple as that I use a SharedCollection but when updating or adding new pictures something unwanted happens. The updated X and Y coordinates, which are set with

sharedModel.addItem({X:x, Y:y, ID:id, SOURCEID:sourceid});

at once, are received as two update commands, with the first only changing the X value and the second with the complete X and Y change.

Doesn't matter you might think, but the problem for me is, that i move the Images with a move effect, so the moving behaviour is pretty edgy, moving first to the new X position and then finally to the target position.

Can anyone explain me the double updates and how do i suppress them? Or are there only workarounds? (I'd hate, to filter the updates ....)

Thanks already,

Jonas

5 Replies

Avatar

Employee

Hi,

Just a few alternative,

1) Instead of sending X& Y seperately can you send a Point object. (remember to register the class using MessageItem.registerBodyClass(Point) )

2) As you are just updating just the X&Y values you can use sharedProperty instead of SharedCollection

3) Please explore SharedCursorPane and might suit you better.

Thanks

Arun

Avatar

Former Community Member

Hi Jonas,

I'm pretty baffled as to why (or how!) it would take only one value of an untyped object and send it by itself. We don't process your message body before sending (except to AMF3 serialize them, if you registerBodyClass them, not the case here).

Care to share some more code? Any other place where you're adding or removing to that SharedCollection? Are you seeing this every single time you send, or while subscribing to the collection the first time?

Thanks for the feedback, I'm curious to get to the bottom of it.

nigel

Avatar

Level 1

Hi again!

Thanks for the replies first!

Well, I found the solution myself after tracing the update routine a bit.

The problem was, that the AFCS service sends the updates of object properties separately.First updating the X value and then sending the new Y value.

The delivered item in the first update call is something like this:

item.property = X

item.newValue = 123

item.oldValue = 122

item.source.X = 123

item.source.Y = 111

and in the second call:

item.property = Y

item.newValue = 123

item.oldValue = 111

item.source.X = 123

item.source.Y = 123

I simply took the item.source.X and item.source.Y and updated the local model, which led to the double update, messing up my animation.

I changed the updating part to this, so my animation is safe:

private function onCollectionChange(event:CollectionEvent):void
        {
       
            var item:Object = event.items[0] ;
           
            if ( event.kind == CollectionEventKind.ADD )
            {
                ...some code
            }
            else if (  event.kind == CollectionEventKind.REMOVE )
            {      
                ...some code
            }
            else if ( event.kind == CollectionEventKind.UPDATE )
            {
                trace ("UPDATING ITEM TO",item.source.X,item.source.Y,"WITH ID",item.source.ID);
               
                for ( var i:int = 0 ; i < localModel.length ; i++ ) {
                    if ( localModel.getItemAt(i).ID == item.source.ID) {
                        var updatedUnit:Unit = localModel.getItemAt(i) as Unit;
                       
                        if (item.property == "X")
                        {
                            updatedUnit.updateX(item.newValue);
                        }
                        if (item.property == "Y")
                        {
                            updatedUnit.updateY(item.newValue);
                            dispatchEvent(new UnitChangeEvent(UnitChangeEvent.UNIT_UPDATE,updatedUnit));
                        }                       
                    }
                }
            }
        }

Before it was something like:

     localModel.setItemAt({ID:item.source.ID, X:item.source.X, Y:item.source.Y});

So far. If you are interested in more code, let me know.

The whole thing is for a boardgame collaboration service, to play boardgames together online.

You may want to have a look at http://www.volger.org/om/

Avatar

Former Community Member

I'm still super-confused by this - the service is definitely not splitting up your message item bodies. Glad you've got it working though. We should still look into this.

thanks

nigel

Avatar

Level 1

Hey again,

well, if you are still not satiesfied I'm willing to dive more into this!

For me it doesn't seem like an unnormal behaviour. I think I simply misunderstood the mechanics of the service. At one point a set the new Objects (setting 2 values simultaneously) and the service tells me about each changed value - in two update events. What else is it supposed to do? Or didn't I make myself clear ..?

To answer your questions (sorry to not answer them before):

>> I'm pretty baffled as to why (or how!) it would take only one value of an untyped object and send it by itself.

Honestly - I don't understand that sentence exactly! I'm not a native english speaker, maybe you could formulate it somehow different ...

>> We don't process your message body before sending (except to AMF3 serialize them, if you registerBodyClass them, not the case here).

So it should just send the updated object as a whole?

>> Care to share some more code?

What do you need.

>> Any other place where you're adding or removing to that SharedCollection?

Only one adding and one removing and one updating routine. Pretty simple. Changes are written to the local model only via onCollectionChange Event.

>> Are you seeing this every single time you send, or while subscribing to the collection the first time?

Yes, every time. But doesn't seem to me like an abnormal behaviour.

Well, hoping to help.

Jonas