5 Replies Latest reply on Jun 26, 2015 8:32 AM by lolly_slippen

    Scaling Movieclip according to the input from sensor

    lolly_slippen

      Hi there,

       

      I am new to adobe flash community and new on using the flash language, so pardon me about it.

       

      I am currently trying to send data from the pressure sensor through Arduino and display it on flash.

      Don't worry about the sensor and Arduino side of it since I have done the coding and communication part of it to flash, now I am trying to do is when the user press the sensor to have the circle ball [movieclip] to scale and expand the size according to the amount of pressure input from the sensor.

       

      Below is the code I have done so far for the scaling and hopefully is on track, I use the width and height to adjust the size however I received an error that said "call to possibly undefined method CircleGreen".

      Any ideas on what to do is greatly appreciate it , I will play around and let you know if I fix my problem.

       

      Thank you

      var circleGreen = new CircleGreen();

       

      a.addEventListener(ArduinoEvent.ANALOG_DATA, onTickk);

       

      function onTickk(e:ArduinoEvent):void{

       

        var feetValue:int;

        feetValue = a.getAnalogData(0);  //to get the data from the sensor

       

        circleGreen.x = -circleGreen.width / 2 + 312;

         circleGreen.y = -circleGreen.height / 2 + 188;

       

        circleGreen.width = feetValue / 40 ;

        circleGreen.height = feetValue / 40 ;

       

        addChild(circleGreen);

       

      }

        • 1. Re: Scaling Movieclip according to the input from sensor
          lolly_slippen Level 1

          I've changed the variable

          var circleGreen = new MovieClip();

          the error for "possibly undefined method CircleGreen" has disappeared but nothing happens, the circle is not resizing, although there are no error displayed. I assume is my logic of the coding is wrong. I will fiddle around more in the hope of finding solution soon.

          • 2. Re: Scaling Movieclip according to the input from sensor
            funkysoul Level 4

            Maybe something like this?

            Assuming that you don't have any movieclip on the stage with the name circleGreen, I just drew it with AS3

            var circleGreen:Sprite;
            
            function init():void{
                 circleGreen = new Sprite();
                 circleGreen.graphics.beginFill(0x00FF00, 1);
                 circleGreen.graphics.drawCircle(stage.stageWidth / 2, stage.stageHeight / 2,100);
                 circleGreen.graphics.endFill();
                 addChild(circleGreen);
                 
                 a.addEventListener(ArduinoEvent.ANALOG_DATA, onTickk);     
            }
            
            init();
            
            function onTickk(e:ArduinoEvent):void{
            
              var feetValue:int;
              feetValue = a.getAnalogData(0);  //to get the data from the sensor
            
            //since i don't know what range of values the arduino sensor ouputs, the normalized output should always be between 0 and 1 so you can safely multiply the normalized value with something that fits better.
              circleGreen.scaleX = circleGreen.scaleY = normalize(feetValue) * 4;
            }
            
            function normalize(value:Number) {
                 var normalized:Number = (value - 0)/(1 - 0)
                  return normalized;
            }
            
            • 3. Re: Scaling Movieclip according to the input from sensor
              lolly_slippen Level 1

              Hi FunkySoul,

               

               

              Thanks for replying, I've noticed that you put "stage" in the code, is it necessary to put import.flash.display.stage?

              The arduino sensor analog output has an acceptable range between 0 to 255.

               

              I've tested the code and when I played in SWF, the circle ball appeared for less then a second and then it disappears.

              • 4. Re: Scaling Movieclip according to the input from sensor
                funkysoul Level 4

                yes the stage needs to be imported, but you can also replace stage.stageWidth and stage.stageHeight with any number you want.

                Regarding the value simply change line 25 to this:

                var normalized:Number = (value - 0)/(255 - 0);


                Yes it makes sense that you only see the circle for less than a second, as it's immediately waiting for user input from the sensor. as soon as you have normalized your sensor values, things should start to look again.

                • 5. Re: Scaling Movieclip according to the input from sensor
                  lolly_slippen Level 1

                  cool, will tried out after I get back from work in few hours. Thanks a lot funkysoul, will update again in few hours.