MSCED


역시 예전꺼 우려먹기... 

각각의 아이템을 따로 따로 그려서(혹은 만들어) 조합한지라 

퍼블리싱 날짜는 네이버네이뇬에 포스팅했던 그 날짜로 기록...


make something cool every day 

2012. 09. 18




ProgressBarTest_03.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
package {
     
    import flash.display.Sprite;
    import flash.display.StageScaleMode;
    import flash.display.StageAlign;
     
    import fl.controls.Label;
    import fl.controls.Slider;
    import fl.controls.ProgressBar;
    import fl.controls.ProgressBarMode;
    import fl.controls.ProgressBarDirection;
    import fl.events.SliderEvent;
     
    public class ProgressBarTest_03 extends Sprite {
         
        private var progressBar:ProgressBar;
        private var slider:Slider;
        private var displayLabel:Label;
         
        public function ProgressBarTest_03() {
            init();
        }
         
        private function init():void {
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.showDefaultContextMenu = false;
             
            assignComponentsReference();
            configureComponents();
        }
         
        private function assignComponentsReference():void {
            progressBar = mcProgressBar;
            slider = mcSlider;
            displayLabel = mcLabel;
        }
         
        private function configureComponents():void {
            displayLabel.text = "Percent: 0%";
             
            slider.value = 0;
            slider.maximum = 250;
            slider.minimum =  0;
            slider.tickInterval = 25;
            slider.snapInterval = 1;
            slider.liveDragging = true;
            slider.addEventListener(SliderEvent.CHANGE, onChangeValue, false, 0, true);
             
            progressBar.mode = ProgressBarMode.MANUAL;
            progressBar.direction = ProgressBarDirection.RIGHT;
            progressBar.maximum = slider.maximum;
            progressBar.minimum =  slider.minimum;
            progressBar.indeterminate = false;
        }
         
        private function onChangeValue(event:SliderEvent):void {
            progressBar.value = slider.value;
            progressBar.setProgress(progressBar.value, progressBar.maximum);
            displayLabel.text = "Percent: " + Math.round(progressBar.percentComplete) + "%";
        }
    }
}


파폭에서 재생이 끝난 후 플레이 버튼을 눌러도 리플레이가 되지 않는

오류가 있지만, 수정하기 귀찮다는게 함정....

ProgressBarTest_04.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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
package {
     
    import flash.display.Sprite;
    import flash.display.StageScaleMode;
    import flash.display.StageAlign;
    import flash.display.MovieClip;
     
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.events.TimerEvent;
     
    import flash.events.AsyncErrorEvent;
    import flash.events.NetStatusEvent;
     
    import flash.utils.Timer;
    import flash.media.Video;
    import flash.text.TextFormat;
     
    import flash.net.NetConnection;
    import flash.net.NetStream;
     
    import fl.controls.Label;
    import fl.controls.ProgressBar;
    import fl.controls.ProgressBarMode;
     
    public class ProgressBarTest_04 extends Sprite {
         
        private var connection:NetConnection;
        private var stream:NetStream;
         
        private var timer:Timer;
        private var video:Video;
        private var videoHolder:MovieClip;
        private var duration:Number;
         
        private var positionLabel:Label;
        private var positionBar:ProgressBar;
        private var messageLabel:Label;
         
        private var playButton:Sprite;
        private var pauseButton:Sprite;
        private var stopButton:Sprite;
         
        private static var videoURL:String = "http://www.helpexamples.com/flash/video/cuepoints.flv";
         
        public function ProgressBarTest_04() {
            init();
        }
         
        private function init():void {
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.showDefaultContextMenu = false;
             
            assignComponentsReference();
            configureComponents();
        }
         
        private function assignComponentsReference():void {
            playButton = mcPlayButton;
            pauseButton = mcPauseButton;
            stopButton = mcStopButton;
             
            videoHolder = mcVideoHolder;
            positionBar = mcPositionBar;
            positionLabel = mcPositionLabel;
        }
         
        private function configureComponents():void {
            var format:TextFormat = new TextFormat;
            format.color = 0x999999;
            format.size = 10;
            format.font = "Arial, Tahoma, Verdana, Sans";
             
            positionLabel.textField.text = "00 : 00";
            positionLabel.setStyle("textFormat", format);
             
            positionBar.mode = ProgressBarMode.MANUAL;
            positionBar.indeterminate = false;
             
            connect();
        }
         
        private function connect():void {
            connection = new NetConnection();
            connection.addEventListener(NetStatusEvent.NET_STATUS, onNetStatusEvent, false, 0, true);
            connection.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onAsyncErrorEvent, false, 0, true);
            connection.connect(null);
        }
         
        private function onNetStatusEvent(event:NetStatusEvent):void {
            switch (event.info.code) {
                case "NetConnection.Connect.Success" :
                    connectStream();
                    break;
                case "NetStream.Play.StreamNotFound" :
                    showErrorMessage();
                    break;
                case "NetStream.Play.Start" :
                    initVideo();
                    trace("Start [" + stream.time.toFixed(3) + " seconds]");
                    break;
                case "NetStream.Play.Stop" :
                    completeVideo();
                    trace("Stop [" + stream.time.toFixed(3) + " seconds]");
                    break;
            }
            trace(event.info.code);
        }
         
        private function onAsyncErrorEvent(event:AsyncErrorEvent):void {
            trace("onAsyncErrorEvent: " + event);
        }
         
        private function connectStream():void {
            stream = new NetStream(connection);
            stream.client = this;
            stream.bufferTime = 5;
            stream.checkPolicyFile = true;
            stream.addEventListener(NetStatusEvent.NET_STATUS, onNetStatusEvent, false, 0, true);
            stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onAsyncErrorEvent, false, 0, true);
             
            video = new Video();
            video.width =  320;
            video.height = 213;
            video.attachNetStream(stream);
            videoHolder.addChild(video);
             
            stream.play(videoURL);
            stream.pause();
        }
         
        public function onMetaData(metaData:Object):void {
            for (var key:String in metaData) {
                trace(key + "=====" + metaData[key]);
            }
            duration = metaData.duration;
        }
         
        public function onCuePoint(metaData:Object):void {}
         
        private function initVideo():void {
            if (!playButton.hasEventListener(MouseEvent.CLICK)) {
                playButton.buttonMode = true;
                playButton.addEventListener(MouseEvent.CLICK, playVideo, false, 0, true);
            }
            if (!pauseButton.hasEventListener(MouseEvent.CLICK)) {
                pauseButton.buttonMode = true;
                pauseButton.addEventListener(MouseEvent.CLICK, pauseVideo, false, 0, true);
            }
            if (!stopButton.hasEventListener(MouseEvent.CLICK)) {
                stopButton.buttonMode = true;
                stopButton.addEventListener(MouseEvent.CLICK, stopVideo, false, 0, true);
            }
            if (timer == null) {
                timer = new Timer(30);
                timer.addEventListener(TimerEvent.TIMER, onTimer, false, 0, true);
            }
        }
         
        private function playVideo(event:MouseEvent):void {
            stream.resume();
            timer.start();
        }
         
        private function pauseVideo(event:MouseEvent):void {
            stream.pause();
            timer.stop();
        }
         
        private function stopVideo(event:MouseEvent):void {
            stream.pause();
            stream.seek(0);
            positionBar.setProgress(0, duration);
            positionLabel.text = "00 : 00";
            timer.stop();
        }
         
        private function completeVideo():void {
            stopVideo(null);
        }
         
        private function onTimer(event:TimerEvent):void {
            try {
                var min:String = convertDigit(Math.floor(stream.time / 60));
                var sec:String = convertDigit(Math.floor(stream.time % 60));
                positionLabel.text = min + " : " + sec;
                positionBar.setProgress(stream.time, duration);
            } catch (err:Error) {
                trace(err.message);
            }
        }
         
        private function convertDigit(num:Number):String {
            return num < 10 ? "0" + num : num.toString();
        }
         
        private function showErrorMessage():void {
            var format:TextFormat = new TextFormat();
            format.size = 11;
            format.bold = true;
            format.color = 0x00CC66;
            format.font = "Tahoma, Arial, Verdana, Sans";
             
            messageLabel = new Label();
            messageLabel.text = "URL Not Found";
            messageLabel.setStyle("textFormat", format);
            messageLabel.x = 10 + Math.round(videoHolder.width / 2 -  messageLabel.textField.textWidth / 2);
            messageLabel.y = 10 + Math.round(videoHolder.height / 2 - messageLabel.textField.textHeight / 2);
            addChild(messageLabel);
        }
    }
}



ProgressBarTest_01.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package {
     
    import flash.display.Sprite;
    import flash.display.StageAlign;
     
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.events.ProgressEvent;
    import flash.events.IOErrorEvent;
    import flash.events.SecurityErrorEvent;
     
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.media.ID3Info;
    import flash.media.SoundLoaderContext;
    import flash.net.URLRequest;
     
    import fl.controls.Label;
    import fl.controls.Button;
    import fl.controls.ProgressBar;
    import fl.controls.ProgressBarMode;
     
    public class ProgressBarTest_01 extends Sprite {
         
        private var sound:Sound;
        private var channel:SoundChannel;
         
        private var artist:String;
        private var songName:String;
         
        private var displayLabel:Label;
        private var loadButton:Button;
        private var progressBar:ProgressBar;
         
        private static var soundURL:String = "http://www.helpexamples.com/flash/sound/song1.mp3";
         
        public function ProgressBarTest_01() {
            init();
        }
         
        private function init():void {
            stage.align = StageAlign.TOP_LEFT;
            stage.showDefaultContextMenu = false;
             
            assignComponentsReference();
            configureComponents();
        }
         
        private function assignComponentsReference():void {
            displayLabel = mcLabel;
            loadButton = mcButton;
            progressBar = mcProgressBar;
        }
         
        private function configureComponents():void {
            progressBar.mode = ProgressBarMode.EVENT;
            loadButton.addEventListener(MouseEvent.CLICK, onMouseClick, false, 0, true);
        }
         
        private function onMouseClick(event:MouseEvent):void {
            loadButton.enabled = false;
            loadSound();
        }
         
        private function loadSound():void {
            sound = new Sound();
            sound.addEventListener(IOErrorEvent.IO_ERROR, onIOErrorEvent, false, 0, true);
            sound.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError, false, 0, true);
            sound.addEventListener(Event.ID3, onID3Event, false, 0, true);
             
            progressBar.source = sound;
            progressBar.addEventListener(ProgressEvent.PROGRESS, onLoadProgress, false, 0, true);
            progressBar.addEventListener(Event.COMPLETE, onLoadComplete, false, 0, true);
            try {
                var context:SoundLoaderContext = new SoundLoaderContext();
                context.checkPolicyFile = true;
                sound.load(new URLRequest(soundURL + "?uniqueNumber=" + new Date().getTime()), context);
            } catch (err:Error) {
                trace(err.message);
            }
        }
         
        private function removeListeners():void {
            sound.removeEventListener(IOErrorEvent.IO_ERROR, onIOErrorEvent);
            sound.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
            sound.removeEventListener(Event.ID3, onID3Event);
             
            progressBar.removeEventListener(ProgressEvent.PROGRESS, onLoadProgress);
            progressBar.removeEventListener(Event.COMPLETE, onLoadComplete);
        }
         
        private function onIOErrorEvent(event:IOErrorEvent):void {
            displayLabel.text = "IOErrorEvent : URL NotFound";
            removeListeners();
        }
         
        private function onSecurityError(event:SecurityErrorEvent):void {
            displayLabel.text = "SecurityError : Sandbox Violation";
            removeListeners();
        }
         
        private function onLoadProgress(event:ProgressEvent):void {
            displayLabel.text = "sound loading... " + Math.round(progressBar.percentComplete) + "%";
        }
         
        private function onLoadComplete(event:Event):void {
            channel = sound.play();
            channel.addEventListener(Event.SOUND_COMPLETE, onSoundComplete, false, 0, true);
            displayLabel.text = songName + ".mp3 - " + artist;
            removeListeners();
            trace("File size: " + sound.bytesTotal + "bytes");
        }
         
        private function onID3Event(event:Event):void {
            var id3:ID3Info = sound.id3;
            for (var item:String in id3) {
                trace(item, " : ", id3[item]);
            }
             
            artist = id3.artist;
            songName = id3.songName;
             
            if (artist == null) {
                artist = "Unknown artist";
            }
             
            if (songName == null) {
                songName = "There is no data";
            }
        }
         
        private function onSoundComplete(event:Event):void {
            channel.stop();
            channel.removeEventListener(Event.SOUND_COMPLETE, onSoundComplete);
             
            progressBar.reset();
            progressBar.source = null;
            loadButton.enabled = true;;
            displayLabel.text = "Play again?";
        }
    }
}


ProgressBarTest_02.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
package {
     
    import flash.display.Sprite;
    import flash.display.StageAlign;
     
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.events.ProgressEvent;
    import flash.events.IOErrorEvent;
    import flash.events.SecurityErrorEvent;
     
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.media.ID3Info;
    import flash.media.SoundLoaderContext;
    import flash.net.URLRequest;
     
    import fl.controls.Label;
    import fl.controls.Button;
    import fl.controls.ProgressBar;
    import fl.controls.ProgressBarMode;
     
    public class ProgressBarTest_02 extends Sprite {
         
        private var sound:Sound;
        private var channel:SoundChannel;
         
        private var artist:String;
        private var songName:String;
         
        private var displayLabel:Label;
        private var loadButton:Button;
        private var progressBar:ProgressBar;
         
        private static var soundURL:String = "http://www.helpexamples.com/flash/sound/song1.mp3";
         
 
        /* 상략... */
 
 
        private function configureComponents():void {
            progressBar.mode = ProgressBarMode.POLLED;
            loadButton.addEventListener(MouseEvent.CLICK, onMouseClick, false, 0, true);
        }
 
        /* 중략... */
 
        private function onLoadProgress(event:ProgressEvent):void {
            var percent:uint = Math.round(sound.bytesLoaded / sound.bytesTotal * 100);
            displayLabel.text = "sound loading... " + percent + "%";
            trace(Math.round(sound.bytesLoaded / sound.bytesTotal * 100) + "%");
        }
 
 
        /* 하략... */
 
 
    }
}





MSCED


make something cool every day 

2012. 01. 20







MSCED


make something cool every day 

2011. 03. 27