Closed napcat closed 9 years ago
Hi napcat:
Thanks for pointing out, its a design flaw in current version.
Actually Scanner is neither static or singleton, but the underlying bridge ( extensionContenxt which calls methods and receives event from native code) is singleton and binds the events on the first instance of the Scanner only.
In next update I will make the Scanner class a singleton.
EDIT: I think it would be ugly for developer to use scanner as a singleton, reason being developer needs to call dispose() after the usage of scanner is done. Hence following design seems better.
Fixed in New Design, You can try the current ANE (Android Only for now)
I found a strange behavior...
I have two different classes. Witch class has her own instance of a scanner object with a function listening for a ScannerEvent.Scan event.
The problem is:
If I create an instance of ClassA and run a scan the function executed on a ScannerEvent.Scan is from ClassA.
If I start create and instance of ClassB after I created and instance of ClassA, and run a scan the function executed on the ScannerEvent.Scan if from Class A and not Class B.
This strange beahviour also happens if a swap the order (first ClassB and then ClassA).
ClassA { private function init() { try { scanner = new Scanner(); scanner.setTargetArea(512, "0xFF333333", "0xFFFFFFFF"); scanner.setConfig(Symbology.QRCODE, Config.ENABLE, 1); scanner.setConfig(Symbology.CODE128, Config.ENABLE, 1); scanner.setConfig(Symbology.EAN13, Config.ENABLE, 1);
}
private function onScannerCode(e:ScannerEvent):void {
trace("CLASS A"); } }
ClassB { private function init() { try { scanner = new Scanner(); scanner.setTargetArea(512, "0xFF333333", "0xFFFFFFFF"); scanner.setConfig(Symbology.QRCODE, Config.ENABLE, 1); scanner.setConfig(Symbology.CODE128, Config.ENABLE, 1); scanner.setConfig(Symbology.EAN13, Config.ENABLE, 1);
}
private function onScannerCode(e:ScannerEvent):void { trace("CLASS B"); } }