0 Replies Latest reply on Oct 13, 2009 2:36 PM by Tony Heagren

    Count items in an string...

    Tony Heagren Level 1

      Hi all,


      I've got myself intot a complete confusion with a site I'm building with Flash and php.

      I cannot for the life of me get php to do what I want so I'm turning to Flash for the answer !


      I'm working in Flash 8 so AS2 is my limit.


      So the problem starts with a VERY simple string in a txt file that looks like this:

      images/1.jpg,images/2.jpg,images/3.jpg  etc etc


      This is imported into flash (on Level 6) and flash displays the images one by one.

      So far so simple. But to make the gallery loop I use a variable in called "allpics" so when the gallery

      reaches that number it defaults to the first picture again. So far so simple...

      When I had a fixed number of images all was well becaue I could just append that number on the end of the string in the

      txt file using php as "&totalimgs=100"   and flash would merrily translate "totalimgs" into "allpics". (see line 3 of the code).

      But now that users can upload pictures the number is constantly growing and because of the way I've built the php

      upload file I can't (reliably) set that variable anymore.

      So what I need instead is a way of counting the items in the string thats imported from the txt file. If I can count

      the commas maybe, or the occurance of "jpg" I can set a number for "allpics" and the gallery will loop.

      Code I'm using in flash (so far) is below   (can't find the "insert code" button so I'm pasting....where is that button)?

      On line 3 Flash used to read the variable "totalimgs" from php but that's no longer available.


      Really hope someone can help with this - thanks in advance



      import mx.data.components.DataHolder;
      piclist = _level6.imglist;
      allpics = _level6.totalimgs;
      photos = piclist.split(",");
      howmany = allpics;



          var loadListener:Object = new Object();
          loadListener.onLoadInit = function(mc:MovieClip) {
              mc._x = (Stage.width/2)-(mc._width/2);
              mc._y = (Stage.height/2)-(mc._height/2-12);
          var mcLoader:MovieClipLoader = new MovieClipLoader();
          var nextPhoto:String = photos[num];
          var photoHolder:MovieClip = _root.createEmptyMovieClip("photoHolder", 1);
          mcLoader.loadClip(nextPhoto, photoHolder);
          num = ++num;
          setProperty("LB", _alpha, "40");
          _root.LB.enabled = 0;
          setProperty("_root.backB", _visible, "0");