A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: please help me create an array using shared objects

  1. #1
    Junior Member
    Join Date
    Sep 2004
    Location
    Osaka, Japan
    Posts
    27

    please help me create an array using shared objects

    Arggggh! I have been trying to make an array using my shared objects but I can't do it!!! I'm lost!!
    The components:
    -I have 10 multiple choice tests. Each test has 3 types for a total of 30 tests.
    -Each test has the saved variables stored in a shared object: test score, date&time, testname, student name, and number of times they took the test.
    The rules:
    -Any test can be taken any number of times by any student. This means that ALL information is saved and should never be overwritten.
    The objective:
    -I would like to save all data into an array without overwriting any previously saved data because if the same test is taken more than once I need to have that information too. (I will hopefully try to pull from this array later to populate dynamic text fields for a report card for all the tests ever taken.)
    The working pieces:
    -I am using 30 shared objects successfully. One shared object has 5 variables for each test. i.e. There are 3 book tests, 3 animal tests, 3 math tests, 3 sound tests, etc... The following variables are for color test #2 for example:
    color2LocalSO.data.score
    color2LocalSO.data.time
    color2LocalSO.data.what
    color2LocalSO.data.name
    color2LocalSO.data.counter

    Question:
    -Can someone please help me build the array to do this? I don't know anything about arrays or pushes. How can I get an array to look through 30 shared objects and save the new information without overwriting the old info when a student takes the same test more than once Can anyone point me in the right direction? I have been trying to do this for over a month!!

  2. #2
    Gods cower, women quiver. Buckwheat469's Avatar
    Join Date
    Dec 2003
    Location
    Uranus
    Posts
    247
    The issue with Flash is that unless you have a communication server or PHP working with your movie so that you can write the arrays into a database it's impossible to store the information.

    Think of Flash like javascript, it's client-side. So if you did record the values of the test then you would need something to tell your system what the student got as a score.

    As with arrays I think you can do:
    code:

    myArray = new array();
    myArray[1] = something;
    myArray[2] = somethingElse;
    echo myArray[2];



    You can also do variable names in the array:
    code:
    myArray[variable] = something;


    but that's not good becuase you can't do something like this:
    code:
    for(i=1;i<=5;i++){
    echo myArray[i];
    }



    You can do multilevel arrays too. From your C++ programming I would assume you know about multilevel arrays too.
    yup.

  3. #3
    Junior Member
    Join Date
    Sep 2004
    Location
    Osaka, Japan
    Posts
    27
    Thanks for the quick reply buckwheat!

    I was wondering if you could be a little more verbose. I mean detail the solution a little more. The concept you gave was fine, although I think it is not impossible to store the information. I am using shared objects and they work fine. I can store individual sets of variables in shared objects but I just want to populate an array without overwriting what was there. I just don't know how to write out the array is all.

    Still struggling,
    Challenged

  4. #4
    Gods cower, women quiver. Buckwheat469's Avatar
    Join Date
    Dec 2003
    Location
    Uranus
    Posts
    247
    Well if you are happy by using your shared objects then you can try that, but if you want to record the scores for grading then you will need some sort of server-side recording, like a database. Since Flash runs on the user's computer and not the server you can't directly interact with a database to record information like PHP can unless you either have Macromedia's addons for Flash or you link the Flash to PHP or ASP.

    For arrays you can do the 'for' statement to input as many values as you want.
    code:

    myArray = new array();
    nameArray = new array();

    for(i=1;i<=100;i++){
    myArray[i] = textboxScore;
    nameArray[i] = textboxName;
    echo nameArray[i] + " received" + myArray[i] + " on the test."
    }



    You can post your fla file in MX format not MX2004 and I could help you out a little more with it.
    yup.

  5. #5
    Junior Member
    Join Date
    Sep 2004
    Location
    Osaka, Japan
    Posts
    27
    thanks again buckwheat!

    I'll be at work teaching the rest of this week but I'll work on the array using what you posted here on Thursday Japan time which is Wednesday your time.

    If I can get it to work I'll let you know. If not, well....I'll let you know. Talk to you in about 4 days

    Challenged

  6. #6
    Junior Member
    Join Date
    Sep 2004
    Location
    Osaka, Japan
    Posts
    27
    Hi buckwheat,

    I thought about your solution and the array looks like the way to go but wouldn't populating this array overwrite the information that is already populated there?

    I want to keep all the information already there and add new information.

    I think there is a method called "push" that would allow that but I don't know how to use it.

    Challenged

  7. #7
    Gods cower, women quiver. Buckwheat469's Avatar
    Join Date
    Dec 2003
    Location
    Uranus
    Posts
    247
    This is a bit beyond my programming. As far as I know, an array in Flash is completely erased as soon as the user closes the Flash movie. So basically you would populate the array with whatever scores or values you want, but then if the user closes IE then the values erase and the array returns to undefined. Flash is not a very useful storage means for data. You can use an xml or text file to populate the array but using Flash to process the array might be too difficult.

    I would set it up like this:
    - Create a text file with the questions for the "test"
    - Create another text file with the answers but protect this file by putting it in an obscure location and changing the permissions on it (if you can)
    -Use Flash to read the variables in the text file and populate a questionArray and an answerArray
    -When the user is done answering questions have them click a submit button that sends their score to a php file using a POST or GET return. http://something.com/test.php?user=jdoe&score=100 (get). Using a POST is more secure, then a user can't cheat and send the wrong score.
    -Use the PHP file to post the data to a database or another file.

    The problem is that if the person messes up on the test they can always right-click on the movie and rewind it back to the start and try again.
    yup.

  8. #8
    Junior Member
    Join Date
    Sep 2004
    Location
    Osaka, Japan
    Posts
    27
    Thank you for your help buckwheat! I really appreciate all that you have suggested and done.

    Unfortunately I am looking for a way to use a solution that I know can be done easily as I'm halfway there. I am using shared objects as you know, and they are a fantastic way to save information. FlashMX devised this method because so many developers wanted to save information and it works very very well because it's well thought out, entensible and saves directly to the hard drive.

    I just needed information on how to use it in an array with the inclusion of a PUSH. I will have to try again.

    Thanks again,
    Challenged

  9. #9
    Junior Member scudsucker's Avatar
    Join Date
    Feb 2003
    Location
    Cape Town, RSA
    Posts
    1,509
    Straight from Flash help:
    code:

    var items_array:Array = new Array(101, 346, 483);
    var currentUserIsAdmin:Boolean = true;
    var currentUserName:String = "Ramona";

    var my_so:SharedObject = SharedObject.getLocal("superfoo");
    my_so.data.itemNumbers = items_array;
    my_so.data.adminPrivileges = currentUserIsAdmin;
    my_so.data.userName = currentUserName;

    for (var prop in my_so.data) {
    trace(prop+": "+my_so.data[prop]);
    }
    // returns:
    // userName: Ramona
    // adminPrivileges: true
    // itemNumbers: 101,346,483


    Note- this is AS2. To conver to Actionscript 1, change all variables that look like this:
    code:

    var currentUserIsAdmin:Boolean = true;


    to this
    code:

    var currentUserIsAdmin = true;

    Hariyemadzisawira nhaka yedu! Down the SCUD and win!
    I'm too lazy to read Private Messages.

  10. #10
    Junior Member
    Join Date
    Sep 2004
    Location
    Osaka, Japan
    Posts
    27
    Thanks scud,
    I went with shared objects and they work just fine!
    Cheers,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center