1 Reply Latest reply on Apr 9, 2008 11:14 PM by Santanu Karar

    Screen Capture

    jamestparker Level 1
      I had made a App with flash and zinc that allows me to load a external swf from Hard drive or a network. Then I am able to take a screen Capture of the loaded swf, and I am able to save it as a png or jpeg (etc). Is AIR able to do the same thing?

      below is my code for the Flash/Zinc App I speak of

      stop();
      function wait() {// a function called 'wait'
      clearInterval(myTimer);//stops the function being called again.
      takeSnapshot();
      trace("take snap in clear");
      }
      function myTimer2() {
      setInterval(wait2,5000);
      }
      function wait2() {// a function called 'wait'
      clearInterval(myTimer);//stops the function being called again.
      }


      draggable_mc._visible = false;
      square_mc._x = square_mc._y=0;
      square_mc.beginFill(0xFFFFFF);
      square_mc.moveTo(0,0);
      square_mc.lineTo(1024,0);
      square_mc.lineTo(1024,768);
      square_mc.lineTo(0,768);
      square_mc.lineTo(0,0);
      square_mc.endFill();
      //Enables you to load your own SWF into the application
      function loadCustom() {
      //mdm.Dialogs.BrowseFile.filterList = "SWF Files|*.swf";
      //mdm.Dialogs.BrowseFileUnicode.defaultExtension = ".png";
      mdm.Dialogs.BrowseFile.title = "Open a File";
      var filePath = mdm.Dialogs.BrowseFile.show();
      if (filePath != "false" && filePath != undefined) {
      showPath(filePath);
      unloadSWF();
      loadExternalMovie(filePath);
      }
      }
      // main function to load external movie:
      function loadExternalMovie(filePath) {
      unloadSWF();
      showPath(filePath);
      var holder:MovieClip = box.createEmptyMovieClip("holder", 0);
      holder._lockroot = true;
      holder.loadMovie(filePath);
      }
      //
      function unloadSWF() {
      // if movie is already loaded unload it then
      // remove holding movie clip from box
      if (box.holder) {
      box.holder.unloadMovie();
      box.holder.removeMovieClip();
      box._xscale = box._yscale=100;
      showPath("");
      }
      }
      //Displays SWF location information
      function showPath(filePath) {
      info.text = filePath;
      //wait2();
      }
      //Assigns functions to the buttons
      loadC.onRelease = function() {
      loadCustom();
      };
      //Call Me Function...delay
      function takeSnapshot() {

      mdm.Dialogs.BrowseFile.title = "Save picture";
      mdm.Dialogs.BrowseFile.buttonText = "Save";
      //mdm.Dialogs.BrowseFile.defaultFilename = "myImage.jpg";

      var filePath = mdm.Dialogs.BrowseFile.show();
      if (filePath == "false") {
      // do nothing if the user presses cancel
      } else {
      //Run The Rest after a .25 second gap...
      intervalOne = setInterval(takeSnapshot2,250,filePath);
      }
      }
      //Function called after delay, which takes the actual screenshot
      function takeSnapshot2(filepath) {
      trace("take snap");
      //stop calling this function
      clearInterval(intervalOne);
      var xLoc:String = "6";
      var yLoc:String = "70";
      var width:String = "800";
      var height:String = "600";
      if (filePath == "false") {
      // do nothing if the user presses cancel
      } else {
      //Checks to see correct extension has been used
      var fileExtension = filePath.substr(-4).toLowerCase();
      if (fileExtension == ".bmp" || fileExtension == ".png") {
      if (fileExtension == ".bmp") {
      mdm.Image.ScreenCapture.movieAreaToBmpAlt(6,70,800,600,filePath);
      //Enables the user to view their image using the default image viewing program
      mdm.FileSystem.deleteFile(bmp_file); //Delete the bmp file

      var Result = mdm.Dialogs.promptModal("View your newly captured image?", "yesno", "confirm");
      if (Result == true) {
      mdm.System.exec(filePath);
      } else {
      // Do nothing if user selects "no"
      }
      } else {
      mdm.Image.ScreenCapture.movieAreaToBmpAlt(6,70,800,600,filePath);
      mdm.Image.bmpToPng(filePath,filePath,false,"white");
      mdm.FileSystem.deleteFile(bmp_file); //Delete the bmp file
      //Enables the user to view their image using the default image viewing program
      var Result = mdm.Dialogs.promptModal("View your newly captured image? P.S. If you want to see the transparency use Fireworks.", "yesno", "confirm");
      if (Result == true) {
      mdm.System.exec(filePath);

      } else {
      // Do nothing
      }
      }
      } else {
      mdm.Dialogs.prompt("Please ensure you input the correct file extension. See help for details.");
      }
      }
      }
      function showHelp() {
      gotoAndPlay(2);
      }
      function hideHelp() {
      gotoAndPlay(1);
      }
      ts_btn.onRelease = function() {
      takeSnapshot();
      };
      draggable_mc.submit_mc.onRelease = function() {
      col = new Color(square_mc);
      james = "0x"+draggable_mc.txt_col;
      col.setRGB(james);
      };
      bg_btn.onRelease = function() {
      draggable_mc._visible = true;
      };
      draggable_mc.close_mc.onRelease = function() {
      draggable_mc._visible = false;
      };
      draggable_mc.bar.onPress = function() {
      this._parent.startDrag(false,0,0,1024-this._width,768-this._parent._height);
      };
      draggable_mc.bar.onRelease = stopDrag;
      draggable_mc.bar.onReleaseOutside = stopDrag;