8 Replies Latest reply on Aug 30, 2007 9:26 AM by oneandonly_mohawke

    Help with a  resource meter.

      I have been creating a lot of live gauges and meters for a web based dashboard, most work great. I am now trying to create a Flash usage meter like the CPU meter in Windows task manager, but cannot seem to get it working. I am fairly new to Flash so I consider myself a newbie so I may be approaching this wrong. I have everything working, but I need the it to scroll right to keep a nice clean history.

      basically what I have now is a movie clip (line) which I move to the right and draw a line to get the value. It works but when I get to the end and it starts back at 0 it is going over the history rather than shifting all lines to the left. This makes for a very cluttered and hard to read histogram. The whole thing is from 0 (left) to 120+ minutes (right) where the actual display area (img_mc) is 175 x 70px.

      I have attached the code if anyone is willing to help or point me in the right direction with this.

      Thank you!
        • 1. Re: Help with a  resource meter.
          FlashForumName Level 1
          You could use an interval. If you're storing the points in say, an array, you can just write over the old data as you no longer need to display it anymore and then tack on the new data. Each interval iteration, update your data in the array, then read the values from your array and just redraw.

          This may cause the lines to disappear briefly on each redraw. If there are not a lot of points, you could instead create a new movieclip for each point and just move them as your interval updates. Destroying them once they reach the end of the viewing area and creating a new one each iteration for the start.
          • 2. Re: Help with a  resource meter.
            oneandonly_mohawke Level 1
            Not sure that would help. I am actually moving it over one and creating a new movie clip each time. When I get to the end of the background it starts at zero and increments up again over writing the previous line. The problem is that it needs to push all the existing lines over one from that point on. Adding a for loop to accomplish that causes Flash to issue a "script running slow warning", or something to that effect. For some reason when I tried using height and width rather than lineto() Flash 8 pro did very strange things that lead to me and a colleague to give up on that approach, which seemed easier to work with since I wouldn't need to keep track of values to draw the lines as well as move them over.

            Is there an easy way to move all the lineto() objects over one all at once? Can I store them in an array as say an object with all the data included or as a new mc or is lineto() a bad way to solve this issue? Like I said, we tried width and height on a movie clip. That just moved things all over stage with very unpredictable results.

            Thanks so much.
            • 3. Re: Help with a  resource meter.
              FlashForumName Level 1
              To start, I would recommend doing it like this: Just use 1 movieclip and use an array to hold the data. You could clear and redraw each time since it would yield the best performance out of the methods we have discussed updating the array each iteration. I assume you are not using a huge amount of points so the redraw should be quite quick.

              If you are sure you want to do it the other way, perhaps something like this. If you used some generic naming method, such as:

              var temp3:MovieClip = _root.createEmptyMovieClip("lineName" + i, _root.getNextHighestDepth());

              You can easily cycle through this later using something like:


              using i in both instances to give each a unique name. This would, of course, remove the objects but you could essentially move or do whatever inside a for loop. Just keep a counter when you create them so you know how many to loop through and you should be fine. As long as there are not too many objects, the flash should not give the warning. That warning happens after 15s (I think) whenever a loop is run constantly. There are ways to deal with it but i do not think you'll have to deal with it unless you are using a ton of objects.

              I would also recommend trying to avoid creating a new object every time unless you are destroying one in turn as this will slowly fill up your memory and degrade your performance. The more movieclips you are adding to draw the lines, the more it's going to hinder your performance.
              • 4. Help with a  resource meter.
                clbeech Level 3
                I think you'd be better off not using the attachMovie method here. Your getting to many MCs on the Stage and you're going to have to track and remove them, it's going to be really slow this way no matter how you do it.

                Here's a drawing API method that doesn't use MC attachement. You will need to modify it some to get the placement you want in your meter, I could help you place it correctly if you post the fla. To run this, make a new doc, and paste this in the first frame, it does not need anything in the Library to run. Here's the code:
                • 5. Help with a  resource meter.
                  Greg Dove Level 4
                  EDIT - just reading back, this is the way 'flashForumName' suggested.

                  I tried to do this using bitmapData for the history... I think it would be nice to get pixel level scrolling happening. But I failed! I haven't done much with bitmaps so I need to spend some time learning that. Here's what I came up with, which I think is close to the style of the windows task manager in terms of the way it works.

                  You can adjust the width and numpoints to change how it appears.

                  • 6. Re: Help with a  resource meter.
                    clbeech Level 3
                    Oh ... I see now, I didn't get the 'scrolling' part when I went and ran the first code, before more recent posts. hmmm....
                    • 7. Re: Help with a  resource meter.
                      clbeech Level 3
                      OK, I've got the BitmapData method. I'd say create this as a separate swf, and load it in. It's based on Stage dimensions, so make a Stage at the size you want it to be, paste the code in the first frame.
                      • 8. Re: Help with a  resource meter.
                        oneandonly_mohawke Level 1
                        Thanks so much for your help on this. A friend and I got this working, I'll attach the code. It seems to work well and doesn't eat resources that I can tell. Let me know what you think.