| Subcribe via RSS

Animation Window

February 26th, 2009 | 2 Comments | Posted in AIR, ActionScript 3.0

Well, this is another AIR project with Native Window. In this AIR project you will see how to animate a Native Window, and the Tween Method if you do not already know, but I think you are knowing this method. I used the simple Tween Method not the TweenMax or another. But if you like the TweenMax you can use it. The code is not very hard to understand. Put if you don’t understand go to the previous post and look there or leave me a comment, and I will answer you in the shortest time.
OK…enough talking, this is the code and the explanations:

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
package
{
	     // ----------------------------------------
        //  Imports
       // ----------------------------------------
 
	import flash.display.MovieClip;
	import flash.display.NativeWindow;
	import flash.display.NativeWindowType;
	import flash.display.NativeWindowInitOptions;
	import flash.display.NativeWindowSystemChrome;
	import flash.display.StageDisplayState;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.text.TextField;
	import flash.events.MouseEvent;
	import flash.system.Capabilities;
	import fl.transitions.Tween;
	import fl.transitions.easing.Bounce;
	import fl.transitions.TweenEvent;
 
	public class AnimationWindow extends MovieClip
	{
		 // ----------------------------------------
        //   Variables
       // ----------------------------------------
 
	    //Same public variables which will help us in the following private methodes
		public var mainWindow:NativeWindow;
		public var newWinInit:NativeWindowInitOptions = new NativeWindowInitOptions ();
		public var newWin:NativeWindow;
		public var labelText:TextField = new TextField();
		public var createIt:MovieClip = new MovieClip();
		public var moveWin:MovieClip = new MovieClip();
		public var thisTime:Date = new Date();
 
		  // ----------------------------------------
         //  CONSTRUCTOR
        // ---------------------------------------
           //Now set the constructor of your ActionScript class
		public function AnimationWindow ():void
		{
			//At this point, you must remember that the new window you will create has to keep the
            //content unaltered. To do this, you have assigned the StageScaleMode.NO_SCALE value to scaleMode
            //property and the StageAlign.TOP_LEFT value to the  align properties
			mainWindow = stage.nativeWindow;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
 
			//The content for the New Native Window
			labelText.htmlText = String("Today is <b>"+thisTime.getDate()+"/"+(thisTime.getMonth()+1)+"/"+thisTime.getFullYear()+"</br>");
 
			addChild(createIt);
			addChild(moveWin);
			designButton(createIt, 100,30,0,0);
			designButton(moveWin, 100,30,0,100);
 
			createIt.addEventListener(MouseEvent.CLICK,createWindow);
			moveWin.addEventListener(MouseEvent.CLICK, moveWindow);
		}
		  // ----------------------------------------
         //  Private Methods
        // ----------------------------------------
 
		private function createWindow(e:MouseEvent):void
		{
			//Next are the methods that create the new window:
			newWinInit.systemChrome = NativeWindowSystemChrome.STANDARD;
			newWinInit.type = NativeWindowType.UTILITY;
			newWin = new NativeWindow(newWinInit);
			newWin.activate()
			newWin.stage.addChild(labelText);
			newWin.title = "Calendar|Window";
			newWin.x = 0;
			newWin.width = 300;
			newWin.height = 100;
			newWin.stage.addEventListener(MouseEvent.CLICK,closeMe);
		}
 
		function closeMe(event:MouseEvent):void
		{
			//The closeMe method allows you to close both of the windows once the user clicks the utility window.
			newWin.close();
			mainWindow.close();
		}
 
		private function moveWindow(event:MouseEvent)
		{
			//The next method, allows you to move the window on the user’s desktop.
			var moveIt:Tween = new Tween(newWin, "x", Bounce.easeOut,newWin.x,((Capabilities.screenResolutionX) - newWin.width), 5, true);
 
			moveIt.addEventListener(TweenEvent.MOTION_FINISH,backIt);
			function backIt(event:TweenEvent)
			{
				moveIt.yoyo();
			}
		}
 
		private function designButton(obj:MovieClip, objWidth:Number, objHeight:Number, objX:Number, objY:Number)
		{
			//Set the position to the buttons
			with(obj.graphics)
			{
				beginFill(0xAACCDD, 1);
				drawRect(objX,objY,objWidth, objHeight);
				endFill()
			}
			obj.buttonMode = true;
		}
	}
}

There is the file with .air extension: Animation Window

Tags: , , , ,

Native Window

February 24th, 2009 | 3 Comments | Posted in AIR, ActionScript 3.0

I apologize for my absence, but I have same problems. Well today I make something very easy and basic for a AIR aplication. The aplication had to be ready yesterday, put the develop platform makes me same troubles. The aplication name is Native Window, well this aplication prcatic will open a new window inside the first. Here is the code:

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
package
{
	     // ----------------------------------------
        //  Imports
       // ----------------------------------------
 
     //Import the MovieClip-- for the Constructor and for the button
	import flash.display.MovieClip;
	//Import the NativeWidow  of course for the New Native WIndow that will be created
	import flash.display.NativeWindow;
	//Import the MouseEvent for the button Mouse Click
	import flash.events.MouseEvent;
	/*And finaly will import the NativeWindowInitOptions 
	fot the future options that will be applied on the NativeWindow*/
	import flash.display.NativeWindowInitOptions;
 
	public class main extends MovieClip
	{
		 // ----------------------------------------
        //   Variables
       // ----------------------------------------
 
		  //Same private variables which will help us in the following private methodes
		//The newWin represents the NativeWindow
		public var newWin:NativeWindow;
		//This represents the button that will open the NativeWindow
		public var myButton:MovieClip = new MovieClip();
		//And this are the Native Window Option
		public var init:NativeWindowInitOptions = new NativeWindowInitOptions();
 
		public function main():void
		{
		  // ----------------------------------------
         //  CONSTRUCTOR
        // ---------------------------------------
 
			// I set the resizable option "true"
			init.resizable = true;
			//I set the maximizable option  "false"
			init.maximizable = false;
			//And the minimizable option "true"
			init.minimizable = true;
			//Init the drawButton function, which will be described later
			drawButton(myButton);
			myButton.addEventListener(MouseEvent.CLICK, openWindow);
		}
		  // ----------------------------------------
         //  Private Methods
        // ----------------------------------------
 
		private function drawButton(obj:MovieClip):void
		{
			with(obj.graphics)
			{
				// Draw the rect for the button
				beginFill(0xAAEECC, 1);//Set the Color and the Alpha
				drawRect(10,10,100,20);//Set the position
				endFill();
			}
			addChild(obj);
			obj.buttonMode = true; //Give the buttonMode to the obj
		}
 
		  // ----------------------------------------
         //  Private Methods
        // ----------------------------------------
 
		private function openWindow(e:MouseEvent):void
		{
			newWin = new NativeWindow(init); //Initialize the Native Window
            newWin.activate(); //Activate the Window
			//Set the position
			newWin.height = 200;
			newWin.width = 300;
			//Give a name
			newWin.title = "My First New Win!";
		}
	}
}

I hope you like it. There is the file with .air extension: Native Window

Tags: , , ,

Simple Web Browser

February 14th, 2009 | No Comments | Posted in AIR, ActionScript 3.0

Well, this is a new categorie in my blog, her name is AIR, this Adobe AIR is a cross-platform runtime environment for building rich Internet applications using Adobe Flash, Adobe Flex, HTML, or Ajax, that can be deployed as a desktop application. This first project is a Web Browser, a very simple Web Browser

Here is the code and the comments:

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
package
{
	     // ----------------------------------------
        //  Imports
       // ----------------------------------------
 
	import flash.display.Sprite;
	import flash.html.HTMLLoader;
	import flash.net.URLRequest;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.KeyboardEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFieldType;
 
	public class MyHTML extends Sprite
	{
		 // ----------------------------------------
        //   Variables
       // ----------------------------------------
	      //Same private variables which will help us in the following private methodes
 
		public var urlReq:URLRequest = new URLRequest("http://www.google.com");
		public var myHTML:HTMLLoader = new HTMLLoader();
		public var address_txt:TextField = new TextField();
		public var address_btn:Sprite = new Sprite();
		public var addressLabel_txt:TextField = new TextField();
 
		  // ----------------------------------------
         //  CONSTRUCTOR
        // ---------------------------------------
 
		public function MyHTML()
		{
 
			myHTML.width = stage.stageWidth; //Set the myHTML width
			myHTML.height = stage.stageHeight - address_txt.y; //Set the myHTML
			myHTML.load(urlReq); //Load the first page in the browser
 
			with(address_txt)
			//Set the address_txt option
			{
				border = true;
				type = TextFieldType.INPUT; // The tipe of the address_txt must be Input
				x = 18; //Set the x
				y = 5; //Set the y
				width = 360; //Set the width
				height = 22; //Set the height
				text = "http://www.google.com"; // This is the text how is in the address_txt
				background = true;
				backgroundColor = 0xFFFFFF; //Set the color
			}
 
			with(address_btn)
			// Draw the rect for the button
			{
				graphics.beginFill(0xFFFFFF, 1); //Ste the Color and the Alpha
				graphics.drawRect(400,5,50,20); // Set the x, the y and the position of the rect
				graphics.endFill();
				buttonMode = true; //Set the button Mode
			}
 
			with(addressLabel_txt)
			{
				x = 400;
				y = 5;
				text = "GO!"
				autoSize = TextFieldAutoSize.LEFT;
				selectable = false;
				mouseEnabled = false;
			}
 
			//Add to the stage: myHTML, address_txt, address_btn and addressLabel_txt
			addChild(myHTML);
			addChild(address_txt);
			addChild(address_btn);
			addChild(addressLabel_txt);
			//Set the myHTML position
			myHTML.x = 0;
			myHTML.y = this.address_txt.y + this.address_txt.height + 5;
			address_btn.addEventListener(MouseEvent.CLICK, viewPageHandler);
			stage.addEventListener(KeyboardEvent.KEY_DOWN, viewPageHandlerByEnter);
		}
 
		  // ----------------------------------------
         //  Private Methods
        // ----------------------------------------
 
		private function viewPageHandler(event:MouseEvent)
		//This load the URL and transform to a page content
		{
			urlReq = new URLRequest(address_txt.text);
			myHTML.load(urlReq);
		}
 
		private function viewPageHandlerByEnter(event:KeyboardEvent)
		//Well this make the same thing but if you press Enter
		{
			if(event.keyCode == 13)
			{
				urlReq = new URLRequest(address_txt.text);
				myHTML.load(urlReq);
			}
		}
	}
}
 
//Remember this is Air not Flash, the HTMLLoader not work in a flash project.

Well this is a very simple Web Browser. And I say again this is a Air project , not a Flash project, and the HTMLLoader not works on a Flash project
Here is the result:Web Browser

Tags: , , , ,

X,Y,Z Inspector

February 7th, 2009 | 2 Comments | Posted in ActionScript 3.0

I started to read a AS 3.0 book and i found something very interesting, this interesting thing is this:

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
package
{
	     // ----------------------------------------
        //  Imports
       // ----------------------------------------
 
	import flash.display.MovieClip;
	import flash.display.Loader;
	import flash.text.TextField;
	import flash.utils.setInterval;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
 
	public class Inspector extends MovieClip
	{
		 // ----------------------------------------
        //  Private Variables
       // ----------------------------------------
	      //Same private variables which will help us in the following private methodes
 
		public var rotateX_mc:MovieClip = new MovieClip();
		public var rotateY_mc:MovieClip = new MovieClip();
		public var rotateZ_mc:MovieClip = new MovieClip();
		public var resetAll_mc:MovieClip = new MovieClip();
		public var menu:Array = [[rotateX_mc, 0xFFAACC, "X Rotation"],
							     [rotateY_mc, 0xAABBCC, "Y Rotation"],
								 [rotateZ_mc, 0xDD7766, "Z Rotation"],
								 [resetAll_mc, 0xEEAA44, "Reset All"]];
 
		// These variables determinate the space between buttons
		//Also the height and width of each of them
		//And the speed of object rotation
 
		public var rotationSquare:MovieClip = new MovieClip();
		public var speed:int = 2;
 
		public var spacing:Number = 60;
		public var squareWidth:Number = 70;
		public var squareHeight:Number = 30;
 
		public var rotateX:Boolean;
		public var rotateY:Boolean;
		public var rotateZ:Boolean;
 
		  // ----------------------------------------
         //  CONSTRUCTOR
        // ---------------------------------------
		   // Here, the cod will place each button on yhe X aix at regular intervals
		   //And will assign the setRotation() method
 
		public function Inspector():void
 
		{
			for(var i:Number=0; i < menu.length; i++)
			{
				var rotationValue:TextField = new TextField();
				rotationValue.selectable = false;
				rotationValue.mouseEnabled = false;
				drawingSquare(menu[i][0], menu[i][1]);
				menu[i][0].x = (spacing + 20) * i;
				rotationValue.text = menu[i][2];
				menu[i][0].addChild(rotationValue);
				menu[i][0].addEventListener(MouseEvent.CLICK, setRotation);
			}
			drawingObject();
			setInterval(rotateIt , 20);
		}
 
		  // ----------------------------------------
         //  Private Methods
        // ----------------------------------------
 
		private function drawingSquare(obj:MovieClip, color:uint):void
		    // The drawingSquare() method will alow you to create a rectangular shape each time it's invoked
		{
			with(obj.graphics)
			{
				beginFill(color, 1);
				moveTo(0,0);
				lineTo(squareWidth, 0);
				lineTo(squareWidth, squareHeight);
				lineTo(0, squareHeight);
				endFill();
			}
			this.addChild(obj);
		}
 
		private function drawingObject():void
		   // The drawingObject() method place the square on the stage
		{
			var pathPhoto:URLRequest = new URLRequest("http://www.stratulat.com/blog/wp-content/air_appicon-tn.gif");
			var loader:Loader = new Loader();
			loader.load(pathPhoto);
			rotationSquare.addChild(loader);
			rotationSquare.x = stage.stageWidth * 0.5;
			rotationSquare.y = stage.stageHeight * 0.5;
			this.addChild(rotationSquare);
		}
 
		private function rotateIt():void
		    // This part will allow you to mange the animation using the setInterval() method
		{
			if(rotateX)
			{
				rotationSquare.rotationX+=speed;
			}
			if(rotateY)
			{
				rotationSquare.rotationY+=speed;
			}
			if(rotateZ)
			{
				rotationSquare.rotationZ+=speed;
			}
		}
 
		private function setRotation(event:MouseEvent):void
		    // This last method monitors the status of the three Boolean variables: rotateX, rotateY, rotateZ
		{
			switch(event.currentTarget)
			{
				case rotateX_mc:
				rotateX = true;
				rotateY = false;
				rotateZ = false;
				break;
 
				case rotateY_mc:
				rotateX = false;
				rotateY = true;
				rotateZ = false;
				break;
 
				case rotateZ_mc:
				rotateX = false;
				rotateY = false;
				rotateZ = true;
				break;
 
				case resetAll_mc:
				rotateX = false;
				rotateY = false;
				rotateZ = false;
 
				rotationSquare.rotationX = 0;
				rotationSquare.rotationY = 0;
				rotationSquare.rotationZ = 0;
			}
		}
	}
}

Here is the final result:

I hope you like, see ya next time.
Have Fun!

Tags: , , , , ,

AS 3.0 XML MP3 Player

February 2nd, 2009 | 41 Comments | Posted in ActionScript 3.0

Hey, I came back with something new and interesting, I make a Mp3 Player. Is not a very advenced but is not so easy to understud if you are new in this. Here is the code, and if you whant to ask me something leave me a comment.

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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
/**
	 * Author: Horatiu Condrea ( http://www.flashdesign-store.com )
	 * Description: AS 3.0 MP3 Player
**/
 
    // -------------------------------------
    // Imports
    // -------------------------------------
 
//I import the TweenMax class because, she helps me to make same tween in the stage
import gs.TweenMax;
import gs.easing.*;
 
stage.scaleMode = StageScaleMode.NO_SCALE;
 
    // -------------------------------------
    // Variables
    // -------------------------------------
 
var sound:Sound = new Sound();
var musicReq:URLRequest;
 
//The BytesArray helps me to "see" the sound bytes and the transform to a spectrum
var ba:ByteArray = new ByteArray();
var buffer:SoundLoaderContext;
var sc:SoundChannel;
var st:SoundTransform;
var isPlaying:Boolean = true;
var pos:Number;
var currentSound:Sound = sound;
 
var xml:XML;
var songlist:XMLList;
var currentIndex:Number = 0;
 
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, whenLoaded);
 
//Here we load in our XML and create a function that will run when our loader has completed loading
 
function whenLoaded(e:Event):void
{
	xml = new XML(e.target.data);
	songlist = xml.song;
	musicReq = new URLRequest(songlist[0].url);
	sound.load(musicReq);
	sc = sound.play();
	title_txt.text = songlist[0].title; //I load the <title> of the XML file
	nr_txt.text = songlist[0].number;   //I load the <number> of the XML file
	gen_txt.text = songlist[0].gen;     //I load the <gen> of the XML file
}
//My XML file name is "main.xml" and in this part I load the XML
loader.load(new URLRequest("main.xml"));
 
// I created these 2 variables(bmd and bm)
// Because the filter must know where to act
var bmd:BitmapData = new BitmapData(512, 300, true, 0x000000);
var bm:Bitmap = new Bitmap(bmd);
addChild(bm);
 
//I create a new Sprite for the spectrum line
var sp:Sprite = new Sprite();
addChild(sp);
 
var blur:BlurFilter = new BlurFilter(8,8,2); // Set the BlurFilter Effect
 
var colorMatrix:ColorMatrixFilter = new ColorMatrixFilter
([1 ,0, 0, 0, 0,
  0, 1, 0, 0, 0,           // Set the ColorMatrixFilter Effect
  0, 0, 1, 0, 0,
  0, 0, 0, 0.96, 0]);
 
    // -------------------------------------
    // Stage Objects
    // -------------------------------------
 
//Well in this part I put the objects on the stage,my object are Exporting to ActionScript, and the objects are in my library.
//Some mathematical stufe
var bar_a = new Bar_a();
addChild(bar_a);
bar_a.y = stage.stageHeight * 0.5 - 25;
bar_a.x = stage.stageWidth * 0.5;
 
var bar_b = new Bar_b();
addChild(bar_b);
bar_b.y = stage.stageHeight * 0.5 + 25;
bar_b.x = stage.stageWidth * 0.5;
 
var play_btn = new Play();
addChild(play_btn);
play_btn.y = stage.stageHeight * 0.5 - 15;
play_btn.x = 80;
play_btn.scaleX = 1.2;
play_btn.scaleY = 1.2;
 
var stop_btn = new Stop();
addChild(stop_btn);
stop_btn.y = stage.stageHeight * 0.5 - 15;
stop_btn.x = 40;
stop_btn.scaleX = 1.2;
stop_btn.scaleY = 1.2;
 
var pause_btn = new Pause();
addChild(pause_btn);
pause_btn.y = stage.stageHeight * 0.5 - 15;
pause_btn.x = 60;
pause_btn.scaleX = 1.2;
pause_btn.scaleY = 1.2;
 
var next_btn = new Next();
addChild(next_btn);
next_btn.y = stage.stageHeight * 0.5 - 15;
next_btn.x = 100;
next_btn.scaleX = 1.2;
next_btn.scaleY = 1.2;
 
var prev_btn = new Prev();
addChild(prev_btn);
prev_btn.y = stage.stageHeight * 0.5 - 11;
prev_btn.x = 20;
prev_btn.scaleX = 1.2;
prev_btn.scaleY = 1.2;
 
var volume_mc = new Volume();
addChild(volume_mc);
volume_mc.y = stage.stageHeight * 0.5 + 10;
volume_mc.x = 325;
 
buffer = new SoundLoaderContext(5000)
 
    // -------------------------------------
    // Buttons &#038; Function
    // -------------------------------------
 
//Now we'll add some Mouse Events for our buttons on the MP3 Player and give them some functions
 
stop_btn.addEventListener(MouseEvent.CLICK, stopSound);
function stopSound(e:MouseEvent):void
{
	SoundMixer.stopAll(); //With this function I stop all the music
	isPlaying = false;
}
 
pause_btn.addEventListener(MouseEvent.CLICK, pauseSound);
function pauseSound(e:MouseEvent):void
{
	//Well, if you look over the variables, I will find the "pos:number" variable, this will take the muisc position and then I stope the music because is a pause_btn
	pos = sc.position;
	sc.stop();
	isPlaying = false;
}
 
play_btn.addEventListener(MouseEvent.CLICK, playSound);
function playSound(e:MouseEvent):void
{
	//Here I start the muzic, but I start the muisc in the "pos" position
	if(isPlaying == false)
	{
		sc = currentSound.play(pos);
 
		isPlaying = true;
	}
 
}
 
next_btn.addEventListener(MouseEvent.CLICK, nextSong);
function nextSong(e:Event):void
//Well in this function I start the next song, if you are clicking on the next_btn
{
	if (currentIndex < (songlist.length() + 1))
	{
		currentIndex++;
	}
	else
	{
		currentIndex = 0;
	}
 
	var nextReq:URLRequest = new URLRequest(songlist[currentIndex].url);
	var nextTitle:Sound = new Sound(nextReq);
	sc.stop();
	title_txt.text = songlist[currentIndex].title;//I load the<title>of the XML file
	nr_txt.text = songlist[currentIndex].number;//I load the<number>of the XML file
	gen_txt.text = songlist[currentIndex].gen;//I load the <gen> of the XML file
	sc = nextTitle.play();
	isPlaying = true;
	currentSound = nextTitle;
}
 
prev_btn.addEventListener(MouseEvent.CLICK, prevSong);
function prevSong(e:Event):void
//Here I start the previos song
{
	if (currentIndex < (songlist.length() - 1))
	{
		currentIndex++;
	}
	else
	{
		currentIndex = 0;
	}
 
	var nextReq:URLRequest = new URLRequest(songlist[currentIndex].url);
	var nextTitle:Sound = new Sound(nextReq);
	sc.stop();
	title_txt.text = songlist[currentIndex].title;
	nr_txt.text = songlist[currentIndex].number;//Again load the number, gen and title of the XML file
	gen_txt.text = songlist[currentIndex].gen;
	sc = nextTitle.play();
	isPlaying = true;
	currentSound = nextTitle;
}
 
    // -------------------------------------
    // Spectrums
    // -------------------------------------
 
addEventListener(Event.ENTER_FRAME, loop_a);
addEventListener(Event.ENTER_FRAME, loop_b);
 
function loop_a(e:Event):void
//Well here is the first spectrum
{
	sp.graphics.clear();
	sp.graphics.lineStyle(2, 0xfffff0);//Select a color and a thickness for the line spectrum
	sp.graphics.moveTo(-5, 50); //I put my target for line
	SoundMixer.computeSpectrum(ba);
	for(var i:uint=0; i<256; i++)
	{
		var num:Number = -ba.readFloat()*50 + 50;
		sp.graphics.lineTo(i*2, num);
	}
	bmd.draw(sp);
	// Apply the filter effects to line
	bmd.applyFilter(bmd,bmd.rect,new Point(),blur);
	bmd.applyFilter(bmd,bmd.rect,new Point(),colorMatrix);
	bmd.scroll(3,0);
}
 
function loop_b(e:Event):void
//Here is the second spectrum, and it is make with the same way
{
	sp.graphics.clear();
	sp.graphics.lineStyle(2, 0xfffff0);
	sp.graphics.moveTo(-1, 250);
	SoundMixer.computeSpectrum(ba);
	for(var i:uint=0; i<256; i++)
	{
		var num:Number = -ba.readFloat()*50 + 250;
		sp.graphics.lineTo(i*2, num);
	}
	bmd.draw(sp);
	bmd.applyFilter(bmd,bmd.rect,new Point(),blur);
	bmd.applyFilter(bmd,bmd.rect,new Point(),colorMatrix);
	bmd.scroll(3,0);
}
 
    // -------------------------------------
    // Progrss Bar
    // -------------------------------------
 
progress_mc.addEventListener(MouseEvent.CLICK, setNewProgress);
addEventListener(Event.ENTER_FRAME, calcProgress);
 
function calcProgress(e:Event):void
//In this function I caluclate the music progress for the Progrss Bar
{
	var p:MovieClip = this.progress_mc.mcProgressFill;
	var w:uint		= Math.round( 175 * sc.position / currentSound.length);
	p.width 		= w;
}
 
function setNewProgress(e:MouseEvent):void
{
	var t:uint = currentSound.length * e.currentTarget.mouseX / 175;
	sc.stop();
	sc = currentSound.play(t);
}
 
    // -------------------------------------
    // Volume
    // -------------------------------------
 
var drag:Boolean = false;
var rectangle:Rectangle = new Rectangle(0,0,150,0);//I create a new rectangle
volume_mc.slider_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragIt);
stage.addEventListener(MouseEvent.MOUSE_UP, dropIt);
 
volume_mc.slider_mc.buttonMode = true;
 
function dragIt(e:Event):void
{
	volume_mc.slider_mc.startDrag(false,rectangle);
	drag = true;
	volume_mc.slider_mc.addEventListener(Event.ENTER_FRAME, adjustVolume);
}
 
function adjustVolume(e:Event):void
{
	var vol:Number = volume_mc.slider_mc.x / 150;
	var st:SoundTransform = new SoundTransform(vol);
	if (sc != null)
	{
		sc.soundTransform = st;
	}
}
 
function dropIt(e:Event):void
{
	if (drag)
	{
		volume_mc.slider_mc.stopDrag();
		drag = false;
	}
}
 
    // -------------------------------------
    // Buttons Effects
    // -------------------------------------
 
//Well, here is going to helps me the TweenMax, Here is runing the same effect, but it is put in the all buttons
play_btn.addEventListener(MouseEvent.ROLL_OVER, rollover)
function rollover(e:MouseEvent):void
{
	TweenMax.to(play_btn, 1, {colorMatrixFilter:{colorize:0x666666, amount:1}});
}
 
play_btn.addEventListener(MouseEvent.ROLL_OUT, rollout)
function rollout(e:MouseEvent):void
{
	TweenMax.to(play_btn, 1, {colorMatrixFilter:{colorize:0xffffff, amount:1}});
}
 
stop_btn.addEventListener(MouseEvent.ROLL_OVER, rollover_b)
function rollover_b(e:MouseEvent):void
{
	TweenMax.to(stop_btn, 1, {colorMatrixFilter:{colorize:0x666666, amount:1}});
}
 
stop_btn.addEventListener(MouseEvent.ROLL_OUT, rollout_b)
function rollout_b(e:MouseEvent):void
{
	TweenMax.to(stop_btn, 1, {colorMatrixFilter:{colorize:0xffffff, amount:1}});
}
 
pause_btn.addEventListener(MouseEvent.ROLL_OVER, rollover_c)
function rollover_c(e:MouseEvent):void
{
	TweenMax.to(pause_btn, 1, {colorMatrixFilter:{colorize:0x666666, amount:1}});
}
 
pause_btn.addEventListener(MouseEvent.ROLL_OUT, rollout_c)
function rollout_c(e:MouseEvent):void
{
	TweenMax.to(pause_btn, 1, {colorMatrixFilter:{colorize:0xffffff, amount:1}});
}
 
next_btn.addEventListener(MouseEvent.ROLL_OVER, rollover_d)
function rollover_d(e:MouseEvent):void
{
	TweenMax.to(next_btn, 1, {colorMatrixFilter:{colorize:0x666666, amount:1}});
}
 
next_btn.addEventListener(MouseEvent.ROLL_OUT, rollout_d)
function rollout_d(e:MouseEvent):void
{
	TweenMax.to(next_btn, 1, {colorMatrixFilter:{colorize:0xffffff, amount:1}});
}
 
prev_btn.addEventListener(MouseEvent.ROLL_OVER, rollover_e)
function rollover_e(e:MouseEvent):void
{
	TweenMax.to(prev_btn, 1, {colorMatrixFilter:{colorize:0x666666, amount:1}});
}
 
prev_btn.addEventListener(MouseEvent.ROLL_OUT, rollout_e)
function rollout_e(e:MouseEvent):void
{
	TweenMax.to(prev_btn, 1, {colorMatrixFilter:{colorize:0xffffff, amount:1}});
}
 
volume_mc.slider_mc.addEventListener(MouseEvent.ROLL_OVER, rollover_f)
function rollover_f(e:MouseEvent):void
{
	TweenMax.to(volume_mc.slider_mc, 1, {colorMatrixFilter:{colorize:0x666666, amount:1}});
}
 
volume_mc.slider_mc.addEventListener(MouseEvent.ROLL_OUT, rollout_f)
function rollout_f(e:MouseEvent):void
{
	TweenMax.to(volume_mc.slider_mc, 1, {colorMatrixFilter:{colorize:0xffffff, amount:1}});
}
stop();

Well don’t worry is not so hard to make it, but is more to write.
Here is the Mp3 Player:AS 3.0 Mp3 Player

Tags: , , , ,
Get Adobe Flash playerPlugin by wpburn.com wordpress themes