13 Replies Latest reply on Jun 19, 2007 8:58 AM by GeckoProgrammer

    Flash Shared User Objects (Flash 8)

    GeckoProgrammer
      Okay, so I have a color bar movie clip.
      It has five colors and the colors change the background color.

      What I want to know is how to see (with actionscript) which frame the background (a movie clip) is on, so it remembers which color they selected. I would like to use Shared User Objects for this. I have tried and tried (for about 3 hours), but no success.


      Thanks in advance...
        • 1. Re: Flash Shared User Objects (Flash 8)
          Level 7
          GeckoProgrammer,

          > What I want to know is how to see (with actionscript)
          > which frame the background (a movie clip) is on,

          Reference the movie clip's instance name and check the
          MovieClip._currentframe property of that instance.

          > ... so it remembers which color they selected. I would
          > like to use Shared User Objects for this.

          For that, you'll need an instance of the SharedObject class, then access
          its data property. You can get and set properties (variables) of this data
          property.

          > I have tried and tried (for about 3 hours), but no success.

          Let's see your code so far. :)


          David Stiller
          Adobe Community Expert
          Dev blog, http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. Re: Flash Shared User Objects (Flash 8)
            kglad Adobe Community Professional & MVP
            use the _currentframe property of movieclips.
            • 3. Re: Flash Shared User Objects (Flash 8)
              GeckoProgrammer Level 1
              Wow! Thanks guys! You are so fast!
              • 4. Re: Flash Shared User Objects (Flash 8)
                GeckoProgrammer Level 1
                My code:

                local_data = SharedObject.getLocal("user_data");
                local_data.data.c = color;
                local_data.flush();

                color = bg23._currentframe

                if (color == "5"){
                bg23.gotoAndStop("green");
                } else if (color == 2){
                bg23.gotoAndStop("blue1");
                } else if (color == 3){
                bg23.gotoAndStop("blue2");
                } else if (color == 6){
                bg23.gotoAndStop("skin");
                } else if (color == 4){
                bg23.gotoAndStop("red");
                } else {
                bg23.gotoAndStop(1);
                }



                bg23 is my background movie clip
                • 6. Re: Flash Shared User Objects (Flash 8)
                  kglad Adobe Community Professional & MVP
                  color is an number, not a string.

                  and if you're assigning the value of color to your sharedobject, you should define it before assigning it.

                  if you're retrieving that value, you should be assigning local_data.c to color.
                  • 7. Re: Flash Shared User Objects (Flash 8)
                    GeckoProgrammer Level 1
                    I do assign a number to each color:

                    Color Button:

                    on(release){
                    _root.bg23.gotoAndStop("skin");
                    var color = 5;
                    }
                    • 8. Re: Flash Shared User Objects (Flash 8)
                      Level 7
                      GeckoProgrammer,

                      > My code:
                      >
                      > local_data = SharedObject.getLocal("user_data");

                      So far, so good. You've instantiated a SharedObject instance by way of
                      the static SharedOjbect.getLocal() method.

                      > local_data.data.c = color;

                      Here, you're either creating a new c property of your instance's data
                      property or you're setting the value of a c property already in existance.
                      Either way, you're setting it to whatever the value of color is.

                      > local_data.flush();

                      Here, you're flushing the SharedObject instance, which immediately saves
                      its data. This is all well and good -- or may be -- but you're not actually
                      *getting* information out of your shared object. What happens next time,
                      when the visitor has already been here? Do you want Flash to check that
                      "user_data" Flash cookie to see if c already has a value? I imagine you
                      do -- but that's only conjecture.

                      If that's your aim, check the value first, then use that if your if()
                      statements. Otherwise, your SWF will check the current frame of bg23 ...

                      > color = bg23._currentframe

                      ... which will presumably always be the same.

                      > if (color == "5"){
                      > bg23.gotoAndStop("green");
                      > } else if (color == 2){
                      > bg23.gotoAndStop("blue1");

                      A series of if() statements is perfectly fine, here. But you might want
                      to use a switch() statement. That way you could access bg23._currentframe
                      once and be done with it ... no need for the color variable.

                      switch(bg23._currentframe) {
                      case 3:
                      bg23.gotoAndStop("blue2");
                      break;
                      case 6:
                      bg23.gotoAndStop("skin");
                      break;
                      // etc.
                      }

                      Make sure that when you set that c property, you're setting it to a
                      variable or value that actually *has* a value. In your code sample, you're
                      setting c to color before color has been defined.


                      David Stiller
                      Adobe Community Expert
                      Dev blog, http://www.quip.net/blog/
                      "Luck is the residue of good design."


                      • 9. Re: Flash Shared User Objects (Flash 8)
                        kglad Adobe Community Professional & MVP
                        what's the point of assigning color in a button release and assigning it to be bg23._currentframe?
                        • 10. Flash Shared User Objects (Flash 8)
                          GeckoProgrammer Level 1
                          New code I have:


                          local_data = SharedObject.getLocal("user_data");

                          color = bg23._currentframe;

                          switch(bg23._currentframe) {
                          case 3:
                          bg23.gotoAndStop("blue2");
                          break;
                          case 6:
                          bg23.gotoAndStop("skin");
                          break;
                          case 9:
                          bg23.gotoAndStop("blue1");
                          break;
                          case 12:
                          bg23.gotoAndStop("green");
                          break;
                          case 15:
                          bg23.gotoAndStop("red");
                          break;
                          }

                          local_data.data.c = color;

                          local_data.flush();

                          • 11. Flash Shared User Objects (Flash 8)
                            GeckoProgrammer Level 1
                            <Duplacate message>
                            • 12. Re: Flash Shared User Objects (Flash 8)
                              Level 7
                              GeckoProgrammer,

                              >I still don't get it... it doesn't work:

                              That's the key, Gecko ... you need to make sure you *do* get it,
                              otherwise you'll be floundering. ;) Think carefully about what you're
                              asking Flash do to. Consider the order in which you're asking things to be
                              done.

                              Look at your code this time:

                              > local_data = SharedObject.getLocal("user_data");

                              Now you have your SharedObject instance. So far, so good. That
                              getLocal() method either retrieves an existing SharedObject, stored locally,
                              or it creates a new one (if one doesn't already exist).

                              > switch(bg23._currentframe) {
                              > case 0:
                              > bg23.gotoAndStop("blue2");
                              > break;
                              > // etc.

                              Here you're checking the current frame of the bg23 movie clip, and based
                              on the value of that number, you're sending that clip's timeline to a frame
                              label.

                              To my thinking, you want to see where the user *was* last time -- is
                              that right? If so, you'll want to check local_data.data.c to see if it
                              already has a value; that is, see if the user has already been here, and if
                              so, use c's value in your switch() statement.

                              As it is currently, the SWF will load up and always go to the same place
                              (assuming bg23 always starts on the same frame).

                              > local_data.data.c = color;


                              After all that checking, you're setting the c property to color (where
                              is this declared? -- the value of color is currently undefined).

                              > color = bg23._currentframe;

                              Now you're setting the value of color (but not using that value
                              anywhere).

                              > local_data.flush();

                              Finally, you're saving an undefined property, c, to your shared object.

                              I can only guess at what you're really after, but my guess is this:

                              a) SWF loads up.
                              b) Check for existing shared object.
                              c) Check for existing c property.
                              d) If c has a value (a number, presumably), use that value to determine
                              where to send bg23's timeline.
                              e) If c has no value, send bg23's timeline to your preferred default
                              location.
                              f) User interacts a bit with bg23. (Here's where I'm really guessing.)
                              Every time user interacts with bg23, update the c property with bg23's
                              _currentframe value, then flush.


                              David Stiller
                              Adobe Community Expert
                              Dev blog, http://www.quip.net/blog/
                              "Luck is the residue of good design."


                              • 13. Re: Flash Shared User Objects (Flash 8)
                                GeckoProgrammer Level 1
                                Thanks for taking is slow.

                                I understand now.