12 Replies Latest reply on Aug 11, 2010 7:45 AM by mldb88

    Help with shared objects...again...

    mldb88 Level 2

      Okay, I've been looking at a really good tutorial for shared objects in AS2, and I think I've gotten the basic concept down of how they work... now the problem lies in just integrating it into what I already have, which is making my brain hurt.  Basically its for a quiz game, which will have a dynamic scoreboard.  I want the scores in the shared object to update when the submit button is pressed, and then have the new values loaded into text boxes.  Displaying the values is going to be the easy part, its just updating them is what my brain doesnt want to wrap itself around.  Here is the array I have at the moment (yes, horribly inefficient, but the last time I actually did any coding before this was over 2 years ago when I was still a computer science major... with all of 4 actual Comp Sci courses under my belt -_-)

       

       

      scores= new Array();
      names= new Array();
      insert=function() {
           var newscore;
           var newname;
           newscore=0
           newscore=_global.correct;
           if (newscore > scores[0]) {
               scores[14]=scores[13];
               scores[13]=scores[12];
               scores[12]=scores[11];
               scores[11]=scores[10];
               scores[10]=scores[9];
               scores[9]=scores[8];
               scores[8]=scores[7];
               scores[7]=scores[6];
               scores[6]=scores[5];
               scores[5]=scores[4];
               scores[4]=scores[3];
               scores[3]=scores[2];
               scores[2]=scores[1];
               scores[1]=scores[0];
               scores[0]=newscore;
               names[14]=names[13];
               names[13]=names[12];
               names[12]=names[11];
               names[11]=names[10];
               names[10]=names[9];
               names[9]=names[8];
               names[8]=names[7];
               names[7]=names[6];
               names[6]=names[5];
               names[5]=names[4];
               names[4]=names[3];
               names[3]=names[2];
               names[2]=names[1];
               names[1]=names[0];
               names[0]=newname;
           }
               else if (newscore > scores[1]) {
               scores[14]=scores[13];
               scores[13]=scores[12];
               scores[12]=scores[11];
               scores[11]=scores[10];
               scores[10]=scores[9];
               scores[9]=scores[8];
               scores[8]=scores[7];
               scores[7]=scores[6];
               scores[6]=scores[5];
               scores[5]=scores[4];
               scores[4]=scores[3];
               scores[3]=scores[2];
               scores[2]=scores[1];
               scores[1]=newscore
               names[14]=names[13];
               names[13]=names[12];
               names[12]=names[11];
               names[11]=names[10];
               names[10]=names[9];
               names[9]=names[8];
               names[8]=names[7];
               names[7]=names[6];
               names[6]=names[5];
               names[5]=names[4];
               names[4]=names[3];
               names[3]=names[2];
               names[2]=names[1];
               names[1]=newname;

      Continues all the way down to scores[14]

      Now, if I wanted this to pull data from the shared object, would I just put user_so.score[3]=user_so.score[2] for instance?  Or would I run the array and just update the new valued individually once the array insertion function completes?  THe problem with the latter is that it's not directly accessing the shared object so I'd need to find a way to pull them out into other variables first, and this is about the point where my brain just decides to short out on me and stop working alltogether...yay...

      So yea, any help on this would be much appreciated.

      also, would the array have to be declared within the shared object as well?  If so, how would I do that exactly?  Probably something so simple but the fact that it's shared objects is throwing me off...

        • 1. Re: Help with shared objects...again...
          kglad Adobe Community Professional & MVP

          after you instantiate your sharedobject (eg, so), you use:

           

          so.data.variablename=value;

          so.flush();

           

          to immediatedly update your so.

           

          use

           

          yourvariable=so.data.variablename;

           

          to update yourvariable's value using the so.

          • 2. Re: Help with shared objects...again...
            mldb88 Level 2

            Okay, so would it be better to just pool all the so data into temporary variables to be used in the array, and then dump the results back into the so?

            or would it be better to directly update the so through the array function I have set up?


            • 3. Re: Help with shared objects...again...
              kglad Adobe Community Professional & MVP

              you can store an array in an so:

               

               

              so.data.soArray = yourArray;

              • 4. Re: Help with shared objects...again...
                mldb88 Level 2

                Ok, and one last question, would it be possible to have two swf files accessing the shared object at the same time (say, the quiz is

                dropping values into the so, and a banner is pulling them out and displaying them, reloading the so every time it loops back to frame one, but both are running simultaneously)?

                • 5. Re: Help with shared objects...again...
                  kglad Adobe Community Professional & MVP

                  yes, but you don't want to stuff the user's i-net connection by updating too frequently.  you should update the so only when there's something to change and you should be checking the so only when something is changed.

                   

                  you can use the localconnection class to communicate between the two swfs so the 2nd swf knows when the so has been updated.  which makes it clear you shouldn't be using the so.  when you want to communicate between two swfs that are open at the same time by the same client, use the localconnection class only.

                  • 6. Re: Help with shared objects...again...
                    mldb88 Level 2

                    Ok, do you know of any tutorials or anything that explain how to do that?

                    Never even encountered a localconnection class object before so I'm not sure

                    how I'd implement such a thing.

                    • 7. Re: Help with shared objects...again...
                      kglad Adobe Community Professional & MVP

                      check the flash help files.  there is sample code that shows how to use localconnection.

                       

                      create two test flas and copy the code from the help files and get that working.  you can then implement that code to your current project.

                      • 8. Re: Help with shared objects...again...
                        mldb88 Level 2

                        ok, and can this be done in AS2 as well as AS3?

                        • 9. Re: Help with shared objects...again...
                          mldb88 Level 2

                          Ok, the shared object WAS working just fine until I had the banner start referencing it.  Then the quiz began giving me syntax errors like crazy, and even when the banner isnt runnit it gives me issues.

                           

                           

                          user_so.data.soArray[0]=scores[0];
                          user_so.data.soArray[1]=scores[1];
                          user_so.data.soArray[2]=scores[2];
                          user_so.data.soArray[3]=scores[3];
                          user_so.data.soArray[4]=scores[4];
                          user_so.data.soArray[5]=scores[5];
                          user_so.data.soArray[6]=scores[6];
                          user_so.data.soArray[7]=scores[7];
                          user_so.data.soArray[8]=scores[8];
                          user_so.data.soArray[9]=scores[9];
                          user_so.data.soArray[10]=scores[10];
                          user_so.data.soArray[11]=scores[11];
                          user_so.data.soArray[12]=scores12];
                          user_so.data.soArray[13]=scores[13];
                          user_so.data.soArray[14]=scores[14];
                              _global.player= "Input Name";
                              player.text=_global.player;
                              _global.correct= 0;
                              phrase=" ";
                          gotoAndStop (1);
                          }

                           

                          these are the lines it's telling me I need an on handler for, which I do have, at the very start of the entire code.

                          Ive counted the brackets and those seem to line up, but I'll double check again.  The code is on the submit button itself (yes I know it's poor coding form, but this is how I learned it and what I'm used to, and since I'm on a bit of a time schedule now isn't the time to completely re-learn the proper conventions and etiquite of coding in flash).

                          on (release) {
                              if (user_so.data.tname!=undefined){
                                  user_so.data.tname = _global.player;
                                  user_so.data.newscore = _global.correct;
                                  insert=function() {
                              var newscore;
                              var newname;
                              newscore=0
                              newscore=_global.correct;
                              if (newscore > scores[0]) {
                                  scores[14]=scores[13];
                                  scores[13]=scores[12];
                                  scores[12]=scores[11];
                                  scores[11]=scores[10];
                                  scores[10]=scores[9];
                                  scores[9]=scores[8];
                                  scores[8]=scores[7];
                                  scores[7]=scores[6];
                                  scores[6]=scores[5];
                                  scores[5]=scores[4];
                                  scores[4]=scores[3];
                                  scores[3]=scores[2];
                                  scores[2]=scores[1];
                                  scores[1]=scores[0];
                                  scores[0]=newscore;
                                  names[14]=names[13];
                                  names[13]=names[12];
                                  names[12]=names[11];
                                  names[11]=names[10];
                                  names[10]=names[9];
                                  names[9]=names[8];
                                  names[8]=names[7];
                                  names[7]=names[6];
                                  names[6]=names[5];
                                  names[5]=names[4];
                                  names[4]=names[3];
                                  names[3]=names[2];
                                  names[2]=names[1];
                                  names[1]=names[0];
                                  names[0]=newname;
                              }
                                  else if (newscore > scores[1]) {
                                  scores[14]=scores[13];
                                  scores[13]=scores[12];
                                  scores[12]=scores[11];
                                  scores[11]=scores[10];
                                  scores[10]=scores[9];
                                  scores[9]=scores[8];
                                  scores[8]=scores[7];
                                  scores[7]=scores[6];
                                  scores[6]=scores[5];
                                  scores[5]=scores[4];
                                  scores[4]=scores[3];
                                  scores[3]=scores[2];
                                  scores[2]=scores[1];
                                  scores[1]=newscore
                                  names[14]=names[13];
                                  names[13]=names[12];
                                  names[12]=names[11];
                                  names[11]=names[10];
                                  names[10]=names[9];
                                  names[9]=names[8];
                                  names[8]=names[7];
                                  names[7]=names[6];
                                  names[6]=names[5];
                                  names[5]=names[4];
                                  names[4]=names[3];
                                  names[3]=names[2];
                                  names[2]=names[1];
                                  names[1]=newname;
                              }

                              else if (newscore > scores[2]) {
                                  scores[14]=scores[13];
                                  scores[13]=scores[12];
                                  scores[12]=scores[11];
                                  scores[11]=scores[10];
                                  scores[10]=scores[9];
                                  scores[9]=scores[8];
                                  scores[8]=scores[7];
                                  scores[7]=scores[6];
                                  scores[6]=scores[5];
                                  scores[5]=scores[4];
                                  scores[4]=scores[3];
                                  scores[3]=scores[2];
                                  scores[2]=newscore;
                                  names[14]=names[13];
                                  names[13]=names[12];
                                  names[12]=names[11];
                                  names[11]=names[10];
                                  names[10]=names[9];
                                  names[9]=names[8];
                                  names[8]=names[7];
                                  names[7]=names[6];
                                  names[6]=names[5];
                                  names[5]=names[4];
                                  names[4]=names[3];
                                  names[3]=names[2];
                                  names[2]=newname;
                              }
                                  else if (newscore > scores[3]) {
                                  scores[14]=scores[13];
                                  scores[13]=scores[12];
                                  scores[12]=scores[11];
                                  scores[11]=scores[10];
                                  scores[10]=scores[9];
                                  scores[9]=scores[8];
                                  scores[8]=scores[7];
                                  scores[7]=scores[6];
                                  scores[6]=scores[5];
                                  scores[5]=scores[4];
                                  scores[4]=scores[3];
                                  scores[3]=newscore;
                                  names[14]=names[13];
                                  names[13]=names[12];
                                  names[12]=names[11];
                                  names[11]=names[10];
                                  names[10]=names[9];
                                  names[9]=names[8];
                                  names[8]=names[7];
                                  names[7]=names[6];
                                  names[6]=names[5];
                                  names[5]=names[4];
                                  names[4]=names[3];
                                  names[3]=newname;
                                  }
                                  else if (newscore > scores[4]) {
                                  scores[14]=scores[13];
                                  scores[13]=scores[12];
                                  scores[12]=scores[11];
                                  scores[11]=scores[10];
                                  scores[10]=scores[9];
                                  scores[9]=scores[8];
                                  scores[8]=scores[7];
                                  scores[7]=scores[6];
                                  scores[6]=scores[5];
                                  scores[5]=scores[4];
                                  scores[4]=newscore;
                                  names[14]=names[13];
                                  names[13]=names[12];
                                  names[12]=names[11];
                                  names[11]=names[10];
                                  names[10]=names[9];
                                  names[9]=names[8];
                                  names[8]=names[7];
                                  names[7]=names[6];
                                  names[6]=names[5];
                                  names[5]=names[4];
                                  names[4]=newname;
                                      }
                                  else if (newscore > scores[5]) {
                                  scores[14]=scores[13];
                                  scores[13]=scores[12];
                                  scores[12]=scores[11];
                                  scores[11]=scores[10];
                                  scores[10]=scores[9];
                                  scores[9]=scores[8];
                                  scores[8]=scores[7];
                                  scores[7]=scores[6];
                                  scores[6]=scores[5];
                                  scores[5]=newscore;
                                  names[14]=names[13];
                                  names[13]=names[12];
                                  names[12]=names[11];
                                  names[11]=names[10];
                                  names[10]=names[9];
                                  names[9]=names[8];
                                  names[8]=names[7];
                                  names[7]=names[6];
                                  names[6]=names[5];
                                  names[5]=newname;
                                          }
                                  else if (newscore > scores[6]) {
                                  scores[14]=scores[13];
                                  scores[13]=scores[12];
                                  scores[12]=scores[11];
                                  scores[11]=scores[10];
                                  scores[10]=scores[9];
                                  scores[9]=scores[8];
                                  scores[8]=scores[7];
                                  scores[7]=scores[6];
                                  scores[6]=newscore;
                                  names[14]=names[13];
                                  names[13]=names[12];
                                  names[12]=names[11];
                                  names[11]=names[10];
                                  names[10]=names[9];
                                  names[9]=names[8];
                                  names[8]=names[7];
                                  names[7]=names[6];
                                  names[6]=newname;
                                  }
                                      else if (newscore > scores[7]) {
                                  scores[14]=scores[13];
                                  scores[13]=scores[12];
                                  scores[12]=scores[11];
                                  scores[11]=scores[10];
                                  scores[10]=scores[9];
                                  scores[9]=scores[8];
                                  scores[8]=scores[7];
                                  scores[7]=newscore;
                                  names[14]=names[13];
                                  names[13]=names[12];
                                  names[12]=names[11];
                                  names[11]=names[10];
                                  names[10]=names[9];
                                  names[9]=names[8];
                                  names[8]=names[7];
                                  names[7]=newname;
                                      }
                                          else if (newscore > scores[8]) {
                                  scores[14]=scores[13];
                                  scores[13]=scores[12];
                                  scores[12]=scores[11];
                                  scores[11]=scores[10];
                                  scores[10]=scores[9];
                                  scores[9]=scores[8];
                                  scores[8]=newscore;
                                  names[14]=names[13];
                                  names[13]=names[12];
                                  names[12]=names[11];
                                  names[11]=names[10];
                                  names[10]=names[9];
                                  names[9]=names[8];
                                  names[8]=newname;
                                          }
                                              else if (newscore > scores[9]) {
                                  scores[14]=scores[13];
                                  scores[13]=scores[12];
                                  scores[12]=scores[11];
                                  scores[11]=scores[10];
                                  scores[10]=scores[9];
                                  scores[9]=newscore;
                                  names[14]=names[13];
                                  names[13]=names[12];
                                  names[12]=names[11];
                                  names[11]=names[10];
                                  names[10]=names[9];
                                  names[9]=newname;
                                              }
                                                  else if (newscore > scores[10]) {
                                  scores[14]=scores[13];
                                  scores[13]=scores[12];
                                  scores[12]=scores[11];
                                  scores[11]=scores[10];
                                  scores[10]=newscore;
                                  names[14]=names[13];
                                  names[13]=names[12];
                                  names[12]=names[11];
                                  names[11]=names[10];
                                  names[10]=newname;
                                                  }
                                                      else if (newscore > scores[11]) {
                                  scores[14]=scores[13];
                                  scores[13]=scores[12];
                                  scores[12]=scores[11];
                                  scores[11]=newscore;
                                  names[14]=names[13];
                                  names[13]=names[12];
                                  names[12]=names[11];
                                  names[11]=newname;
                                                      }
                                                          else if (newscore > scores[12]) {
                                  scores[14]=scores[13];
                                  scores[13]=scores[12];
                                  scores[12]=newscore;
                                  names[14]=names[13];
                                  names[13]=names[12];
                                  names[12]=newname;
                                                          }   
                                                          else if (newscore > scores[13]) {
                                  scores[14]=scores[13];
                                  scores[13]=newscore;
                                  names[14]=names[13];
                                  names[13]=newname;
                                                          }
                                                              else if (newscore > scores[14]) {
                                  scores[14]=newscore;
                                  names[14]=newname;
                                                              }
                          }
                              }
                              else {
                                  user_so.data.tname = _global.player;
                                  user_so.data.newscore = _global.correct;

                                  scores[0]=user_so.data.newscore;
                                  names[0]=user_so.data.tname;
                                 
                                 
                             
                              }
                          user_so.data.soArray[0]=scores[0];
                          user_so.data.soArray[1]=scores[1];
                          user_so.data.soArray[2]=scores[2];
                          user_so.data.soArray[3]=scores[3];
                          user_so.data.soArray[4]=scores[4];
                          user_so.data.soArray[5]=scores[5];
                          user_so.data.soArray[6]=scores[6];
                          user_so.data.soArray[7]=scores[7];
                          user_so.data.soArray[8]=scores[8];
                          user_so.data.soArray[9]=scores[9];
                          user_so.data.soArray[10]=scores[10];
                          user_so.data.soArray[11]=scores[11];
                          user_so.data.soArray[12]=scores12];
                          user_so.data.soArray[13]=scores[13];
                          user_so.data.soArray[14]=scores[14];
                              _global.player= "Input Name";
                              player.text=_global.player;
                              _global.correct= 0;
                              phrase=" ";
                          gotoAndStop (1);
                          }

                          • 10. Re: Help with shared objects...again...
                            mldb88 Level 2

                            of course i find the typo that ruined the whole thing 5 sseconds AFTERposting... but the banner portion still says undefined for some reason...

                             

                            Banner code:

                            onClipEvent(enterFrame){
                                _root.score_txt.text=user_so.data.sonames[0],user_so.data.soArray[0],user_so.data.sonames [1],user_so.data.soArray[1];

                             

                            }

                            its on a small object outside of the stage.

                            • 11. Re: Help with shared objects...again...
                              kglad Adobe Community Professional & MVP

                              i'm not sure what you're trying to display and whatever it is shouldn't be in an onEnterFrame loop attached to an object.

                               

                              but try:

                               

                                  _root.score_txt.text=user_so.data.sonames[0]+","+user_so.data.soArray[0]+","+ user_so.data.sonames[1]+","+user_so.data.soArray[1];

                              • 12. Re: Help with shared objects...again...
                                mldb88 Level 2

                                ok, it's displaying the variables as undefined.... ugh....

                                ive tried defining the arrays from the shared object in the main timeline, still not coming up as the values stored in there.