10 Replies Latest reply on Jul 3, 2007 2:02 AM by Newsgroup_User

    Reading Data : LoadVars

    Level 7
      I want to read data from several files whose names are written in array

      then I want to get an array with names of those file whose content length is
      more than 1000.

      I have done looping and able to get data of files and check their length but
      not able to store the file name.
      this is happing probably becoz onLoad of loadvars is not gtting called in
      loop sequentilayy so that i can get the file name there itself , but onLoad
      is getting called one by one after the loop finishs .here the file name is
      lost.

      How to do !!!!!!!!!!!!!!!!!!11


        • 1. Re: Reading Data : LoadVars
          Greg Dove Level 4
          Whether you attempt it simultaneously or sequentially, I believe one way to do it would be to make sure the LoadVars instance has a reference to the file name before you call the load method. That way, the filename is accessible from the LoadVars instance inside the onLoad handler.

          I haven't tried this, so please let me know if it works/helps.
          • 2. Re: Reading Data : LoadVars
            Level 7
            Thanks I was thinking on same idea.It worked.
            I want to populate a list box inside the handleThisLv() but it is not doing
            so .any idea !!



            "GWD" <webforumsuser@macromedia.com> wrote in message
            news:f65ji0$20d$1@forums.macromedia.com...
            > Whether you attempt it simultaneously or sequentially, I believe one way
            > to do
            > it would be to make sure the LoadVars instance has a reference to the file
            > name
            > before you call the load method. That way, the filename is accessible from
            > the
            > LoadVars instance inside the onLoad handler.
            >
            > I haven't tried this, so please let me know if it works/helps.
            >
            > //EXAMPLE ONLY for sequentially named text files.
            > //I haven't tried this but its how I would attempt it.
            > //Please let me know if this type of approach works.
            >
            > function handleThisLv(success:Boolean, LV:LoadVars) {
            >
            > if (success) {
            > trace('loaded '+LV.fileName);
            > //do whatever e.g. check content is greater than 1000 chars
            > if (LV.content.length>1000) {
            > //do something
            > }
            > } else {
            > trace('failed to load '+LV.fileName);
            > }
            > }
            >
            > for (var i = 1; i<1001; i++) {
            > var nextToLoad = "textfile"+i+".txt";
            > var newLV:LoadVars = new LoadVars();
            > newLV.fileName = nextToLoad;
            > // this means that the latest LoadVars knows its source filename
            > newLV.onLoad = function(success:Boolean) {
            > handleThisLv(success,this);
            >
            > };
            > newLV.load(nextToLoad);
            > }
            >


            • 3. Re: Reading Data : LoadVars
              Level 7
              Can I trace when the last loadvar .onLoad inside the loop
              finished.!!!!!!!!!!!






              "GWD" <webforumsuser@macromedia.com> wrote in message
              news:f65ji0$20d$1@forums.macromedia.com...
              > Whether you attempt it simultaneously or sequentially, I believe one way
              > to do
              > it would be to make sure the LoadVars instance has a reference to the file
              > name
              > before you call the load method. That way, the filename is accessible from
              > the
              > LoadVars instance inside the onLoad handler.
              >
              > I haven't tried this, so please let me know if it works/helps.
              >
              > //EXAMPLE ONLY for sequentially named text files.
              > //I haven't tried this but its how I would attempt it.
              > //Please let me know if this type of approach works.
              >
              > function handleThisLv(success:Boolean, LV:LoadVars) {
              >
              > if (success) {
              > trace('loaded '+LV.fileName);
              > //do whatever e.g. check content is greater than 1000 chars
              > if (LV.content.length>1000) {
              > //do something
              > }
              > } else {
              > trace('failed to load '+LV.fileName);
              > }
              > }
              >
              > for (var i = 1; i<1001; i++) {
              > var nextToLoad = "textfile"+i+".txt";
              > var newLV:LoadVars = new LoadVars();
              > newLV.fileName = nextToLoad;
              > // this means that the latest LoadVars knows its source filename
              > newLV.onLoad = function(success:Boolean) {
              > handleThisLv(success,this);
              >
              > };
              > newLV.load(nextToLoad);
              > }
              >


              • 4. Re: Reading Data : LoadVars
                Greg Dove Level 4
                quote:

                Originally posted by: Newsgroup User
                Thanks I was thinking on same idea.It worked.
                I want to populate a list box inside the handleThisLv() but it is not doing
                so .any idea !!



                So long as the listbox is on the same timeline/frame as the code, you should be able to use the listbox's addItem method inside handleThisLv for the items you want to add.
                • 5. Re: Reading Data : LoadVars
                  Greg Dove Level 4
                  quote:

                  Originally posted by: Newsgroup User
                  Can I trace when the last loadvar .onLoad inside the loop
                  finished.!!!!!!!!!!!


                  Yes... I guess you could do it like this:
                  • 6. Re: Reading Data : LoadVars
                    Level 7
                    I had the same idea but i cannot hardcode the value like if
                    (LV.loadIndex==1000) .the newLV.load(nextToLoad); is called in a loop where
                    some condition are checked and then newLV.load called so not able to assign
                    value of loop to lv.

                    2) the list box is on same time line and i am using
                    this.list_combo.addItem({label:"Label", data:"data"});
                    to populate list component.
                    I know it is correct , i debugged too but still not adding items to combo.Is
                    there some timing related issues with lv and list.

                    any idea .

                    Thanks


                    > Yes... I guess you could do it like this:
                    >
                    >
                    > function handleThisLv(success:Boolean, LV:LoadVars) {
                    >
                    > if (success) {
                    > trace('loaded '+LV.fileName);
                    > //do whatever e.g. check content is greater than 1000 chars
                    > if (LV.content.length>1000) {
                    > //do something
                    > }
                    > if (LV.loadIndex==1000) { //or whatever the last number is
                    > trace("last one has loaded")
                    >
                    > }
                    > } else {
                    > trace('failed to load '+LV.fileName);
                    > }
                    > }
                    >
                    > for (var i = 1; i<1001; i++) {
                    > var nextToLoad = "textfile"+i+".txt";
                    > var newLV:LoadVars = new LoadVars();
                    > newLV.fileName = nextToLoad;
                    > newLV.loadIndex = i;
                    > // this means that the latest LoadVars knows its source filename
                    > newLV.onLoad = function(success:Boolean) {
                    > handleThisLv(success,this);
                    >
                    > };
                    > newLV.load(nextToLoad);
                    > }
                    >



                    • 7. Re: Reading Data : LoadVars
                      Greg Dove Level 4
                      quote:

                      I had the same idea but i cannot hardcode the value like if
                      (LV.loadIndex==1000) .the newLV.load(nextToLoad); is called in a loop where
                      some condition are checked and then newLV.load called so not able to assign
                      value of loop to lv.


                      OK then... instead of a loadIndex property, just assign a boolean .isLast value to each LoadVars. If its not the last one should always be false. The only one with a true value assigned should be the last one in the LoadVars creation loop.

                      inside the onLoad handler, instead of
                      if (LV.loadIndex==1000)
                      use
                      if (LV.isLast)

                      quote:

                      2) the list box is on same time line and i am using
                      this.list_combo.addItem({label:"Label", data:"data"});
                      to populate list component.
                      I know it is correct , i debugged too but still not adding items to combo.Is
                      there some timing related issues with lv and list.


                      try :
                      list_combo.addItem({label:"Label", data:"data"});
                      instead of :
                      this.list_combo.addItem({label:"Label", data:"data"});

                      If that doesn't work then post your code
                      • 8. Re: Reading Data : LoadVars
                        Level 7
                        let me say first the problem is solved :) .

                        But we even could not use boolean since loadis call in condition if
                        condition false the would not load in that case false val and if condition
                        true then true will be passed to handler function even in first go.!!! so
                        that won't work.

                        Second the list box path dint work if i used relativ path
                        this.pah.list_combo.
                        but worked if used absolute path _root.path.list_combo.. I dont know why
                        but it it is working.


                        "GWD" <webforumsuser@macromedia.com> wrote in message
                        news:f6crko$kle$1@forums.macromedia.com...
                        >
                        quote:

                        I had the same idea but i cannot hardcode the value like if
                        > (LV.loadIndex==1000) .the newLV.load(nextToLoad); is called in a loop
                        > where
                        > some condition are checked and then newLV.load called so not able to
                        > assign
                        > value of loop to lv.

                        >
                        > OK then... instead of a loadIndex property, just assign a boolean .isLast
                        > value to each LoadVars. If its not the last one should always be false.
                        > The
                        > only one with a true value assigned should be the last one in the LoadVars
                        > creation loop.
                        >
                        > inside the onLoad handler, instead of
                        > if (LV.loadIndex==1000)
                        > use
                        > if (LV.isLast)
                        >
                        >
                        quote:

                        2) the list box is on same time line and i am using
                        > this.list_combo.addItem({label:"Label", data:"data"});
                        > to populate list component.
                        > I know it is correct , i debugged too but still not adding items to
                        > combo.Is
                        > there some timing related issues with lv and list.

                        >
                        > try :
                        > list_combo.addItem({label:"Label", data:"data"});
                        > instead of :
                        > this.list_combo.addItem({label:"Label", data:"data"});
                        >
                        > If that doesn't work then post your code
                        >


                        • 9. Re: Reading Data : LoadVars
                          Greg Dove Level 4
                          quote:

                          Second the list box path dint work if i used relativ path
                          this.pah.list_combo.
                          but worked if used absolute path _root.path.list_combo.. I dont know why
                          but it it is working.


                          I'm pretty sure its because inside the onLoad handler 'this' is referring to the LoadVars instance and not the timeline. It should work without 'this' as well. But using _root is another option if that's the level of you list_combo
                          • 10. Re: Reading Data : LoadVars
                            Level 7
                            You were right "this" in function refered to loadvers in context and
                            threfore list component worked if used withut refering this.
                            combo.addItem()
                            and not this.combo.additem()

                            Thanks


                            "GWD" <webforumsuser@macromedia.com> wrote in message
                            news:f6cv42$oam$1@forums.macromedia.com...
                            >
                            quote:

                            Second the list box path dint work if i used relativ path
                            > this.pah.list_combo.
                            > but worked if used absolute path _root.path.list_combo.. I dont know why
                            > but it it is working.

                            >
                            > I'm pretty sure its because inside the onLoad handler 'this' is referring
                            > to
                            > the LoadVars instance and not the timeline. It should work without 'this'
                            > as
                            > well. But using _root is another option if that's the level of you
                            > list_combo
                            >
                            >