Sections
You are here: Home Forum Flash Chart/Gauge Scripts?

Chart/Gauge Scripts?

Up to Flash

Chart/Gauge Scripts?

Posted by Andrew Galewsky at March 15. 2008

I have succesfully build some temp. probes and gotten them interfaced via flash. However, not being a truly experienced flash dude I was wondering if anybody could point me to some flash scripts that would allow me to make simple strip charts and/or guages...

Preferably free :)

Re: Chart/Gauge Scripts?

Posted by Philip Forget at June 20. 2008
Here is a simple flash class that displays any signal coming from the board as a needle on a dial. You just have to change the variables for your setup. Should help you be on your way.

You will need to turn on autosend: http://makingthings.com/documentation/how-to/configure-autosend

This will avoid having to send messages to the board requesting values.

[code]
package 
{
    import com.makingthings.makecontroller.*;
    import flash.display.Sprite;
    import flash.events.*;
   
    public class SimpleGauge extends Sprite
    {
        private var needle:Sprite;
        private var mcConnect:McFlashConnect;
       
            //    the min and max values from your sensor
        private static const minPosition:int = 0;
        private static const maxPosition:int = 1023;
            //    the port to listen for the signal on
        private static const analogIn:uint = 0;
       
        public function SimpleGauge()
        {
                //    draw a simple gray circle centered
            graphics.beginFill(0x000000, .25);
            graphics.drawCircle(200, 200, 200);
           
                // create the needle sprite and draw a 150 pixel line away from it's center
            needle = new Sprite();
            needle.graphics.moveTo(0, -150);
            needle.graphics.lineStyle(2, 0xFF0000);
            needle.graphics.lineTo(0, 0);
           
                //    center the needle on stage and add it
            needle.x = 200;
            needle.y = 200;
           
            addChild(needle);
           
                // create the mchelper connection and tell it to listen for boards
            mcConnect = new McFlashConnect();
            mcConnect.addEventListener(McEvent.ON_MESSAGE_IN, messageInListener);
            mcConnect.connect();
        }
       
            //    listen as messages come in
        private function messageInListener(e:McEvent):void
        {
                //    assign the message to a new OscMessage Object
            var oscMessage:OscMessage = e.data;
            if (oscMessage.address == '/analogin/' + analogIn + '/value')
            {
                    //    calculate the percentage of the current message based on the max and min constants
                var currentPercentage:Number = (oscMessage.args[0] / (maxPosition - minPosition));
                    //    set the needle position
                needle.rotation = 360 * currentPercentage;
            }
               
        }
    }
   
}
[/code]

Let me know if you have any questions,


Philip
Powered by Ploneboard
Document Actions