25 Replies Latest reply on Feb 12, 2009 2:17 PM by GumpsterF

    Array to Array

    GumpsterF
      Hi.
      I have a .fla where I am brining in 4 text sharedObject(s) from another .fla. I have made an array of this incoming information in the receiveing .fla. I want the incoming array text to populate 4 text fields in the receiving file, but I want the text fields to ignore blank or "undefinded" information. So if only 2 shared objects show up in the receiving array it is to ignore the blank ones and populate the first two text fields with information. I have made an array of the 4 receiving text fields. I would like an idea of 1. how to ignore a Shared Object var instance that does not receive and information and 2. how to populate a text field array with information form a text array. Here is the code I have that is not working. Any guidance would be greatly appreciated.


        • 1. Re: Array to Array
          clbeech Level 3
          the items stored in the picArray are not textFields - so you should be able to use the string (assuming the myLoginDataX is a string) without the 'text' property which a property of textfields.

          to restrict the filed info when no information is present, you can use a condition to check for undefined values.

          so more like:
          • 2. Re: Array to Array
            GumpsterF Level 1
            hi clbeech, yes you and I were close to the same solution I think. I was using;

            • 3. Re: Array to Array
              GumpsterF Level 1
              But your code works much better as it parses out the "undefined" string in the text field when it runs.

              The only thing I was hoping to to as well was to populate the 1st text field in the string with the 1st bit of data and then the 2nd field with the 2nd bit of data.

              How would I adjust your code to accomplish that? As it sits now, if there is no info for the 1st text field it remains blank, if there is some data for the 2nd it populates that, none for the 3rd it is blank.

              I can send you my sender and receiver fla's if you like. They are pretty simple. I am trying to understand this so I can apply it to something way more complex. Here is my current code;


              • 4. Re: Array to Array
                clbeech Level 3
                hey there :) very good - however you don't need the second half of the condition there, since that will place the set out of order, and it may get overwritten on the next iteration of the loop. better to just no put anything in the field - or even 'undefined' perhaps - if you want to create a list of them though you might want to use a 'single' textField and concatenate the strings on separate lines.
                • 5. Re: Array to Array
                  GumpsterF Level 1
                  Thanks, I thought of the single text field, but it is not an option. I am going to have a bunch or separate dynamic text fields in a fla, that I need to populate with incoming SharedObject text strings. I need them populated in the order in which they are received, so when the receiver fla is run, there are no blank or undefined fields.

                  Here is the page I am going to try and populate so you can see what I mean. This form was done in Flash, not HTML.
                  http://www.nothingofnote.com/contact/contact.html
                  The item # field is what I want to bring in from Flash buttons on other pages.


                  null
                  • 6. Re: Array to Array
                    GumpsterF Level 1
                    maybe weed them out before they hit the array?
                    • 7. Re: Array to Array
                      clbeech Level 3
                      i see - so the idea here is that they can navigate between pages and when they return they still have the information they put into each field right? or maybe not quite... but something similar. you know what i might do here is use a 'single' array in the SO - yes an SO can store an array - so you could just push in new info and then when it's pulled back out, there wont be any 'blanks' or undefined at all, only the number of elelments in the array, you also then on need 'one' SO data object, and no picArray - just iterate out of the SO directly, something like this:
                      • 8. Re: Array to Array
                        GumpsterF Level 1
                        ok, I see what you are getting at. But maybe it is early here and I have not had enough coffee yet, but.... Is that code to be placed in the receiving fla or the sending fla? Or both?

                        My goal is to have several movies, (maybe 100), feed the same SO array. So if this is the sending code, which it kinda looks like, can it be the same in every (say 100) sending fla's?
                        • 9. Re: Array to Array
                          clbeech Level 3
                          ok - i think i see where you're going - and yes, you can use the same code in all movies - in fact you could easily make this into a class file and just import it for each new movie you make as a 'DataHandler' class or something like that - then you don't *have* to call setData or getData if you don't need to, but it's available as a method of the class - like MC for instance- we don't always use the 'lineGradientStyle()' method or the 'opaqueBackground' property but they are available none-the-less.

                          but every time the class is instantiated you should call the init() method maybe from the constructor, it checks to see if any data has been stored - if *not* it makes a new array in the SO, if *so* then it sets the local array (ie. info) to whatever is currently in the SO.

                          you'd also want to set up methods to handle things like, clear out the data, maybe store the last time the user was there, and stuff like that - but if you package it all in a class - you only have to import it into each swf and then you can call methods of the class once you instantiate the constructor (eg. var data = new DataHandler(); )

                          • 10. Re: Array to Array
                            GumpsterF Level 1
                            Good idea clbeech. A little beyond my abilities at the moment. I have yet to create classes.
                            I have created what I have so far by scouring the net for code snippets and reading all the action script 2 books we have here. I have actually learned as3 first and am now trying to learn as2. Kinda backwards I know.

                            What I would like to know is, (supposing I am not going to create a class), the code you posted two posts ago, is that code that goes into the movie where the information is being sent? Or is this code for the receiver?

                            To me, it kinda looks like ;

                            var so:SharedObject = SharedObject.getLocal('myCookie'. '/');
                            var info:Array = new Array();

                            function initData() {
                            if(so.data.loginData == undefined) {
                            so.data.loginData = info;
                            }else{
                            info = so.data.loginData;
                            }
                            }

                            function setData(newData:*) {
                            info.push(newData);
                            so.data.loginData = info;
                            so.flush();
                            }

                            is for the sending fla., and this;

                            function getData() {
                            for(var i=0; i<info.length; i++) {
                            textBlockArray .text = info;
                            }
                            }

                            is in the receiving fla.

                            Is this correct? If so, how, (or where), do I hook up the sender to a button function like I had originally?
                            • 11. Re: Array to Array
                              GumpsterF Level 1
                              Hi clbeech, OK, I took a stab at it, creating a Data Handler Class.
                              How does this look? I saved it as DataHandler.as



                              • 12. Re: Array to Array
                                clbeech Level 3
                                hey that looks pretty good - now make sure you have this class located in driectory 'com' > subdirectory 'example' if you're going to use the package like that (which is fine) you can also place the file in the Base Class directories in your Flash folder and then utilize it without having the .as file in every folder you create. I'd use a constructor in there though, and call the init() method from within it on every instantiation, this will check the SO and set it up for receiving/sending.

                                previously you asked about 'which' method was for which function - and you are correct, with the exception of the init method, should belong to both, weather you are sending or receiving.

                                not sure about extending the SO class there - may want MC, I'll have to check on that probably be ok - but you may need to import some other base classes.
                                • 13. Re: Array to Array
                                  GumpsterF Level 1
                                  Hi. Ok well I changed the path as you suggested. Now I get this error;
                                  A type identifier is expected after the ':'.
                                  • 14. Re: Array to Array
                                    GumpsterF Level 1
                                    Sorry clbeech. That last reply did not look like I wanted it to. I really dislike the way this forum attaches code to messages. I now get this error in my DataHandler.as "A type identifier is expected after the ':'."
                                    • 15. Re: Array to Array
                                      GumpsterF Level 1
                                      What I tried to say in the 2nd last post was that I still a lot lost in what you are trying to tell me, but I am attempting to figure it out. What about trying something in my original receiver code to delete the undefined information from the array before it gets passed into the textfield array. like;
                                      • 16. Re: Array to Array
                                        clbeech Level 3
                                        yeah - the issue is in the setData(newData:*) < under AS2 we can't use the * symbol which says 'any data type' - i forgot :( so you need to designated a data type for the incoming parameter - i'm assuming String.

                                        also there are a few other issues though - so here's an example that's closer below. to use the class, place it in the same folder as the fla file - once compiled it no longer needs to 'go with' the swf, it'll be part of it. next in the fla code use:

                                        import DataHandler;
                                        var soData = new DataHandler(textBlockArray);

                                        by 'passing' the array within the constructor (which must be defined previous to doing so) you can use 'any' array and 'any' textfield names within each fla - they wont always have to be 'itemtext1', itemtext2', etc. so i set up the loop to reflect this below. now you could remove that 'concept' and go another route, this would be to have the getData method 'return' an array - which you handle in the fla code instead, but if all of you files will basically be the same, then the current set up should be just fine. so here's a revised class code:
                                        • 17. Re: Array to Array
                                          GumpsterF Level 1
                                          hi clbeech.
                                          after a couple of days of trying to make this all work, I must ask for your sage advice once again. I know I am close, but I am not quite understanding the concept yet. I saved the .as file as you suggested and when run it seems no be error free. I applied that to both my sender and receiver fla's. When I have two send buttons in a sender fla, the second string seems to overwrite the first string when I trace it. My receiver fla does not error but no information is coming in. Attached is the code I have for both receiver and sender fla's.

                                          • 18. Re: Array to Array
                                            dmenn Level 1
                                            >> you can also place the file in the Base Class directories in your Flash folder and then utilize it without having the .as file in every folder you create.
                                            <<

                                            clbeech, this is not recommended... the class is not part of the Flash classes and should go in a package like he had. There's no need to place it in every folder/fla created unless he doesn't use the package identifier... Using the package name like: class com.example.DataHandler lets you just instance it whenever you need:
                                            var myHandler = new com.example.DataHandler(); no need to ever copy it elsewhere.

                                            • 19. Re: Array to Array
                                              clbeech Level 3
                                              alrighty ;) I've had a chance to review this, here's the issue. you are not using the methods defined in the class to accomplish the goals in the receiver or sender. part of the reason of defining these methods within the class is so that you can access them and use them without have to rewrite them each time. in the files, you are treating the class instance as though it were a SO object and calling methods like 'flush()' and 'clear()' - these aren't methods of the DataHandler class - they are methods of the SO class. Within the DataHandler class we've created the mechanism needed to handle the SO for you, so what you need to do is call those methods from the files to use them.

                                              But i did make a few changes to the DataHandler class, first I took the constructor parameter out, since i see now that you don't need that in both files, and one issue was that the array wasn't being defined previous to the constructor, so it was null. instead, pass the array as a parameter in the 'getData' method, to iterate through any amount of fields that you may have on stage. and now do *not* pass anything in the constructor.

                                              I've also added a 'removeData' method to the class, because it appears as though you want to be able to remove 'specific' data from the cart (is that right?) if so, you need to call the new method (eg. removeData) and pass the string of the data that is being removed, so this can then be used to 'find' that data in the stored array and remove 'just that' piece of data. currently, the class method 'clearData' will move *all* data from the array, and i don't think that's what you are wanting to do.

                                              so here is the updated class code, and a revised version of the file codes for you to check out, I've also included some trace statements in the class code so that you can see what's happening when you implement one of the methods, you weren't getting outputs before because there was no data of that type within the class:
                                              • 20. Re: Array to Array
                                                clbeech Level 3
                                                dmenn - not correct.

                                                "clbeech, this is not recommended... the class is not part of the Flash classes and should go in a package like he had."

                                                - in fact this is a recommended method of filing your classes right out of the documentation and examples. because the compiler first looks in the local directory for class/package files, if none are found it will then searches any specified class paths assigned to the file (see your publish setting and click on the 'settings' button next to the ActionScript verions combobox, under the Flash tab - if you don't know what class paths are), if none are found there it then reviews the base directories, where you certainly can store commonly used class that you create.

                                                "There's no need to place it in every folder/fla created unless he doesn't use the package identifier... Using the package name like: class com.example.DataHandler lets you just instance it whenever you need:
                                                var myHandler = new com.example.DataHandler(); no need to ever copy it elsewhere."


                                                - even if you place it with a package structure - which is purely for organization - you will still need to have those package directories local to each document - UNLESS - you point to that package location with a class path declaration (as specified above) - so tell me why would one place a single .as file within two directories deep? what is the point there?

                                                you are incorrect, in most regards.
                                                • 21. Re: Array to Array
                                                  GumpsterF Level 1
                                                  Hi clbeech. As to the matter of where to keep the DataHandler.as file. I will try what you suggest after I (we) get this code to work. For now it is just easier to keep it in the same working folder. As to the adjusted code, I am very grateful for your explanation and comments in the code, I understand now what you are trying to tell me. I have played with your code for a day and still cannot seem to get it to work quite right.

                                                  When I open my sender fla and run it the first time, this is the output message I get after pressing both loadButtons;

                                                  found local data:
                                                  _level0.item_0001,_level0.item_0002
                                                  set new data: item # 2557
                                                  currently stored data: item # 2557
                                                  set new data: item # 1552
                                                  currently stored data: item # 2557,item # 1552

                                                  If I then close the swf and run it a second time, this is the output message I get after pressing both loadButtons;

                                                  no local data
                                                  _level0.item_0001,_level0.item_0002
                                                  set new data: item # 2557
                                                  currently stored data: undefined
                                                  set new data: item # 1552
                                                  currently stored data: undefined

                                                  When I open my receiver fla and run it after closing the 1st sender swf run attempt, no text is displayed in the text fields and the receiver fla output message just says;

                                                  no local data

                                                  When I open my receiver fla and run it after closing the 2nd sender swf run attempt, no text is displayed in the text fields and the receiver fla output message just says;

                                                  found local data

                                                  So it seems to me that somehow the stored daa is being deleted automatically somehow and the receiver fla is not finding anything to display. I want to be able to control the clearing of fields with buttons on both the receiver and sender, plus I am going to have a "send" button that will send a bunch of information to a mail.php file including the infor received in these text fields. I will set up that "send" button to clear all stored information, everywhere, if possible.
                                                  I am going to send you four files via email clbeech so you can see what is happening for yourself. The gathered_item.fla, Saved Item.fla, and the DataHandler.as are the files I have been using during this tutelage. The fourth is going to be my eventual "receiver" fla. The file is called "les_mail_2.fla". I thought you might like to see where I was going with all this eventually. I know the code in there is a little scary as I am not used to making arrays. lol
                                                  • 22. Re: Array to Array
                                                    GumpsterF Level 1
                                                    clbeech, seems I cannot attach files to a private message, so if you would like the files let me know how I may get them to you.
                                                    • 23. Re: Array to Array
                                                      GumpsterF Level 1
                                                      Hi clbeech. Was my question too involved or make no sense?
                                                      I would love for you to look at the two files, you would probably see that problem right off.
                                                      I am at a loss. sorry
                                                      • 24. Re: Array to Array
                                                        GumpsterF Level 1
                                                        Hi clbeech. I hope you are still with me.
                                                        I have implemented your code and when I trace the soData in the sender and the receiver fla's, I get the result [object Object]. I tried tracing soData.text, but it then says undefined. I am at a loss as to why. I have spent a week changing this and that in the DataHandler.as and both the receiver and sender. Any ideas?
                                                        Forrest
                                                        • 25. Re: Array to Array
                                                          GumpsterF Level 1
                                                          Hi. I even dumbed it down and tried this...., but still got [object Object] with the trace.