Copy link to clipboard
Copied
Hello,
I need to create an AIR application developed with Adobe Animate which can read QR codes.
I found some code samples in AS3 based on "LOGOSWARE Class Library", but this only can read basic QR Codes, but not QR codes with a lot of information, such as the sample I have added in this post.
There is some other library to read QR codes? Can someone help me?
The code that I'm using looks like:
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.media.*;
import flash.utils.*;
import flash.filters.*;
import flash.geom.*;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import com.logosware.event.QRdecoderEvent;
import com.logosware.event.QRreaderEvent;
import com.logosware.utils.QRcode.GetQRimage;
import com.logosware.utils.QRcode.QRdecode;
private function onStart():void {
cameraView = buildCameraView();
resultView = buildResultView();
cameraView.x = (stageWidth - cameraView.width) / 2;
cameraView.y = -15;
this.addChild(qrHome_mc);
this.addChild( cameraView );
this.addChild( resultView );
resultView.visible = false;
getQRimage = new GetQRimage(video);
getQRimage.addEventListener(QRreaderEvent.QR_IMAGE_READ_COMPLETE, onQrImageReadComplete);
qrDecode.addEventListener(QRdecoderEvent.QR_DECODE_COMPLETE, onQrDecodeComplete);
redTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onRedTimer );
this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function buildCameraView():Sprite {
camera.setQuality(0, 100);
camera.setMode(SRC_SIZE, SRC_SIZE, 24, true );
video.attachCamera( camera );
var sprite:Sprite = new Sprite();
var videoHolder:Sprite = new Sprite();
videoHolder.addChild( video );
videoHolder.x = videoHolder.y = 15;
freezeImage = new Bitmap(new BitmapData(SRC_SIZE, SRC_SIZE));
videoHolder.addChild( freezeImage );
freezeImage.visible = false;
red.graphics.lineStyle(2, 0xFF0000);
red.graphics.drawRect(videoHolder.x - 5 , videoHolder.y , videoHolder.width - videoHolder.x - 5, videoHolder.height - videoHolder.y - 10);// .drawPath(Vector.<int>([1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2, 2]), Vector.<Number>([30, 60, 30, 30, 60, 30, 290, 60, 290, 30, 260, 30, 30, 260, 30, 290, 60, 290, 290, 260, 290, 290, 260, 290]));
blue.graphics.lineStyle(2, 0x0000FF);
blue.graphics.drawRect(videoHolder.x - 5, videoHolder.y , videoHolder.width - videoHolder.x - 5, videoHolder.height - videoHolder.y - 10);// .drawPath(Vector.<int>([1,2,2,1,2,2,1,2,2,1,2,2]), Vector.<Number>([30,60,30,30,60,30,290,60,290,30,260,30,30,260,30,290,60,290,290,260,290,290,260,290]));
sprite.addChild( videoHolder );
sprite.addChild( red );
sprite.addChild( blue );
blue.alpha = 0;
red.x = red.y = 15;
blue.x = blue.y = 15;
return sprite;
}
private function buildResultView():Sprite {
var sprite:Sprite = new Sprite();
sprite.graphics.beginGradientFill(GradientType.LINEAR, [0xDDDDEE, 0xBBBBCC], [0.9, 0.9], [0, 255], new Matrix(0, 0.1, -0.1, 0, 0, 150));
sprite.graphics.drawRoundRect(0, 0, 280, 280, 20);
sprite.addChild( textArea );
textArea.width = 250;
textArea.height = 200;
textArea.wordWrap = true;
textArea.multiline = true;
textArea.border = true;
textArea.background = true;
textArea.backgroundColor = 0xFFFFFF;
textArea.x = textArea.y = 15;
var btnText:TextField = new TextField();
btnText.autoSize = TextFieldAutoSize.LEFT;
btnText.text = "CLOSE";
btnText.selectable = false;
var btnSprite:Sprite = new Sprite();
btnSprite.addChild(btnText);
btnSprite.graphics.lineStyle(1);
btnSprite.graphics.beginGradientFill(GradientType.LINEAR, [0xEEEEEE, 0xCCCCCC], [0.9, 0.9], [0, 255], new Matrix(0, 0.01, -0.01, 0, 0, 10));
btnSprite.graphics.drawRoundRect(0, 0, 80, 20, 8);
btnText.x = 0.5 * (btnSprite.width - btnText.width);
btnText.y = 0.5 * (btnSprite.height - btnText.height);
btnSprite.x = 0.5 * ( 280 - 80 );
btnSprite.y = 240;
btnSprite.buttonMode = true;
btnSprite.mouseChildren = false;
btnSprite.addEventListener(MouseEvent.CLICK, onClose);
sprite.addChild( btnSprite );
sprite.addChild( textArea );
sprite.x = sprite.y = 35;
sprite.filters = [new DropShadowFilter(4.0,45,0,0.875)];
return sprite;
}
private function onEnterFrame(e: Event):void {
if (camera != null)
{
if ( camera.currentFPS > 0 )
{
getQRimage.process();
}
}
}
private function onQrImageReadComplete(e:QRreaderEvent):void {
trace("read complete");
qrDecode.setQR(e.data);
qrDecode.startDecode();
}
private function onQrDecodeComplete(e:QRdecoderEvent):void {
blue.alpha = 1.0;
redTimer.reset();
redTimer.start();
textArray.shift();
textArray.push( e.data );
if ( textArray[0] == textArray[1] && textArray[1] == textArray[2] ) {
navigateToURL(new URLRequest(e.data), "_blank");
this.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
redTimer.stop();
camera = null;
textArray = ["", "", ""];
freezeImage.visible = false;
cameraView.filters = [];
}
}