-
Notifications
You must be signed in to change notification settings - Fork 1
/
CameraTool.as
106 lines (90 loc) · 2.98 KB
/
CameraTool.as
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
94
95
96
97
98
99
100
101
102
103
104
105
106
package com.shaunhusain.fingerPainting.tools
{
import flash.display.Loader;
import flash.display.Stage;
import flash.events.ErrorEvent;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.MediaEvent;
import flash.events.TouchEvent;
import flash.media.CameraUI;
import flash.media.MediaPromise;
import flash.media.MediaType;
public class CameraTool extends ToolBase implements ITool
{
//--------------------------------------------------------------------------------
// Variables
//--------------------------------------------------------------------------------
private var deviceCameraApp:CameraUI = new CameraUI();
private var imageLoader:Loader;
//--------------------------------------------------------------------------------
// Constructor
//--------------------------------------------------------------------------------
public function CameraTool(stage:Stage) {
super(stage);
if( CameraUI.isSupported )
{
trace( "Initializing camera..." );
deviceCameraApp.addEventListener( MediaEvent.COMPLETE, imageCaptured );
deviceCameraApp.addEventListener( Event.CANCEL, captureCanceled );
deviceCameraApp.addEventListener( ErrorEvent.ERROR, cameraError );
}
else
{
trace( "Camera interface is not supported.");
}
}
//--------------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------------
public function takeAction(event:TouchEvent=null):void
{
model.disableNextAutosave = true;
deviceCameraApp.launch( MediaType.IMAGE );
}
//--------------------------------------------------------------------------------
// Camera UI functions
//--------------------------------------------------------------------------------
private function imageCaptured( event:MediaEvent ):void
{
trace( "Media captured..." );
var imagePromise:MediaPromise = event.data;
if( imagePromise.isAsync )
{
trace( "Asynchronous media promise." );
imageLoader = new Loader();
imageLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, asyncImageLoaded );
imageLoader.addEventListener( IOErrorEvent.IO_ERROR, cameraError );
imageLoader.loadFilePromise( imagePromise );
}
else
{
trace( "Synchronous media promise." );
imageLoader.loadFilePromise( imagePromise );
showMedia( imageLoader );
}
}
private function captureCanceled( event:Event ):void
{
trace( "Media capture canceled." );
}
private function asyncImageLoaded( event:Event ):void
{
trace( "Media loaded in memory." );
showMedia( imageLoader );
}
private function showMedia( loader:Loader ):void
{
loader.scaleX=-1;
layerM.addLayer( loader );
}
private function cameraError( error:ErrorEvent ):void
{
trace( "Error:" + error.text );
}
public function toString():String
{
return "Loading CameraUI";
}
}
}