4 Replies Latest reply: Jul 16, 2011 11:38 AM by cane2980 RSS

    Quick shared object question.

    cane2980 Community Member

      total newb just learning about shared objects. Looking for a answer I don't seem to find.

       

      Was at a site the other day that used a shared oject to tell me how long I had been viewing the page. I left the page, came back and the counter restarted right where it was when I left. This is cool, but what if there are say 30 people viewing the same page at the same time? As I can't write the code "myObject = new sharedObject" to get a new instance of the shared object, how is this done? Or, when I use the "get local (remote) sharedObject" does that give me a new instance of the shared object? Or is there only ever 1 instance of a shared object?

       

      The reason I ask is say I'm writing a multipalyer game, and I want to store user information in a shared object so it displays in everyones swf. Well If I have only 2 people playing the game, fine, that's 2 shared objects. But what if there are 100 people playing the game? Or am I looking at the shared object use all wrong in the first place? I only have a small pea sized man brain so the logic escapes me...

       

      Please give any help you can, and thanks for any help you provide.

      Cane

        • 1. Re: Quick shared object question.
          Ned Murphy CommunityMVP

          Think of a shared object like a cookie... it is something that is stored on the user's machine.  So you cannot have other users make use of someone else's 'cookie'.

           

          You would likely need a database if you intend to have information about multiple users being visible to all currently accessing the application.

          • 2. Re: Quick shared object question.
            cane2980 Community Member

            Ok Ned, thanks by the way, that kind of helps. In the example I saw on the of the timed viewing on the web page, when the shared object was activated, it downloaded to my hard disk like a cookie, that makes sence.

             

            But I've also read about a shared object being used to parse messages in a chatroom. So, if I'm now understanding how it works correctly... Then in like a chatroom environment, my swf places a call to the server as "get remote sharedObject", the shared object downloads to my swf and waits there, when another user types a message it goes to the shared object. My shared object, because it's shared, grabbs the message and parses it in my text window. Of course you have to program around stack message issues when more than one person sends a message at the same time.

             

            Am I now getting the hang of how it works correctly?

             

            thanks again;

            • 3. Re: Quick shared object question.
              dmeN Community Member

              Like Ned said, the SO is local to each machine... remember Flash plays at the client - so regardless of how many people are playing the game the data in the SO is unique to them. You only ever need the one object...

              • 4. Re: Quick shared object question.
                cane2980 Community Member

                yes, thank you very much. This clears up a lot of thing for me. In one of my books it says when you use the flush comand it dumps the information the hard disk on the server. That appears to be incorrect. What it should say is it dumps it to the hard disk of the flash player using the shared object. Wow a typo in an actionscript 3 book... Go figure!