3 Replies Latest reply on Jun 3, 2006 3:45 AM by Newsgroup_User

    count number of instances a record appears

    V2JTB Level 1
      I have a move that imports Name, Department and Site from an external CSV file, this part I managed to get working after many weeks. I would like to be able to count the number of instances of a specific Site “Glasgow” appears in the String. This way I know how many lines to set.

      Also can you add Dynamic text to a rollover button? I can get the the text to display on the root but not on a button.

      I am new to programming and Flash so apologies in advance.
        • 1. Re: count number of instances a record appears
          Level 7
          Hi!

          For the counting, you'll need some looping structure with either "for" or
          "while" and you can make use of String.indexOf, so the pseudo would be
          something like
          reset counter
          loop through all elements
          if (Site.indexOf("Glasgow") > -1) then increase counter
          end loop

          When it comes to the dynamic text question, then the answer is that this is
          possible. You are probably facing a problem with scope and targetpaths. The
          dynamic textfield is inside the button, so if the button is placed on the
          root level, then to refer to a variable on the root level, you'll need to
          use _parent.variable and not just variable. (Or if you update the text
          through Textfield.text = "bla, bla, bla", then you need something like
          MyButton.Textfield.text="bla, bla, bla".

          I hope this can be of help, if not then provide some of the code you have
          used which makes it easier to give you some more explicit answers.

          Cheers!

          /Jensen/



          "forumnotifier" <webforumsuser@macromedia.com> wrote in message
          news:e5p5v0$b1i$1@forums.macromedia.com...
          >I have a move that imports Name, Department and Site from an external CSV
          >file,
          > this part I managed to get working after many weeks. I would like to be
          > able
          > to count the number of instances of a specific Site ?Glasgow? appears in
          > the
          > String. This way I know how many lines to set.
          >
          > Also can you add Dynamic text to a rollover button? I can get the the
          > text to
          > display on the root but not on a button.
          >
          > I am new to programming and Flash so apologies in advance.
          >


          • 2. Re: count number of instances a record appears
            V2JTB Level 1
            My code is


            on (rollOver) {
            showPerTime = 20; //it is this number I would like to make = the number Bury or Glasgow
            // ** declare variables and constants **
            var loader = new LoadVars();
            // ** load the file **
            loader.load("BUC.csv");
            // ** functions **
            // use onData because text file is not of the form var=value&...
            loader.onData = function(dat) {
            // split on \r\n for files on windows server
            var input_arr = dat.split('\r\n');
            var fields = input_arr[0].split(',');
            function showDataFrom(a, b) {
            trace("Successful Data Load");
            cEnd = b;
            for (var c = 0; c<fields.length; c++) {
            _root[fields[c]].text = '';
            }
            var z = 0;
            for (var x = a; x<=input_arr.length; x++) {
            var citem = input_arr[x].split(',');
            if (citem[0] == "Bury") {
            if (b>=input_arr.length) {
            } else if (a<=1) {
            }
            for (var y = 0; y<citem.length; y++) {
            _root[fields[y]].text += citem[y]+'\n';
            }
            z++;
            if (z>b) {
            }
            }
            }
            }
            showDataFrom(1, showPerTime);
            };
            }
            on (rollOut) {


            Site.text = " ";
            Department.text = " ";
            BUC_member.text = " ";
            trace(input_arr);
            }
            • 3. Re: count number of instances a record appears
              Level 7
              Hi!

              Ok, so you want to update showPerTime after loading data and before calling
              showDataFrom, correct?
              If so, it is not very clear to me the structure of your data. As far as I
              can see, the information to be used is stored in fields, through this
              operation:
              var fields = input_arr[0].split(',');

              But I have no idea how fields is structured, so I can't really help you with
              the rest of the code. I am also wondering if fields actually contains _all_
              the Names, Departments and Sites, and not just the first one.

              Here is an example of how to structure your data:
              Two dimentional array:
              DataList = [[Name1, Department1, Site1], [Name2, Department2, Site2], ...,
              [NameN, DepartmentN, SiteN]]

              To update showPerTime, you could then do something like:
              showPerTime = 0;
              matchSite = "Glasgow";
              for (var i = 0; i < DataList.length; i++) {
              if (DataList [2] == matchSite) {
              showPetTime++;
              }
              }


              /Jensen/

              "V2JTB" <webforumsuser@macromedia.com> wrote in message
              news:e5ph1i$oor$1@forums.macromedia.com...
              > My code is
              >
              >
              > on (rollOver) {
              > showPerTime = 20; //it is this number I would like to make = the number
              > Bury
              > or Glasgow
              > // ** declare variables and constants **
              > var loader = new LoadVars();
              > // ** load the file **
              > loader.load("BUC.csv");
              > // ** functions **
              > // use onData because text file is not of the form var=value&...
              > loader.onData = function(dat) {
              > // split on \r\n for files on windows server
              > var input_arr = dat.split('\r\n');
              > var fields = input_arr[0].split(',');
              > function showDataFrom(a, b) {
              > trace("Successful Data Load");
              > cEnd = b;
              > for (var c = 0; c<fields.length; c++) {
              > _root[fields[c]].text = '';
              > }
              > var z = 0;
              > for (var x = a; x<=input_arr.length; x++) {
              > var citem = input_arr[x].split(',');
              > if (citem[0] == "Bury") {
              > if (b>=input_arr.length) {
              > } else if (a<=1) {
              > }
              > for (var y = 0; y<citem.length; y++) {
              > _root[fields[y]].text += citem[y]+'\n';
              > }
              > z++;
              > if (z>b) {
              > }
              > }
              > }
              > }
              > showDataFrom(1, showPerTime);
              > };
              > }
              > on (rollOut) {
              >
              >
              > Site.text = " ";
              > Department.text = " ";
              > BUC_member.text = " ";
              > trace(input_arr);
              > }
              >
              >