-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathDemo.as
More file actions
93 lines (76 loc) · 2.3 KB
/
Demo.as
File metadata and controls
93 lines (76 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package {
import com.kcly.ane.bitmapdataqrcodescanner.Scanner;
import com.kcly.ane.bitmapdataqrcodescanner.ScannerEvent;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.media.Camera;
import flash.media.Video;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
import flash.utils.setInterval;
public class Demo extends Sprite {
private var scanner:Scanner;
private var tf:TextField;
private var bmpData:BitmapData;
private var video:Video;
private var sp:Sprite;
public function Demo():void {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(Event.DEACTIVATE, deactivate);
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
init();
}
private function init():void {
scanner = new Scanner
scanner.addEventListener(ScannerEvent.SCAN, onScanFound)
var cam:Camera = Camera.getCamera();
cam.setMode(480,480,15);
sp = new Sprite
addChild(sp)
var stageW:int = stage.fullScreenWidth
var vidH:int = stageW/(cam.width/cam.height)
video = new Video(vidH, stageW);
video.y = -stageW / 2;
video.x = -vidH / 2;
video.attachCamera(cam);
sp.x = stageW / 2;
sp.y = vidH / 2;
sp.rotation = 90;
sp.addChild(video);
bmpData = new BitmapData(sp.width, sp.height, false, 0);
tf = new TextField;
tf.multiline = tf.wordWrap = true;
tf.y = sp.height;
addChild(tf)
var tfmt:TextFormat = new TextFormat
tfmt.font = "Arial"
tfmt.size = 48;
tf.defaultTextFormat = tfmt;
tf.text = "Scanning...";
tf.width = stageW;
tf.autoSize = TextFieldAutoSize.LEFT;
setInterval(doScan, 1000)
trace ('inited')
}
private function doScan():void {
bmpData.draw(video);
trace ('doScan', bmpData.width, bmpData.height)
scanner.scan(bmpData);
}
private function onScanFound(evt:ScannerEvent):void {
trace ('onScanFound', evt.data)
tf.text = evt.data;
tf.autoSize = TextFieldAutoSize.LEFT;
}
private function deactivate(e:Event):void {
//NativeApplication.nativeApplication.exit();
}
}
}