Post MacOS Big Sur fail - java.awt.robot.createScreenCapture now only captures desktop - screen-capture

MacOS after installing Big Sur update. Any help on this much appreciated.
Before:
Calling java.awt.robot.createScreenCapture
Results in:
Screenshot of whatever is currently visible
After:
Calling java.awt.robot.createScreenCapture
Results in:
screenshot of desktop
Simple code to test this:
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class ScreenCaptureTest {
public static void main(String[] args) throws IOException, AWTException {
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(new Rectangle(0, 0, 800, 500));
File file = new File("screenCapture.png");
ImageIO.write(image, "png", file);
// Captures part of desktop, not current windows in focus :(
}
}

Have a work-around that does what I need. Takes a screenshot of screens with current focus (and not the Desktop).
May help someone else.
Robot robot = new Robot();
robot.delay(200);
robot.keyPress(KeyEvent.VK_META);
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_3);
robot.keyRelease(KeyEvent.VK_3);
robot.keyRelease(KeyEvent.VK_SHIFT);
robot.keyRelease(KeyEvent.VK_META);
robot.delay(200);
renameCaptureAs(filename);

Related

Using Actionscript 3.0 to play audio from dropbox

Just looking for some advice and hoping someone can point me in the right direction.
I'm trying to create a Flash MP3 player that can play music stored on DropBox. Never used ActionScript before so kind of learning as I go...
From what I've read so far, I need to use URLRequest to get the link to the mp3 file, then use the Sound object to load the file and play it. However, when I test my SWF file I don't get audio. I've also been reading about URLSream and NETstream, but not sure how to use that with the Sound object. I'm not 100% sure if I'm using Sound correctly, and given that this is pretty old technology now, I'm struggling to find decent tutorials.
Here's the code I've been trying:
package {
//Dependencies
import flash.display.MovieClip;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;
import flash.net.URLStream;
import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.media.*;
//Class code
public class soundObject extends MovieClip {
//Variables
var mySong:Sound = new Sound();
//Init Code here
public function soundObject() {
var myRequest:URLRequest = new URLRequest("https://www.dropbox.com/s/[dropboxurl]/T-U-R-T-L-E%20POWER.mp3?dl=0")
mySong.load(myRequest);
mySong.addEventListener(Event.COMPLETE, onSoundLoad);
}
private function onSoundLoad(e:Event): void
{
mySong.play();
}
}
}
So I figured it out guys... and surprise, surprise, it was something rather simple.
In publish settings, I had it set to 'local only'. When I changed this 'network only' the link started to magically work.
Thanks for the help. Got there in the end :D
EDIT: And just in case, I did also have change ?dl=0 to ?dl=1

StageWebView in an AS3-Script

I allreday read a lot of helpful stuff in that forum. Now it's my first time I ask for specific help.
I'm pretty new to Flash and have a problem I struggle for more then a week now. The most efficient and elegant way for my problem is to put a StageWebView-Call into an as-File.
That would be the plan:
In my flash-File: Show a PDF document "xyz" and put it on the stage.
I alreday tried it with Switch-Case - But then I have trouble to get rid of the PDF's.
That was my Idea:
First the new as-File...
package {
import flash.display.MovieClip;
import flash.media.StageWebView;
import flash.geom.Rectangle;
import flash.filesystem.File;
import flash.display.Sprite;
import flash.display.Stage;
public class mypdf {
public var MyWebView:StageWebView
public var file:String
public var pdf:File
public function mypdf(ActFile:String) {
MyWebView = new StageWebView();
file = ActualFile; //MARKING #1
pdf = File.applicationDirectory.resolvePath(file);
MyWebView.stage = stage; //MARKING #2
MyWebView.viewPort = new Rectangle (200, 200, 400, 400);
MyWebView.loadURL(pdf.nativePath);
}
}
}
Than I want to call that in my flash-File...
stop();
var mynewpdf:mypdf = new mypdf("test.pdf");
Two erros are shown:
1120: Access of undefined property error ActualFile (at Marking #1)
1120: Access of undefined property error Stage (at Marking #2)
With a lot more work I could avoid the first error by defining a lot of different as-Scripts for each pdf.
My main problem is the second error.
It would be really nice if someone had any good ideas.
Bye,
Stephan
The second error means that you need to pass the stage to the web view. Either pass it to mypdf class as parameter, or make mypdf DisplayObject (extend Sprite for example) and add it to stage.
I'm not sure this will solve your issue anyways - I think StageWebView can simply display html. The PDF is displayed in your browser because an external plugin for that is launched.
In AIR the situation seems different: http://sujitreddyg.wordpress.com/2008/01/04/rendering-pdf-content-in-adobe-air-application/
StageWebView is wont support for nativePath, instead of using this, you can try with pdf.url. And StageWebView also having support for open .pdf files.
public function mypdf(ActFile:String) {
MyWebView = new StageWebView();
file = ActualFile; //MARKING #1
pdf = File.applicationDirectory.resolvePath(file);
MyWebView.stage = stage; //MARKING #2
MyWebView.viewPort = new Rectangle (200, 200, 400, 400);
addChild( MyWebView );
MyWebView.loadURL(pdf.url);
}
Because, StageWebView will support file:/// format, but in nativePath we got C://.., so, this will help you. Or
Simply convert your StageWebView to Display object, and then added it to your container by using addElement().
You can convert it by,
var _view:SpriteVisualElement = new SpriteVisualElement();
_view.addChild( MyWebView);
this.addElement( view );
To test by, simply call this method in added_to_stage method to test if stage is having or not. This error will come if stage is not setted means also.

Selenium RC how make screenshot of html code while tests execution?

I use selenium RC. My tests are failed after waiForPageToLoad() method. It doesn't find element on the page. I see on my browser what page is still loading while waiForPageToLoad() "said" that page is already loaded. How can I check how looks my HTML code just after waiForPageToLoad() method finished its execution?
One more thing. In one of occasions Element which sould be finded after waiForPageToLoad() is between the
<h1><script language="Javascript" </script>
<a id="some" class="some" onclick="">Text</a>
Text
</h1>
So could be that page is loaded but javascript is not yet executed. How to fix this?
1) waiForPageToLoad() does not prove that you have all elements on the page. It is better to use waitForElementPresent, or check isElementPresent to find out if the element is on the page.
2) you did not mention what language you use in RC.
if java - you may use
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
...
public void captureScreen(String fileName) throws Exception {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle screenRectangle = new Rectangle(screenSize);
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(screenRectangle);
ImageIO.write(image, "png", new File(fileName));
}
if C#:
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using Selenium;
using System.Drawing;
using System.Drawing.Imaging;
namespace SeleniumTests
{
[TestFixture]
public class ImageCapture
{
private ISelenium selenium;
private StringBuilder verificationErrors;
public static string CaptureScreenshot()
{
Bitmap bmpScreenshot = new Bitmap(1024, 768, PixelFormat.Format32bppArgb);
Graphics Screenshot = Graphics.FromImage(bmpScreenshot);
Screenshot.CopyFromScreen(0, 0, 0, 0, new Size(1024, 768));
string name = (System.Convert.ToString(System.DateTime.Now).Replace("/", "_")).Replace(":", "_") + ".jpg";
bmpScreenshot.Save(name, ImageFormat.Jpeg);
return name;
}
3) if you develop in java - consider using Sikuli. It is a tool that works with images on the screen (you may use as java library). You may combine Selenium and Sikuli to get fantastic flexibility and functionality.

AS3 URLRequest Local File on multiple OS/Browsers

Greatings!
I have yet another question concerning the loading of a .swf inside a existing one.
In my game. I have a introduction screen in which I load another .swf (which is a movie).
This all works fine and the URLRequest is this:
request = new URLRequest("Movie.swf");
As I said, this works fine. However when I copy my game.swf and movie.swf to a USB stick.
(I put them in the same directory to prevent other issues).
It doesn't seem to find the movie.swf.
Now I know that it has to do with the path given in the URLRequest and/or the publish settings. But I do not know how to make this so that it searches in the same directory
as the game.swf is in.
I hope you guys have an answer for this issue.
Thanks in advance,
Matti.
Matti, I believe Lukasz's comment is correct about it being a security error.
You can avoid this security error by embedding Movie.swf instead of using a Loader. If you do this, then at compile-time the Movie.swf needs to sit next to the Game.as file, and it will be included in the Game.swf (no need to deliver both files, just Game.swf).
The syntax is:
package
{
import flash.display.Sprite;
public class Game extends Sprite
{
[Embed(source="MyMovie.swf")]
private var myMovieClass:Class;
private var myMovie:DisplayObject;
public function Game():void
{
myMovie = new myMovieClass();
// Technically myMovie is now a Loader, and once
// it's loaded, it'll have .content that's a
// MovieClipLoaderAsset, and .content.getChildAt(0)
// will be your MyMovie.swf main timeline.
}
}
}
Alternately, if you embed it as mimeType="application/octet-stream", you can get the bytes of the SWF and use it in your existing Loader's .loadBytes() method:
package
{
import flash.display.Sprite;
import flash.utils.ByteArray;
public class Game extends Sprite
{
[Embed(source="MyMovie.swf", mimeType="application/octet-stream")]
private var movieBytes:Class;
private var myMovie:DisplayObject;
public function Game():void
{
// Treat this loader the same as your current loader,
// but don't call .load(url), call loadbytes():
var l:Loader = new Loader();
l.loadBytes(new movieBytes() as ByteArray);
}
}
}

classpath in as3 flashdevelop

I am very new in AS3. I use FlashDevelop 4. I have no Adobe Flash, just FD (pure AS3) I have problems with classpath. I searched the database but I found nothing that could help me. So the problem is as follow.
I have the project "Testing" in C:\AS App\Testing with the file Main.as. I have, also, the folder C:\AS App\W_T. In this folder is the file write_text.as. The file Main.as looks like that:
package
{
import flash.display.*;
import flash.text.TextField;
import flash.events.*;
import W_T.write_text;
public class Main extends Sprite
{
var t:TextField=new TextField();
public function Main():void
{
stage.addChild(t);
stage.addEventListener(MouseEvent.CLICK, write);
}
public function write(me:MouseEvent):void
{
var wt:W_T.write_text = new W_T.write_text();
t.x = 100;
t.y = 100;
t.text = wt.output();
}
}
}
The file write_text.as looks like that:
package W_T
{
import flash.display.*;
import flash.text.TextField;
import flash.events.*;
import W_T.*;
public class write_text
{
public function write_text()
{
}
public function output():String
{
var txt:String;
txt = "From function !";
return(txt);
}
}
}
I make the appropriate specification in the global classpath. But I get the following errors:
Error: Type was not found or was not a compile-time constant: write_text.
var wt:W_T.write_text = new W_T.write_text();
Error: Call to a possibly undefined method write_text.
var wt:W_T.write_text = new W_T.write_text();
Definition W_T:write_text could not be found.
import W_T.write_text;
Could you help me please to find where I have done wrong ?
Thank you.
EB
The problem is the compiler isn't finding your write_text.as file. By default, it will be looking here:
C:\AS App\Testing\W_T\write_text.as
Try adjusting accordingly and see if it works. When you declare package W_T { } flash will look in a subfolder called W_T for a file with the same name as the public class.
When you declare just simply package { } with no name, it will look in the root of your class library path, which seems to be a folder called Testing if that's where your main.as file is living.
If you wanted to use a common folder for your class files (that isn't nested in an individual projects folder), you can tell flash develop where to find them by going to: project -> properties, then the Classpaths tab. By default flash develop will only look in folders relative to the project.
The problem is that you haven't told the compiler (flex?) where to find the file. When you add it as classpath you only tell flash develop where to find the file, not the compiler.
First of all you have to check how you compile and secondly how you can change and add classpaths for your solution.u
I usually do this through ant script and a build.xml file and I can't unfortunately remember how the "pure as3"-projects are working in regards to compiling