EzeQL's Blog Actionscript and more..

30Apr/081

Efecto Tv Rota (TV Noise)

Les dejo esta clase pequeña que desarrolle, tvNoise

[SWF]

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
package  {
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.utils.getTimer;
	import flash.utils.Timer;
 
	/**
	* ...
	* @author EzeQL
	* @see www.EzeQL.com/blog
	*/
 
	public class NoiseTV extends Sprite {
		private var _bitmap:Bitmap;
		private var _bitmapData:BitmapData;
 
		private var _bmpWidth:int;
		private var _bmpheight:int;
 
		private var _timer:Timer;
 
		public function NoiseTV(pWidth:int=400,pHeight:int=300)
		{
			_bitmapData  = new BitmapData(pWidth, pHeight, false, 0x000000);
			_bitmap = new Bitmap(_bitmapData);
 
			_bmpheight = pHeight;
			_bmpWidth = pWidth;
		}
 
		public function start():void
		{
			addChild(_bitmap);
			//Prueben Usar Ambos :=>
			this.addEventListener(Event.ENTER_FRAME, NoiseTV_EnterFrame);
 
			//_timer = new Timer(50);
			//_timer.addEventListener(TimerEvent.TIMER, Timer_TimerEvent);
			//_timer.start();
		}
 
		public function stop():void
		{
			this.removeEventListener(Event.ENTER_FRAME, NoiseTV_EnterFrame);
			//_timer.stop();
 
		}
 
		private function drawNoise():void
		{
			var seed:int = int(Math.random() * int.MAX_VALUE);
			//_bitmapData.lock();
			_bitmapData.noise(seed, 0, 255, 0, true); // este hermoso metodo hace todo el trabajo por nosotros :) :)
			//_bitmapData.unlock(); // para este uso no gana performance ..pruebenlo ustedes.
 
		}
 
		public function restart():void
		{
			stop();
			removeChild(_bitmap);
			_bitmapData  = new BitmapData(_bmpWidth, _bmpheight, false, 0x000000);
			_bitmap = new Bitmap(_bitmapData);
			start();
 
		}
 
			private function NoiseTV_EnterFrame (event:Event):void
		{
			//var inicio:uint = getTimer();
			drawNoise();
			//trace(getTimer() - inicio);
		}
 
		private function Timer_TimerEvent(event:TimerEvent):void
		{
			//var inicio:uint = getTimer();
			drawNoise();
			//event.updateAfterEvent(); => en nuestro caso no tiene sentido :)
			//trace(getTimer() - inicio);
 
		}
 
 
		public function get bmpheight():int { return _bmpheight; }
 
		public function set bmpheight(value:int):void {
			_bmpheight = value;
		}
 
		public function get bmpWidth():int { return _bmpWidth; }
 
		public function set bmpWidth(value:int):void {
			_bmpWidth = value;
		}
 
 
 
	}
 
}

clase Main,Ejemplo de uso

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
 
package  {
	import flash.display.Sprite;
	import flash.events.MouseEvent;
 
	/**
	* ...
	* @author EzeQL
	* @see www.EzeQL.com/blog
	*/
	public class Main extends Sprite{
		private var noiseTv:NoiseTV;
 
		public function Main() {
			noiseTv = new NoiseTV();
 
			addChild(noiseTv);
			noiseTv.start();
 
			stage.addEventListener(MouseEvent.CLICK, Stage_Click);
		}
 
		private function Stage_Click(e:MouseEvent):void
		{
			noiseTv.bmpheight = Math.random() * stage.stageHeight;
			noiseTv.bmpWidth = Math.random() * stage.stageWidth
			noiseTv.restart();
 
		}
 
	}
 
}
Comments (1) Trackbacks (0)
  1. hola, soy de barcelona, conozco ActionScript aunque me gustaria actualizarme a 3.0 Alguien me puede informar sobre una buena formación en barcelona o madrid?
    salud


Leave a comment


No trackbacks yet.