GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: the flash recorder for chirrp, written with haXe
Homepage: http://chirrp.net/
Clone URL: git://github.com/why/chirrup.git
Got the basic Rec, Stop, Play buttons all worked out.
why (author)
Wed Apr 16 22:24:31 -0700 2008
commit  7998c464766522ec199f249ff4cd6b0e59669640
tree    6481a420c347222c909dd8bef9a7889469680914
parent  7b149e3288a2bec713326120c6e5ccae3b6dcf6f
...
19
20
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
23
24
...
39
40
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
43
44
...
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
...
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
0
@@ -19,6 +19,22 @@ class Base {
0
   static var httpExp : EReg = ~/^http:\/\//;
0
   static var bpos : Float = 2;
0
 
0
+ static var DEGTORAD:Float = Math.PI/180;
0
+ static var a:Float = Math.tan( 22.5 * DEGTORAD);
0
+
0
+ static var UID_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
0
+
0
+ public static function random(?size : Int) : String
0
+ {
0
+ if(size == null) size = 32;
0
+ var nchars = UID_CHARS.length;
0
+ var uid = "";
0
+ for (i in 0 ... size){
0
+ uid += UID_CHARS.charAt( Std.int(Math.random() * nchars) );
0
+ }
0
+ return uid;
0
+ }
0
+
0
   static function privacyPane() {
0
     Security.showSettings(SecurityPanel.PRIVACY);
0
   }
0
@@ -39,6 +55,42 @@ class Base {
0
     }
0
   }
0
 
0
+ static function addBitmap( bmp ) {
0
+ flash.Lib.current.addChild(new flash.display.Bitmap(bmp, flash.display.PixelSnapping.AUTO, true));
0
+ }
0
+
0
+ static function movieBitmap( bmp ) {
0
+ var mc = new flash.display.MovieClip();
0
+ mc.addChild(new flash.display.Bitmap(bmp, flash.display.PixelSnapping.AUTO, true));
0
+ return mc;
0
+ }
0
+
0
+ static function addBitmapButton( bmpOff, bmpOn, bmpHit, onClick )
0
+ {
0
+ var sb = new flash.display.SimpleButton();
0
+ sb.upState = movieBitmap(bmpOff);
0
+ sb.overState = movieBitmap(bmpOff);
0
+ sb.downState = movieBitmap(bmpOn);
0
+ sb.hitTestState = bmpHit;
0
+ sb.useHandCursor = true;
0
+ sb.addEventListener(flash.events.MouseEvent.CLICK, onClick);
0
+ flash.Lib.current.addChild(sb);
0
+ return sb;
0
+ }
0
+
0
+ static function drawCircle( mc:flash.display.MovieClip, x:Float, y:Float, r:Float )
0
+ {
0
+ mc.graphics.moveTo( x + r, y );
0
+
0
+ for (i in 0...8) {
0
+ var endX = x + r * Math.cos( (i + 1) * 45 * DEGTORAD);
0
+ var endY = y + r * Math.sin( (i + 1) * 45 * DEGTORAD);
0
+ var controlX = endX + r * a * Math.cos( ((i + 1) * 45 - 90) * DEGTORAD);
0
+ var controlY = endY + r * a * Math.sin( ((i + 1) * 45 - 90) * DEGTORAD);
0
+ mc.graphics.curveTo( controlX, controlY, endX, endY);
0
+ }
0
+ }
0
+
0
   static function addButton( text, onClick ) {
0
     var t = new TextField();
0
     t.text = text;
0
...
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
...
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
 
 
158
159
160
161
162
163
164
 
 
 
165
166
167
168
169
170
171
172
173
174
175
176
 
177
178
179
180
0
@@ -1,75 +1,180 @@
0
 import flash.display.BitmapData;
0
+import flash.display.MovieClip;
0
+import flash.display.SimpleButton;
0
 import flash.net.NetStream;
0
 import flash.text.TextField;
0
+import flash.text.TextFormat;
0
 import haxe.Timer;
0
 
0
-class ShoesPng extends BitmapData {
0
-}
0
+class RecOffPng extends BitmapData {}
0
+class RecOnPng extends BitmapData {}
0
+class RecHoverPng extends BitmapData {}
0
+class PlayUpPng extends BitmapData {}
0
+class PlayDownPng extends BitmapData {}
0
 
0
 class Rec extends Base {
0
 
0
+ static var recButton : SimpleButton;
0
+ static var stopButton : SimpleButton;
0
+ static var playButton : SimpleButton;
0
+ static var countdown : TextField;
0
+ static var countfont : TextFormat;
0
+ static var stat : TextField;
0
+
0
   static var seconds : Float = 8;
0
 
0
+ static var uuid : String;
0
   static var url : String;
0
- static var stat : TextField;
0
   static var clock : Timer;
0
   static var start : Float = 0;
0
 
0
   static function timeRecording() {
0
     var used : Float;
0
- stat.text = "" + Base.elapsedTime();
0
     if (Base.elapsedTime() > 0) {
0
       if (start == 0) {
0
         start = Timer.stamp();
0
       }
0
 
0
       used = (Timer.stamp() - start);
0
- stat.text = "" + used;
0
+ countdown.text = "" + Std.int(seconds - used);
0
+ countdown.setTextFormat(countfont);
0
       if (used >= seconds) {
0
- stopRecording();
0
+ stopRecording(null);
0
         clock.stop();
0
       }
0
     }
0
   }
0
 
0
- static function startRecording() {
0
+ static function startRecording(e) {
0
     stat.text = "Connecting...";
0
- Base.record("new.flv", function(ns) {
0
+ stopButton.visible = true;
0
+ recButton.visible = false;
0
+ Base.record(uuid + ".flv", function(ns) {
0
       start = 0;
0
       clock = new Timer(200);
0
       clock.run = timeRecording;
0
     });
0
   }
0
 
0
- static function playRecording() {
0
+ static function playRecording(e) {
0
     stat.text = "Playing.";
0
- Base.play("new.flv");
0
+ Base.play(uuid + ".flv");
0
   }
0
 
0
- static function stopRecording() {
0
+ static function stopRecording(e) {
0
     stat.text = "Stopped";
0
     Base.stop();
0
     clock.stop();
0
+ stopButton.visible = false;
0
+ playButton.visible = true;
0
   }
0
 
0
   static function main() {
0
- var png1 : BitmapData = new ShoesPng(0, 0);
0
- flash.Lib.current.addChild(new flash.display.Bitmap(png1, flash.display.PixelSnapping.AUTO, true));
0
+ uuid = Base.random(32);
0
+
0
+ //
0
+ // Record button
0
+ //
0
+ var rec_off = new RecOffPng(0, 0);
0
+ var rec_hit = new MovieClip();
0
+ rec_hit.graphics.beginFill(0);
0
+ Base.drawCircle(rec_hit, 54, 54, 36);
0
+
0
+ recButton =
0
+ Base.addBitmapButton(
0
+ rec_off,
0
+ new RecHoverPng(0, 0),
0
+ rec_hit,
0
+ startRecording
0
+ );
0
+
0
+ recButton.x = 40;
0
+ recButton.y = 10;
0
+
0
+ //
0
+ // Stop button
0
+ //
0
+ var stop_on = new RecOnPng(0, 0);
0
+
0
+ stopButton =
0
+ Base.addBitmapButton(
0
+ stop_on,
0
+ stop_on,
0
+ rec_hit,
0
+ stopRecording
0
+ );
0
+
0
+ stopButton.visible = false;
0
+ stopButton.x = 40;
0
+ stopButton.y = 10;
0
+
0
+ //
0
+ // Play button
0
+ //
0
+ var play_up = new PlayUpPng(0, 0);
0
+ var play_down = new PlayDownPng(0, 0);
0
+
0
+ playButton =
0
+ Base.addBitmapButton(
0
+ play_up,
0
+ play_down,
0
+ rec_hit,
0
+ playRecording
0
+ );
0
+
0
+ playButton.visible = false;
0
+ playButton.x = 40;
0
+ playButton.y = 10;
0
+
0
+ //
0
+ // Countdown instrument
0
+ //
0
+ countfont = new TextFormat();
0
+ countfont.font = "Verdana";
0
+ countfont.size = 72;
0
+ countfont.bold = true;
0
+ countfont.color = 0;
0
+
0
+ var mcmed = new TextFormat();
0
+ mcmed.font = "Verdana";
0
+ mcmed.size = 14;
0
+ mcmed.bold = true;
0
+ mcmed.color = 0;
0
+
0
+ var mcc = new MovieClip();
0
+ var mct = new TextField();
0
+ mct.text = "You have";
0
+ mct.setTextFormat(mcmed);
0
+ mcc.addChild(mct);
0
+
0
+ countdown = new TextField();
0
+ countdown.text = "8";
0
+ countdown.setTextFormat(countfont);
0
+ mcc.addChild(countdown);
0
+ countdown.x = 10;
0
+ countdown.y = 4;
0
+ flash.Lib.current.addChild(mcc);
0
 
0
- url = flash.Lib.current.loaderInfo.loaderURL;
0
- trace(url);
0
+ var mct2 = new TextField();
0
+ mct2.text = "seconds";
0
+ mct2.setTextFormat(mcmed);
0
+ mct2.x = 3;
0
+ mct2.y = 72;
0
+ mcc.addChild(mct2);
0
 
0
- Base.addButton("Start", startRecording);
0
- Base.addButton("Stop", stopRecording);
0
- Base.addButton("Play", playRecording);
0
+ mcc.x = 220;
0
+ mcc.y = 20;
0
 
0
+ //
0
+ // Sounds good?
0
+ //
0
     stat = new TextField();
0
     stat.text = "Stopped.";
0
     stat.width = 380;
0
     stat.height = 18;
0
     stat.selectable = false;
0
     stat.x = 2;
0
- stat.y = 30;
0
+ stat.y = 124;
0
     flash.Lib.current.addChild(stat);
0
   }
0
 }
...
9
10
11
12
13
...
9
10
11
 
12
0
@@ -9,5 +9,4 @@
0
 -swf chirplay.swf
0
 -swf-version 9
0
 -swf-header 400:140:24:FFFFFF
0
--swf-lib library.swf
0
 -main Play
...
3
4
5
6
 
 
 
 
 
7
8
9
...
3
4
5
 
6
7
8
9
10
11
12
13
0
@@ -3,7 +3,11 @@
0
   <background color="#ffffff"/>
0
   <frame>
0
   <library>
0
- <bitmap id="ShoesPng" name="ShoesPng" import="library/shoes.png" />
0
+ <bitmap id="RecOffPng" name="RecOffPng" import="library/chirec-rec1.png" />
0
+ <bitmap id="RecOnPng" name="RecOnPng" import="library/chirec-rec2.png" />
0
+ <bitmap id="RecHoverPng" name="RecHoverPng" import="library/chirec-rec4.png" />
0
+ <bitmap id="PlayUpPng" name="PlayUpPng" import="library/chirec-play1.png" />
0
+ <bitmap id="PlayDownPng" name="PlayDownPng" import="library/chirec-play2.png" />
0
   </library>
0
   </frame>
0
 </movie>

Comments

    No one has commented yet.