Archive for April, 2008

Les dejo esta clase pequeña que desarrolle, tvNoise

This movie requires Flash Player 9

?View Code ACTIONSCRIPT
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

?View Code ACTIONSCRIPT
 
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();
 
		}
 
	}
 
}

Posted by admin in Actionscript 3 | No Comments

La clase SimpleButton proporciona una forma fácil de crear los típicos estados de un botón pasandole  las imagenes de los estados que este mostrara.

Ejemplo:

This movie requires Flash Player 9

?View Code ACTIONSCRIPT
package
{
import flash.display.Graphics;
import flash.display.Shape;
import flash.display.SimpleButton;
import flash.display.Sprite;
import caurina.transitions.Tweener;
import flash.events.MouseEvent;
import flash.filters.DropShadowFilter;
import flash.geom.Rectangle;
 
public class Main extends Sprite
{
/*www.ezeql.com*/
private var _button_on:Sprite;
private var _button_out:Sprite;
private var _button_press:Sprite;
 
private var _simpleButton:SimpleButton;
 
public function Main():void
{
_button_on = new Sprite();
_button_out = new Sprite();
_button_press = new Sprite();
 
_button_on.addChild(drawButton(0xff0000));
_button_on.filters = [new DropShadowFilter()];
 
_button_out.addChild(drawButton(0x00ff00));
_button_out.filters = [new DropShadowFilter(8)];
 
_button_press.addChild(drawButton(0x0000ff));
_button_press.filters = [new DropShadowFilter(15)];
 
_simpleButton = new SimpleButton(_button_on, _button_out, _button_press,_button_on);
_simpleButton.x = 150;
_simpleButton.y = 125;
 
_simpleButton.addEventListener(MouseEvent.CLICK, SimpleButton_Click);
 
addChild(_simpleButton);
}
 
private function SimpleButton_Click(e:MouseEvent):void
{
trace("click");
}
 
private function drawButton(pColor:uint ):Shape
{
var _rect:Shape = new Shape();
with (_rect.graphics)
{
lineStyle(1);
beginFill(pColor);
drawCircle(0,0,100);
 
}
return _rect;
}
 
}
}

Posted by admin in Actionscript 3 | 1 Comment

Apr. 27, 2008

Uso de Tweener - Tutorial 1

Tweener es una libreria OpenSource para crear “Tweens” de Manera Facil y rapida.
Esta Lib es muy util para alcanzar resultados rapidos y de calidad.

Existen versiones en AS2 para Flash 7 , AS2 para Flash 8 y AS3.Tambien Existen Ports en HaXe y JavaScript.

El proyecto esta hosteado en Google Code: http://code.google.com/p/tweener/

Podemos bajarnos un Release en la solapa Downloads o sincronizarnos via SVN : http://tweener.googlecode.com/svn/trunk/

La documentacion se encuentra en la pagina del Desarrollador del proyecto: http://hosted.zeh.com.br/tweener/docs/en-us/

Nuestro Primer Ejemplo : Tween perpetuo en X,Y y rotation

This movie requires Flash Player 9

?View Code ACTIONSCRIPT
 
package
{
	import flash.display.Sprite;
	import caurina.transitions.Tweener;
 
	public class Main extends Sprite
	{
		private var _sprite:Sprite;
 
		public function Main():void
		{
			_sprite = new Sprite();
			_sprite.graphics.beginFill(0x3399FF, 1);
			_sprite.graphics.drawCircle(0, 0, 25);
			_sprite.graphics.beginFill(0xFF00FF, 1);
			_sprite.graphics.drawRect( -10, -10, 20, 20);
			addChild(_sprite);
			step();
		}
 
		private function step():void
		{
			Tweener.addTween(_sprite, { time:.5, delay:.2, x:Math.random() * stage.stageWidth, y:Math.random() * stage.stageHeight, rotation:Math.random() * 360, transition:"linear",onComplete:step } );
		}
	}
}

Posted by admin in Actionscript 3 | No Comments

En este primer post voy a mostrar el uso basico de Eventos en AS3

This movie requires Flash Player 9

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
package  {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextField;
 
/**
* ...
* @author EzeQL
* @see WWW.EZEQL.COM/BLOG
*/
 
public class EventosIntro extends Sprite {
private var _box:Sprite;
private var _tf:TextField;
private var _click:int = 0;
 
private const VECES_CLICK:String = " veces clickeado";
 
public function EventosIntro() {
draw();
initListeners();
}
 
private function draw():void {
_box = new Sprite();
_box.graphics.lineStyle(1, 0);
_box.graphics.beginFill(0xFF0000);
_box.graphics.drawCircle(50, 75, 50);
_box.graphics.endFill();
_box.alpha = 0.4;
addChild(_box);
 
_tf = new TextField();
_tf.selectable = false;
_tf.textColor = 0x0000ff;
_tf.autoSize = flash.text.TextFieldAutoSize.LEFT;
updateText();
 
addChild(_tf);
}
 
private function initListeners():void {
_box.addEventListener(MouseEvent.CLICK, onBoxCLick, false, 0, true);
_box.addEventListener(MouseEvent.MOUSE_OVER, onBoxOver, false, 0, true);
_box.addEventListener(MouseEvent.MOUSE_OUT, onBoxOut, false, 0, true);
}
 
private function onBoxOut(e:MouseEvent):void {
_box.alpha = .4;
}
 
private function onBoxOver(e:MouseEvent):void {
_box.alpha = 1;
}
 
private function onBoxCLick(e:MouseEvent):void {
_click++;
_box.x++;
_box.y++;
updateText();
}
 
private function updateText():void{
_tf.text = _click.toString() + VECES_CLICK;
}
}
}

Posted by admin in Actionscript 3 | No Comments