-
Notifications
You must be signed in to change notification settings - Fork 4
/
CuTy.as
127 lines (103 loc) · 3.7 KB
/
CuTy.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package {
import flash.display.*;
import flash.events.*;
import flash.system.Capabilities;
import flash.system.Security;
import com.fieldofview.util.Logger;
import com.fieldofview.util.FileStreamer;
import com.fieldofview.util.FullscreenMenu;
import com.fieldofview.qtparser.QTAtom;
import com.fieldofview.qtparser.MovParser;
import com.fieldofview.cuty.CutyScene;
// SWF Metadata
[SWF(width="480", height="360", backgroundColor="#FFFFFF", framerate="24")]
public class CuTy extends Sprite {
private var logger:Logger;
private var movStream:FileStreamer;
private var movStructure:MovParser;
private var scene:CutyScene;
public function CuTy() {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
Security.allowDomain("*")
logger = new Logger(this);
logger.send("CuTy 0.1, © Aldo Hoeben / fieldOfView", Logger.INFO);
// Get the player’s version by using the flash.system.Capabilities class.
var versionString:String = Capabilities.version.split(",")[0];
if (parseInt(Capabilities.version.split(",")[0].split(" ")[1]) < 10) {
logger.send("This viewer requires Flash player 10 or newer", Logger.ERROR);
return;
}
var fullscreenMenu:FullscreenMenu = new FullscreenMenu(this);
scene = new CutyScene(this);
scene.eventDispatcher.addEventListener(CutyScene.ERROR, sceneLog);
scene.eventDispatcher.addEventListener(CutyScene.INFO, sceneLog);
var movURL:String;
if (loaderInfo.parameters.hasOwnProperty("mov")) {
// Get mov url from FlashVars or querystring
movURL = loaderInfo.parameters["mov"];
} else {
// If mov parameter not supplied, try name of swf file with .mov extension
movURL = loaderInfo.loaderURL.replace(/.swf$/, ".mov");
}
logger.send("Loading " + movURL + "...", Logger.INFO);
movStream = new FileStreamer(movURL);
movStream.eventDispatcher.addEventListener(FileStreamer.PROGRESS, streamProgress);
movStream.eventDispatcher.addEventListener(FileStreamer.ERROR, streamError);
movStream.eventDispatcher.addEventListener(FileStreamer.COMPLETE, streamComplete);
movStructure = new MovParser(movStream.content);
movStructure.eventDispatcher.addEventListener(MovParser.ERROR, parserLog);
movStructure.eventDispatcher.addEventListener(MovParser.INFO, parserLog);
}
public function destroy():void {
if (movStream != null) {
movStream.destroy();
movStream = null;
}
if (movStructure != null)
movStructure = null;
}
private function parserLog(__event:Event):void {
logger.send(movStructure.message, __event.type)
if(__event.type == MovParser.ERROR) {
destroy();
}
}
private function sceneLog(__event:Event):void {
logger.send(scene.message, __event.type)
if(__event.type == CutyScene.ERROR) {
destroy();
}
}
private function streamProgress(__event:Event):Boolean {
if(!movStructure.allDone) {
if(!movStructure.handleStream()) {
return false;
}
}
if(!movStructure.allDone) {
return false;
}
if(!scene.built) {
scene.build(movStructure);
logger.send("Loading tiles from Quicktime file...", Logger.INFO);
}
if(!scene.allDone) {
// tiles streaming in
scene.updateTiles(movStream.content);
}
return true;
}
private function streamError(__event:Event):void {
logger.send(movStream.error, Logger.ERROR);
destroy();
}
private function streamComplete(__event:Event):void {
if(movStructure != null && movStructure.allDone == false) {
logger.send("Unexpected end of file.", Logger.ERROR);
destroy();
}
logger.send("Done", Logger.INFO);
}
}
}