Search code examples
actionscript-3flashcameraactionscriptfeed

Rotating a camera feed in Actionscript 3


I am trying to rotate a live camera feed 90 degrees so it's the correct orientation. Here is what I have so far but it just won't do anything with the rotation.

      public function setupCamera(param1:int, param2:int) : void
      {
         camera = Camera.getCamera("1");
         camera.addEventListener(StatusEvent.STATUS,camStatusHandler);
         camera.setMode(param1,param2,stage.frameRate);
         video = new Video(param1,param2);
         video.scaleX = -1;
		     video.rotation = 90;
         video.x = video_placement.x + video_placement.width;
         video.y = video_placement.y;
         video.attachCamera(camera);
         addChildAt(video,0);
      }


Solution

  • Most likely, the rotation is working. The problem is when you rotate 90 degrees the registration/anchor point is now effectively the top-right corner (so if it's at position 0,0 the video will appear off-screen making it look like it's not working).

    You can compensate by adding the width of the video to it's position:

    video.x = video.width + video_placement.x;
    

    In the same manner, setting the scale to -1 inverts the registration point, and since you've rotated the object you need to compensate for it on the y plane by adding the height of the video to it's position:

    video.y = video.height + video_placement.y;