I want to list down all available printers that are availble. I found this answer:
As3 List down the Printers that available in the system
But this doesn’t work, I’m getting this error:
Error: Access of possibly undefined property printers through a reference with static type Class.
this is my source:
package
{
import flash.display.Sprite;
import flash.printing.PrintJob;
import flash.external.ExternalInterface;
public class gethwinfo extends Sprite
{
public function gethwinfo()
{
ExternalInterface.call('getPrinter', getPrinterList());
}
public function getPrinterList():Array
{
var printerList:Vector.<String> = PrintJob.printers;
var deviceNames:Array = [];
if (printerList)
{
for (var i:int = 0; i < printerList.length; i++)
{
deviceNames.push(printerList[i]);
}
} else
{
deviceNames.push("No Printers");
}
deviceNames.sort();
return deviceNames;
}
}
}
The Error says that the property printers is undefined, although this property is listed in the as-reference: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/printing/PrintJob.html#printers
I get this error with strict mode set to true in the compiler options. When I set it to false the build is sucessfull, but when I call this flash object it goes into the else branch and I get the String “No Printers”, which should not be, because I have 6 printer services available on my machine.
I hope that you can give me a hint.
its only available in AIR. thats why the AIR icon is next to it in the as-reference.