<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>digilabs.com.ar &#187; Actionscript</title>
	<atom:link href="http://digilabs.com.ar/category/actionscript/feed" rel="self" type="application/rss+xml" />
	<link>http://digilabs.com.ar</link>
	<description>Let's code!!!</description>
	<lastBuildDate>Tue, 24 Jan 2012 00:14:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>columnas y filas dinamicas en flash</title>
		<link>http://digilabs.com.ar/2011/06/actionscript/columnas-filas-dinamicas-en-flash</link>
		<comments>http://digilabs.com.ar/2011/06/actionscript/columnas-filas-dinamicas-en-flash#comments</comments>
		<pubDate>Fri, 24 Jun 2011 14:37:36 +0000</pubDate>
		<dc:creator>Andrés Argüello Pitt</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS3]]></category>

		<guid isPermaLink="false">http://digilabs.com.ar/?p=1450</guid>
		<description><![CDATA[Varias veces me encuentro en la posición de tener que acomodar movieclips dinamicamente en el escenario de forma ordenada. Por ejemplo crear una matriz de imagenes para una galleria. Aqui dejo un pequeno snipet que permite justamente hacer eso 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 [...]]]></description>
			<content:encoded><![CDATA[<p>Varias veces me encuentro en la posición de tener que acomodar movieclips dinamicamente en el escenario de forma ordenada. Por ejemplo crear una matriz de imagenes para una galleria.<br />
 Aqui dejo un pequeno snipet que permite justamente hacer eso</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> separacionX:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">100</span>;
<span style="color: #000000; font-weight: bold;">var</span> separacionY:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">50</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> fila:<span style="color: #0066CC;">Number</span>;
<span style="color: #000000; font-weight: bold;">var</span> columna:<span style="color: #0066CC;">Number</span>;
<span style="color: #000000; font-weight: bold;">var</span> numCols:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">3</span>;
<span style="color: #000000; font-weight: bold;">var</span> numeroDeItems:uint=<span style="color: #cc66cc;">100</span>;
&nbsp;
<span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>; i <span style="color: #66cc66;">&lt;</span> numeroDeItems; i++<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">var</span> _item:Item=<span style="color: #000000; font-weight: bold;">new</span> Item<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    fila  = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">floor</span><span style="color: #66cc66;">&#40;</span>i <span style="color: #66cc66;">/</span> numCols<span style="color: #66cc66;">&#41;</span>;
    columna= i - numCols <span style="color: #66cc66;">*</span> fila;
    _items.<span style="color: #006600;">x</span> = columna <span style="color: #66cc66;">*</span>  <span style="color: #66cc66;">&#40;</span>separacionX + _item.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">&#41;</span>;
    _items.<span style="color: #006600;">y</span> = fila <span style="color: #66cc66;">*</span>  <span style="color: #66cc66;">&#40;</span>separacionY + _item.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>;
    addChild<span style="color: #66cc66;">&#40;</span>_item<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://digilabs.com.ar/2011/06/actionscript/columnas-filas-dinamicas-en-flash/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eventos personalizado en AS3</title>
		<link>http://digilabs.com.ar/2010/10/actionscript/eventos-personalizado-en-as3</link>
		<comments>http://digilabs.com.ar/2010/10/actionscript/eventos-personalizado-en-as3#comments</comments>
		<pubDate>Wed, 06 Oct 2010 16:08:51 +0000</pubDate>
		<dc:creator>Andrés Argüello Pitt</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://digilabs.com.ar/?p=1201</guid>
		<description><![CDATA[Hasta hace muy poco tiempo siempre que tenia que hacer un script que esperar a que terminara la animacion de un moviclip para hacer otra cosa, lo que hacia era poner una variable en el ultimo frame de la aminacion del movieclip y luego usaba un setInterval o un onEnterFrame y adentro un if y [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-1202" style="float: left; margin-right: 8px;" title="event1" src="http://digilabs.com.ar/wp-content/uploads/2010/10/event1.jpg" alt="" width="250" height="180" />Hasta hace muy poco tiempo siempre que tenia que hacer un script que esperar a que terminara la animacion de un moviclip para hacer otra cosa, lo que hacia era poner una variable en el ultimo frame de la aminacion del movieclip y luego usaba un setInterval o un onEnterFrame y adentro un if y preguntaba si esa variable habia cambiado. <br /> Por ejemplo algo como:<br />
en el ultimo frame de la animación ponía</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"> <span style="color: #0066CC;">_root</span>.<span style="color: #006600;">termino</span>=<span style="color: #000000; font-weight: bold;">true</span>;
<span style="color: #0066CC;">stop</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>y luego en el root ponía</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;">miMovieClip_mc.<span style="color: #0066CC;">onEnterFrame</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
      <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">_root</span>.<span style="color: #006600;">termino</span>==<span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
             <span style="color: #0066CC;">trace</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;terminó la animación se prosigue con lo siguiente&quot;</span><span style="color: #66cc66;">&#41;</span>;
           <span style="color: #0066CC;">delete</span> miMovieClip_mc.<span style="color: #0066CC;">onEnterFrame</span>;
      <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>no creo que haya nada de malo en seguir utilizando este método si la aplicación es simple. cuando tenemos varios onEnterFrame o intervals dando vuelta al mismo tiempo.</p>
<p>AS3 se destaca por ser un leguage de programación más robusto y cuenta con todas las propiedades de los leguajes orientados a objetos, y una de esas cosas con los eventos. Por lo cual el dilema anterior queda reducido a simplemente poner un eventListener y luego disparar un evento cuando la animación termina.<br />
Ejemplo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> terminoAnimacion<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'terminó la animación'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
miMovieClip_mc.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;termino&quot;</span>, terminoAnimacion<span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>y luego en el último frame del movieClip disparamos el evento:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;">dispatchEvent<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Event<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;termino&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">stop</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://digilabs.com.ar/2010/10/actionscript/eventos-personalizado-en-as3/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mouseX y mouseY relativo a objetos distintos</title>
		<link>http://digilabs.com.ar/2010/09/actionscript/mousex-y-mousey-relativo-a-objetos-distintos</link>
		<comments>http://digilabs.com.ar/2010/09/actionscript/mousex-y-mousey-relativo-a-objetos-distintos#comments</comments>
		<pubDate>Fri, 24 Sep 2010 15:38:00 +0000</pubDate>
		<dc:creator>Andrés Argüello Pitt</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://digilabs.com.ar/?p=1185</guid>
		<description><![CDATA[Muchas veces necesitamos saber en donde ésta el mouse con respecto a algo. Y en cualquier momento podemos obtener su ubicación relativa al escenario o a un objeto de manera muy simple. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 import flash.events.MouseEvent; &#160; cuadrado_mc.addEventListener&#40;MouseEvent.MOUSE_OVER, onDown&#41;; function onDown&#40;e:MouseEvent&#41;:void &#123; e.target.addEventListener&#40;MouseEvent.MOUSE_MOVE,onMove&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p>Muchas veces necesitamos saber en donde ésta el mouse con respecto a algo. Y en cualquier momento podemos obtener su ubicación relativa al escenario o a un objeto de manera muy simple.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">MouseEvent</span>;
&nbsp;
cuadrado_mc.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_OVER</span>, onDown<span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">function</span> onDown<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_MOVE</span>,onMove<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> onMove<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">localX</span>,<span style="color: #0066CC;">e</span>.<span style="color: #006600;">localY</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    debug_txt.<span style="color: #0066CC;">htmlText</span>=<span style="color: #ff0000;">&quot;&lt;b&gt;entre del cuadrado&lt;/b&gt;<span style="color: #000099; font-weight: bold;">\n</span>x: &quot;</span>+<span style="color: #0066CC;">e</span>.<span style="color: #006600;">localX</span>+<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>y: &quot;</span>+<span style="color: #0066CC;">e</span>.<span style="color: #006600;">localY</span>+<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&lt;b&gt;mouse relativo al escenario&lt;/b&gt;<span style="color: #000099; font-weight: bold;">\n</span>x: &quot;</span>+mouseX+<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>y: &quot;</span>+mouseY;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>
<object width="450" height="200">
<param name="movie" value="http://digilabs.com.ar/wp-content/uploads/2010/09/local_test.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="opaque"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#00000"></param>
<embed type="application/x-shockwave-flash" width="450" height="200" src="http://digilabs.com.ar/wp-content/uploads/2010/09/local_test.swf" quality="high" bgcolor="#00000" wmode="opaque" menu="false" ></embed>
</object>
</p>
]]></content:encoded>
			<wfw:commentRss>http://digilabs.com.ar/2010/09/actionscript/mousex-y-mousey-relativo-a-objetos-distintos/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generar columnas en Flash</title>
		<link>http://digilabs.com.ar/2010/09/actionscript/generar-columnas-en-flash</link>
		<comments>http://digilabs.com.ar/2010/09/actionscript/generar-columnas-en-flash#comments</comments>
		<pubDate>Fri, 24 Sep 2010 11:00:10 +0000</pubDate>
		<dc:creator>Andrés Argüello Pitt</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS2]]></category>
		<category><![CDATA[AS3]]></category>

		<guid isPermaLink="false">http://digilabs.com.ar/?p=1180</guid>
		<description><![CDATA[Aca dejo un pequeño tip de como generar columnas en flash facilmente. La idea en usar un for pero no necesitar de hacer for añidados o usar contadores sino hacer todo en una sola línea usando el símbolo %. Con este &#8220;truquico&#8221; cada vez que i es divisible por 10 la vuelve cero de forma [...]]]></description>
			<content:encoded><![CDATA[<p>Aca dejo un pequeño tip de como generar columnas en flash facilmente.<br />
La idea en usar un for pero no necesitar de hacer for añidados o usar contadores sino hacer todo en una sola línea usando el símbolo %. Con este &#8220;truquico&#8221; cada vez que i es divisible por 10 la vuelve cero de forma que el contador en x de este ejemplo decrementa desde -250 de 50 en 50. Lo único valores que peude tomar x son entre -250 y 250  y varía de 50 en 50. Usando este método es muy fácil generar una grilla donde posicionamos elementos.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i : <span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>; i<span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">100</span>; i++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
<span style="color: #0066CC;">trace</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'x: '</span>+<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">%</span>10<span style="color: #66cc66;">&#41;</span>-<span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'y: '</span>+ <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span>-<span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #808080; font-style: italic;">//los traces de este ejemplo sería:</span>
<span style="color: #808080; font-style: italic;">/*
x: -250
y: -250
x: -200
y: -245.00000000000003
x: -150
y: -240
x: -100
y: -235
x: -50
y: -229.99999999999997
x: 0
y: -225
x: 50
y: -220.00000000000003
x: 100
y: -215
x: 150
y: -210
x: 200
y: -204.99999999999997
x: -250
y: -200
x: -200
y: -195
x: -150
y: -190
x: -100
y: -185
x: -50
y: -180
x: 0
y: -175
x: 50
y: -170
x: 100
y: -165
x: 150
y: -160
x: 200
...*/</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://digilabs.com.ar/2010/09/actionscript/generar-columnas-en-flash/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tierra en paperVision</title>
		<link>http://digilabs.com.ar/2010/09/actionscript/tierra-en-papervision</link>
		<comments>http://digilabs.com.ar/2010/09/actionscript/tierra-en-papervision#comments</comments>
		<pubDate>Thu, 23 Sep 2010 09:44:22 +0000</pubDate>
		<dc:creator>Andrés Argüello Pitt</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://digilabs.com.ar/?p=1169</guid>
		<description><![CDATA[Estuve jugando con PV3d en Flash Builder 4 y termine con este experimento. es el tipico Hello World, en este caso el nuestro mundo El experimento se trató de ver como se comportaban dos texturas una arriba de otra. lo que hice fue crear dos primitivas de, dos esferas, una esfera minimamente más grande que [...]]]></description>
			<content:encoded><![CDATA[<p>Estuve jugando con PV3d en Flash Builder 4 y termine con este experimento. es el tipico Hello World, en este caso el nuestro mundo <img src='http://digilabs.com.ar/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>El experimento se trató de ver como se comportaban dos texturas una arriba de otra. lo que hice fue crear dos primitivas de, dos esferas, una esfera minimamente más grande que la otra. Luego le apliqué una textura distinta a cada una.  finalmente agregue una particulas con un bitmap que simula ser una extrella.</p>
<p>Como toque final puse un onEnterFrame para renderizar la escena, mientras muevo giro en el eje de la Y ambas esferas a velocidades distintas y tambien muevo minimamente las particulas. Es bastante pesado para el procesador, pero no pain no gain.</p>
<p>
<object width="450" height="300">
<param name="movie" value="http://digilabs.com.ar/wp-content/uploads/2010/09/earth.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="opaque"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#00000"></param>
<embed type="application/x-shockwave-flash" width="450" height="300" src="http://digilabs.com.ar/wp-content/uploads/2010/09/earth.swf" quality="high" bgcolor="#00000" wmode="opaque" menu="false" ></embed>
</object>
</p>
<p>acá dejo el código:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;">package <span style="color: #66cc66;">&#123;</span>
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">BitmapData</span>;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
&nbsp;
<span style="color: #0066CC;">import</span> org.<span style="color: #006600;">papervision3d</span>.<span style="color: #006600;">core</span>.<span style="color: #0066CC;">math</span>.<span style="color: #006600;">Number3D</span>;
<span style="color: #0066CC;">import</span> org.<span style="color: #006600;">papervision3d</span>.<span style="color: #006600;">materials</span>.<span style="color: #006600;">special</span>.<span style="color: #006600;">MovieParticleMaterial</span>;
&nbsp;
<span style="color: #0066CC;">import</span> org.<span style="color: #006600;">papervision3d</span>.<span style="color: #006600;">core</span>.<span style="color: #006600;">geom</span>.<span style="color: #006600;">Particles</span>;
<span style="color: #0066CC;">import</span> org.<span style="color: #006600;">papervision3d</span>.<span style="color: #006600;">core</span>.<span style="color: #006600;">geom</span>.<span style="color: #006600;">renderables</span>.<span style="color: #006600;">Particle</span>;
<span style="color: #0066CC;">import</span> org.<span style="color: #006600;">papervision3d</span>.<span style="color: #006600;">lights</span>.<span style="color: #006600;">PointLight3D</span>;
<span style="color: #0066CC;">import</span> org.<span style="color: #006600;">papervision3d</span>.<span style="color: #006600;">materials</span>.<span style="color: #006600;">BitmapMaterial</span>;
<span style="color: #0066CC;">import</span> org.<span style="color: #006600;">papervision3d</span>.<span style="color: #006600;">materials</span>.<span style="color: #006600;">shaders</span>.<span style="color: #006600;">GouraudShader</span>;
<span style="color: #0066CC;">import</span> org.<span style="color: #006600;">papervision3d</span>.<span style="color: #006600;">materials</span>.<span style="color: #006600;">shaders</span>.<span style="color: #006600;">ShadedMaterial</span>;
<span style="color: #0066CC;">import</span> org.<span style="color: #006600;">papervision3d</span>.<span style="color: #006600;">materials</span>.<span style="color: #006600;">shaders</span>.<span style="color: #006600;">Shader</span>;
<span style="color: #0066CC;">import</span> org.<span style="color: #006600;">papervision3d</span>.<span style="color: #006600;">materials</span>.<span style="color: #006600;">special</span>.<span style="color: #006600;">BitmapParticleMaterial</span>;
<span style="color: #0066CC;">import</span> org.<span style="color: #006600;">papervision3d</span>.<span style="color: #006600;">materials</span>.<span style="color: #006600;">special</span>.<span style="color: #006600;">ParticleBitmap</span>;
<span style="color: #0066CC;">import</span> org.<span style="color: #006600;">papervision3d</span>.<span style="color: #006600;">materials</span>.<span style="color: #006600;">special</span>.<span style="color: #006600;">ParticleMaterial</span>;
<span style="color: #0066CC;">import</span> org.<span style="color: #006600;">papervision3d</span>.<span style="color: #006600;">objects</span>.<span style="color: #006600;">primitives</span>.<span style="color: #006600;">Sphere</span>;
<span style="color: #0066CC;">import</span> org.<span style="color: #006600;">papervision3d</span>.<span style="color: #006600;">objects</span>.<span style="color: #006600;">special</span>.<span style="color: #006600;">ParticleField</span>;
<span style="color: #0066CC;">import</span> org.<span style="color: #006600;">papervision3d</span>.<span style="color: #006600;">view</span>.<span style="color: #006600;">BasicView</span>;
&nbsp;
<span style="color: #66cc66;">&#91;</span>SWF <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;450&quot;</span>, <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;300&quot;</span>, <span style="color: #0066CC;">backgroundColor</span>=<span style="color: #ff0000;">&quot;0x000000&quot;</span>, frameRate=<span style="color: #ff0000;">&quot;30&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> earth <span style="color: #0066CC;">extends</span> BasicView
<span style="color: #66cc66;">&#123;</span>
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> sphere:Sphere;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> sphere2:Sphere;
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> light : PointLight3D;
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> shader : Shader;     
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> stars : ParticleField;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> cloudMaterial : BitmapMaterial;
&nbsp;
<span style="color: #66cc66;">&#91;</span>Embed <span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;/../assets/Earth.jpg&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> EarthMap : <span style="color: #000000; font-weight: bold;">Class</span>;
&nbsp;
<span style="color: #66cc66;">&#91;</span>Embed <span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;/../assets/star.png&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> particleBitmap : <span style="color: #000000; font-weight: bold;">Class</span>;
&nbsp;
<span style="color: #66cc66;">&#91;</span>Embed <span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;/../assets/earthcloudmap.png&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> CloudMap : <span style="color: #000000; font-weight: bold;">Class</span>;
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> particles : Particles;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> particle : Particle
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> counter : <span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span> ;
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> earth<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">500</span>,<span style="color: #cc66cc;">400</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> earthbmp:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> EarthMap<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">bitmapData</span>;
<span style="color: #000000; font-weight: bold;">var</span> earthmaterial:BitmapMaterial = <span style="color: #000000; font-weight: bold;">new</span> BitmapMaterial<span style="color: #66cc66;">&#40;</span>earthbmp<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> clouds : BitmapData = <span style="color: #000000; font-weight: bold;">new</span> CloudMap<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">bitmapData</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// luz</span>
light = <span style="color: #000000; font-weight: bold;">new</span> PointLight3D<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
light.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">300</span>;
light.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">300</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// tipo de shader que uso...</span>
&nbsp;
shader = <span style="color: #000000; font-weight: bold;">new</span> GouraudShader<span style="color: #66cc66;">&#40;</span>light, 0xFFFFFF,0x404040<span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">// y el material.</span>
<span style="color: #000000; font-weight: bold;">var</span> shadedmaterial:ShadedMaterial = <span style="color: #000000; font-weight: bold;">new</span> ShadedMaterial<span style="color: #66cc66;">&#40;</span>earthmaterial, shader<span style="color: #66cc66;">&#41;</span>;
shadedmaterial.<span style="color: #006600;">smooth</span>=<span style="color: #000000; font-weight: bold;">true</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//creo la primer esfera, la tierra</span>
sphere = <span style="color: #000000; font-weight: bold;">new</span> Sphere<span style="color: #66cc66;">&#40;</span>shadedmaterial, <span style="color: #cc66cc;">150</span>,<span style="color: #cc66cc;">24</span>,<span style="color: #cc66cc;">16</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//material para la nubes</span>
cloudMaterial = <span style="color: #000000; font-weight: bold;">new</span> BitmapMaterial<span style="color: #66cc66;">&#40;</span>clouds<span style="color: #66cc66;">&#41;</span>
cloudMaterial.<span style="color: #006600;">smooth</span> = <span style="color: #000000; font-weight: bold;">true</span>;
cloudMaterial.<span style="color: #006600;">doubleSided</span> = <span style="color: #000000; font-weight: bold;">false</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// creo la segunda esfera</span>
sphere2 = <span style="color: #000000; font-weight: bold;">new</span> Sphere<span style="color: #66cc66;">&#40;</span>cloudMaterial,<span style="color: #cc66cc;">160</span>,<span style="color: #cc66cc;">24</span>,<span style="color: #cc66cc;">16</span><span style="color: #66cc66;">&#41;</span>; 
&nbsp;
<span style="color: #808080; font-style: italic;">//creo el sistema de particulas</span>
particles = <span style="color: #000000; font-weight: bold;">new</span> Particles<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//saco el bitmap para crear un material que sera aplicado a cada particula</span>
<span style="color: #000000; font-weight: bold;">var</span> particlematerial : BitmapParticleMaterial = <span style="color: #000000; font-weight: bold;">new</span> BitmapParticleMaterial<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> particleBitmap<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">bitmapData</span>,<span style="color: #cc66cc;">0.5</span>,-<span style="color: #cc66cc;">32</span>,-<span style="color: #cc66cc;">32</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//creo 500 estrellas y la dispongo en el espacio entre 1000 y -500</span>
<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i : <span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>; i<span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">500</span>; i++<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
<span style="color: #000000; font-weight: bold;">var</span> particle : Particle = <span style="color: #000000; font-weight: bold;">new</span> Particle<span style="color: #66cc66;">&#40;</span>particlematerial, <span style="color: #cc66cc;">1</span>, <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">1000</span><span style="color: #66cc66;">&#41;</span> -<span style="color: #cc66cc;">500</span>, <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">1000</span><span style="color: #66cc66;">&#41;</span> -<span style="color: #cc66cc;">500</span>, <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">3000</span><span style="color: #66cc66;">&#41;</span> -<span style="color: #cc66cc;">1500</span><span style="color: #66cc66;">&#41;</span>;
particles.<span style="color: #006600;">addParticle</span><span style="color: #66cc66;">&#40;</span>particle<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #808080; font-style: italic;">//agrego al sceneario el sistema de particulas</span>
scene.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>particles<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//agrego la tierra</span>
scene.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>sphere<span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">//agrego las nubes</span>
scene.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>sphere2<span style="color: #66cc66;">&#41;</span>; 
&nbsp;
<span style="color: #808080; font-style: italic;">//punto de interes de la camara</span>
<span style="color: #0066CC;">camera</span>.<span style="color: #006600;">fov</span> = <span style="color: #cc66cc;">30</span>;
&nbsp;
addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, enterFrame<span style="color: #66cc66;">&#41;</span>;             
&nbsp;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> enterFrame<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
counter++;
&nbsp;
sphere.<span style="color: #006600;">yaw</span><span style="color: #66cc66;">&#40;</span>-<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
sphere2.<span style="color: #006600;">yaw</span><span style="color: #66cc66;">&#40;</span>-<span style="color: #cc66cc;">0.5</span><span style="color: #66cc66;">&#41;</span>;
particles.<span style="color: #006600;">yaw</span><span style="color: #66cc66;">&#40;</span>-<span style="color: #cc66cc;">0.01</span><span style="color: #66cc66;">&#41;</span>;
particles.<span style="color: #006600;">pitch</span><span style="color: #66cc66;">&#40;</span>-<span style="color: #cc66cc;">0.01</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//camera.x = Math.sin(counter*0.02) * 2000;  si quieren que sea automatico en vez de seguir el mouse lo pueden hacer con una onda senoidal</span>
<span style="color: #0066CC;">camera</span>.<span style="color: #006600;">x</span> = <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">320</span>-mouseX<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">0.01</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">2000</span>;
singleRender<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://digilabs.com.ar/2010/09/actionscript/tierra-en-papervision/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Video full screen en flash</title>
		<link>http://digilabs.com.ar/2010/09/actionscript/video-full-screen-en-flash</link>
		<comments>http://digilabs.com.ar/2010/09/actionscript/video-full-screen-en-flash#comments</comments>
		<pubDate>Mon, 20 Sep 2010 08:22:07 +0000</pubDate>
		<dc:creator>Andrés Argüello Pitt</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://digilabs.com.ar/?p=1154</guid>
		<description><![CDATA[La semana pasada tuve un par de trabajos en los que requeria utilizar un video de flash como fondo y arriba de eso un sitio html puro. Asi que la idea de este mini tutorial es mostrar lo facil que es hacer que el video en flash tome el 100 porciento de la pantalla y [...]]]></description>
			<content:encoded><![CDATA[<p>La semana pasada tuve un par de trabajos en los que requeria utilizar un video de flash como fondo y arriba de eso un sitio html puro. Asi que la idea de este mini tutorial es mostrar lo facil que es hacer que el video en flash tome el 100 porciento de la pantalla y se redimencione cuando se cambia el tamano de la pantalla.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">stage</span>.<span style="color: #0066CC;">scaleMode</span> = StageScaleMode.<span style="color: #006600;">NO_SCALE</span>;
<span style="color: #0066CC;">stage</span>.<span style="color: #0066CC;">align</span> = StageAlign.<span style="color: #006600;">TOP_LEFT</span>;</pre></td></tr></table></div>

<p>Con la primer linea especificamos que el tamano de la aplicacion flash tiene que se fija y que se mantiene fija incluso si cambia el tamano del explorador.<br />
La segunda linea especifica que el escenario este alineado en la esquina superior izquierda.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> _netCon :<span style="color: #0066CC;">NetConnection</span> = <span style="color: #000000; font-weight: bold;">null</span>;
<span style="color: #000000; font-weight: bold;">var</span> _netStr :<span style="color: #0066CC;">NetStream</span> = <span style="color: #000000; font-weight: bold;">null</span>;
<span style="color: #000000; font-weight: bold;">var</span> _video :<span style="color: #0066CC;">Video</span> = <span style="color: #000000; font-weight: bold;">null</span>;</pre></td></tr></table></div>

<p>NetConnection es un objecto que podemos describir como un tubo entre el cliente y el servidor.</p>
<p>La clase Video muestra un video en la aplicacion sin incrustarlo en el swf. Digamos lo reproduce en un contenedor mediante streaming.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> SetupNetConnection<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
 _netCon = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">NetConnection</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
 _netCon.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>NetStatusEvent.<span style="color: #006600;">NET_STATUS</span>, NetStatus, <span style="color: #000000; font-weight: bold;">false</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
 _netCon.<span style="color: #0066CC;">connect</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Bueno, yahemso creado la conexion y agredado un listener que monitorea el estado de la conexion. el argumento null significa que no estamos conectando a un Flash media server sino que hacemos streaming de un archivo que reside en un servidor normal.</p>
<p>Ahora vamos a crear el stream que vamos a usar par ver el video mediante el objeto NetConnection y vamos a escuchar su estado mediante listener de ese mismo objeto.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> SetupNetStream<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">var</span> $customClient:<span style="color: #0066CC;">Object</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
$customClient.<span style="color: #006600;">onMetaData</span> = onMetaData;
_netStr = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">NetStream</span><span style="color: #66cc66;">&#40;</span>_netCon<span style="color: #66cc66;">&#41;</span>;
 _netStr.<span style="color: #006600;">client</span> = $customClient;
_netStr.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>NetStatusEvent.<span style="color: #006600;">NET_STATUS</span>, NetStatus, <span style="color: #000000; font-weight: bold;">false</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
_video = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Video</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
 _video.<span style="color: #006600;">attachNetStream</span><span style="color: #66cc66;">&#40;</span>_netStr<span style="color: #66cc66;">&#41;</span>;
 _video.<span style="color: #0066CC;">smoothing</span> = <span style="color: #000000; font-weight: bold;">false</span>;
 addChild<span style="color: #66cc66;">&#40;</span>_video<span style="color: #66cc66;">&#41;</span>;
_netStr.<span style="color: #0066CC;">play</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;video.flv&quot;</span><span style="color: #66cc66;">&#41;</span>;
 <span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>La funcion onMetaData va ser llamada tan pronto como el objeto NetStream obtenga informacion del archivo FLV.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> onMetaData<span style="color: #66cc66;">&#40;</span>$info:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> NetStatus<span style="color: #66cc66;">&#40;</span>$e:NetStatusEvent<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
<span style="color: #b1b100;">switch</span> <span style="color: #66cc66;">&#40;</span>$e.<span style="color: #006600;">info</span>.<span style="color: #006600;">code</span><span style="color: #66cc66;">&#41;</span>   <span style="color: #66cc66;">&#123;</span>
&nbsp;
<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;NetConnection.Connect.Success&quot;</span>:
SetupNetStream<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #b1b100;">break</span>;
&nbsp;
<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;NetStream.Play.Stop&quot;</span>:
_netStr.<span style="color: #0066CC;">seek</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;
 <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> ResizeAndPosition<span style="color: #66cc66;">&#40;</span>$e:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
_video.<span style="color: #0066CC;">width</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span>;
_video.<span style="color: #0066CC;">height</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">RESIZE</span>, ResizeAndPosition, <span style="color: #000000; font-weight: bold;">false</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
ResizeAndPosition<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>; 
&nbsp;
SetupNetConnection<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>
Y el HTML que contrendria el player sería el siguiente:<br />
</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;!--
*{ margin:0; padding:0; }
--&gt;
&lt;object classid=&quot;clsid:d27cdb6e-ae6d-11cf-96b8-444553540000&quot; width=&quot;100%&quot; height=&quot;100%&quot; codebase=&quot;http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0&quot;&gt;&lt;param name=&quot;src&quot; value=&quot;source.swf&quot; /&gt;&lt;embed type=&quot;application/x-shockwave-flash&quot; width=&quot;100%&quot; height=&quot;100%&quot; src=&quot;source.swf&quot;&gt;&lt;/embed&gt;&lt;/object&gt;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://digilabs.com.ar/2010/09/actionscript/video-full-screen-en-flash/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Detectar dirección y rotación</title>
		<link>http://digilabs.com.ar/2010/09/actionscript/detectar-direccion-y-rotacion</link>
		<comments>http://digilabs.com.ar/2010/09/actionscript/detectar-direccion-y-rotacion#comments</comments>
		<pubDate>Sat, 11 Sep 2010 10:35:09 +0000</pubDate>
		<dc:creator>Andrés Argüello Pitt</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Programación]]></category>
		<category><![CDATA[Tutoriales]]></category>

		<guid isPermaLink="false">http://digilabs.com.ar/?p=1117</guid>
		<description><![CDATA[Ayer estuvimos discutiendo con Eduardo un poco sobre su tutorial para detectar la dirección y la rotación en Flash. Su comienzo esta muy bien pero analizamos que tenía un par de fallas. Además él también nombró que le gustaría animar el traslado del avion para que no sea tan brusco, a esto lo realizaremos usando [...]]]></description>
			<content:encoded><![CDATA[<p>Ayer estuvimos discutiendo con Eduardo un poco sobre su <a href="http://digilabs.com.ar/2010/09/actionscript/detectar-direccion-con-actionscrip-2" target="_self">tutorial para detectar la dirección</a> y la rotación en Flash. Su comienzo esta muy bien pero analizamos que tenía un par de fallas. Además él también nombró que le gustaría animar el traslado del avion para que no sea tan brusco, a esto lo realizaremos usando una clase para tweeners.</p>
<p>La primera en realidad no es una falla, sino más bien el deseo que el avión gire hacia la dirección de traslado, lo cual trae un nuevo problema que es hacia donde gira. Por defecto si en Flash sólo se usa rotación el giro que efectúa es en sentido horario, por lo cual a veces esto puede ser muy raro cuando es más rápido girar hacia el otro lado. Hay varias formas de detectar ésto y la que discutíamos es simplemente detectar el angulo de rotación actual restarle 360 y listo. Pero mientras discutiamos con Eduardo que formula utilizar encontré un propiedad/plugin dentro de la clase Tweenmax que no sólo te hace la rotación al ángulo deseado sino que también detecta hacia donde es el giro más corto.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;">TweenMax.<span style="color: #006600;">to</span><span style="color: #66cc66;">&#40;</span>avion_mc, <span style="color: #cc66cc;">0.5</span>, <span style="color: #66cc66;">&#123;</span>shortRotation:<span style="color: #66cc66;">&#123;</span>rotation:<span style="color: #cc66cc;">270</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p><small>Con shortRotation nos evitamos tener que hacer el calculo nosotros y decide hacer el giro en sentido horario o antihorario según cual sea más corto</small></p>
<p>Ahora el otro problema es que cuando movemos el mouse no lo hacemos en un movimiento perfecto hacia arriba o abajo o hacia los laterales, en realidad siempre existen una componente hacia arriba, abajo o laterales . una especie de ruido.<br />
Para solucionar este problema empecé por detectar manualmente en donde se encuentra el mouse y hacia donde se mueve. Luego hago los cambios de giro solamente cuando el movimiento es 100% hacia los costados o 100% hacia arriba o abajo. De esta forma se evita que haya pequeño intentos de cambiar el gira cuando en realidad es sólo ruido.</p>
<p>El código completo es el siguiente:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> com.<span style="color: #006600;">greensock</span>.<span style="color: #66cc66;">*</span>;
<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">greensock</span>.<span style="color: #006600;">easing</span>.<span style="color: #66cc66;">*</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">Start</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_MOVE</span>, CheckDirection<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">Start</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> prevX = <span style="color: #cc66cc;">0</span>;
<span style="color: #000000; font-weight: bold;">var</span> prevY = <span style="color: #cc66cc;">0</span>;
<span style="color: #000000; font-weight: bold;">var</span> curX = <span style="color: #cc66cc;">0</span>;
<span style="color: #000000; font-weight: bold;">var</span> curY = <span style="color: #cc66cc;">0</span>;
<span style="color: #000000; font-weight: bold;">var</span> dirX:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
<span style="color: #000000; font-weight: bold;">var</span> dirY:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> CheckDirection<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:MouseEvent<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
<span style="color: #000000; font-weight: bold;">var</span> dirHorizontal:<span style="color: #0066CC;">String</span> = obtenerDireccionHorizontal<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> dirVertical:<span style="color: #0066CC;">String</span> = obtenerDireccionVertical<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;movimiento en X : &quot;</span> + dirHorizontal + <span style="color: #ff0000;">&quot;, movimiento en Y : &quot;</span> + dirVertical<span style="color: #66cc66;">&#41;</span>;
TweenMax.<span style="color: #006600;">to</span><span style="color: #66cc66;">&#40;</span>avion_mc, <span style="color: #cc66cc;">1</span>, <span style="color: #66cc66;">&#123;</span> x:mouseX,y:mouseY<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
hacerGiro<span style="color: #66cc66;">&#40;</span>dirHorizontal,dirVertical<span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">updateAfterEvent</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> hacerGiro<span style="color: #66cc66;">&#40;</span>dirHorizontal,dirVertical<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>dirHorizontal == <span style="color: #ff0000;">'derecha'</span> <span style="color: #66cc66;">&amp;&amp;</span> dirVertical == <span style="color: #ff0000;">'none'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
TweenMax.<span style="color: #006600;">to</span><span style="color: #66cc66;">&#40;</span>avion_mc, <span style="color: #cc66cc;">0.5</span>, <span style="color: #66cc66;">&#123;</span>shortRotation:<span style="color: #66cc66;">&#123;</span>rotation:<span style="color: #cc66cc;">90</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>dirHorizontal==<span style="color: #ff0000;">'izquierda'</span> <span style="color: #66cc66;">&amp;&amp;</span> dirVertical == <span style="color: #ff0000;">'none'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
TweenMax.<span style="color: #006600;">to</span><span style="color: #66cc66;">&#40;</span>avion_mc, <span style="color: #cc66cc;">0.5</span>, <span style="color: #66cc66;">&#123;</span>shortRotation:<span style="color: #66cc66;">&#123;</span>rotation:<span style="color: #cc66cc;">270</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>dirVertical == <span style="color: #ff0000;">'arriba'</span> <span style="color: #66cc66;">&amp;&amp;</span> dirHorizontal == <span style="color: #ff0000;">'none'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
TweenMax.<span style="color: #006600;">to</span><span style="color: #66cc66;">&#40;</span>avion_mc, <span style="color: #cc66cc;">0.5</span>, <span style="color: #66cc66;">&#123;</span>shortRotation:<span style="color: #66cc66;">&#123;</span>rotation:<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>dirVertical==<span style="color: #ff0000;">'abajo'</span> <span style="color: #66cc66;">&amp;&amp;</span> dirHorizontal == <span style="color: #ff0000;">'none'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
TweenMax.<span style="color: #006600;">to</span><span style="color: #66cc66;">&#40;</span>avion_mc, <span style="color: #cc66cc;">0.5</span>, <span style="color: #66cc66;">&#123;</span>shortRotation:<span style="color: #66cc66;">&#123;</span>rotation:<span style="color: #cc66cc;">180</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> obtenerDireccionHorizontal<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span>
<span style="color: #66cc66;">&#123;</span>
&nbsp;
prevX = curX;
curX = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">mouseX</span>;
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>prevX <span style="color: #66cc66;">&gt;</span> curX<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
dirX = <span style="color: #ff0000;">&quot;izquierda&quot;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>prevX <span style="color: #66cc66;">&lt;</span> curX<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
dirX = <span style="color: #ff0000;">&quot;derecha&quot;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #b1b100;">else</span>
<span style="color: #66cc66;">&#123;</span>
dirX = <span style="color: #ff0000;">&quot;none&quot;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #b1b100;">return</span> dirX;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> obtenerDireccionVertical<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span>
<span style="color: #66cc66;">&#123;</span>
prevY = curY;
curY = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">mouseY</span>;
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>prevY <span style="color: #66cc66;">&gt;</span> curY<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
dirY = <span style="color: #ff0000;">&quot;arriba&quot;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>prevY <span style="color: #66cc66;">&lt;</span> curY<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
dirY = <span style="color: #ff0000;">&quot;abajo&quot;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #b1b100;">else</span>
<span style="color: #66cc66;">&#123;</span>
dirY = <span style="color: #ff0000;">&quot;none&quot;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #b1b100;">return</span> dirY;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Para que les funcione tienen que bajar la clase tweenMax para AS3 desde: http://www.tweenmax.com</p>
<p>Acá el ejemplo funcionando:</p>
<p>
<object width="320" height="480">
<param name="movie" value="http://digilabs.com.ar/wp-content/uploads/2010/09/avioncito.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="opaque"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#00000"></param>
<embed type="application/x-shockwave-flash" width="320" height="480" src="http://digilabs.com.ar/wp-content/uploads/2010/09/avioncito.swf" quality="high" bgcolor="#00000" wmode="opaque" menu="false" ></embed>
</object>
<br />
<small>noten que cambié la resolución a la misma resolución del iPhone, el próximo post será como portar esto a una aplicación de iPhone.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://digilabs.com.ar/2010/09/actionscript/detectar-direccion-y-rotacion/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Detectar dirección con ActionScrip 2</title>
		<link>http://digilabs.com.ar/2010/09/actionscript/detectar-direccion-con-actionscrip-2</link>
		<comments>http://digilabs.com.ar/2010/09/actionscript/detectar-direccion-con-actionscrip-2#comments</comments>
		<pubDate>Thu, 09 Sep 2010 02:03:50 +0000</pubDate>
		<dc:creator>Eduardo Martin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS2]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Programación]]></category>
		<category><![CDATA[Tendencias]]></category>

		<guid isPermaLink="false">http://digilabs.com.ar/?p=1088</guid>
		<description><![CDATA[Si lo que intentan es detectar hacia que dirección va el cursor del mouse utilizando ActionScript2, les recomiendo utilizar un método que poco conocía que es nativo de Flash, su nombre es &#8220;watch&#8220;. Esta función analizar una variable y devuelve dos valores uno nuevo &#8220;newVal&#8221; y otro viejo &#8220;oldVal&#8220;,  lo cual nos facilita el trabajo [...]]]></description>
			<content:encoded><![CDATA[<p>Si lo que intentan es detectar hacia que dirección va el cursor del mouse utilizando ActionScript2, les recomiendo utilizar un método que poco conocía que es nativo de Flash, su nombre es &#8220;<a title="Funcion watch" href="http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001435.html" target="_self"><strong>watch</strong></a>&#8220;. Esta función analizar una variable y devuelve dos valores uno nuevo &#8220;<strong>newVal</strong>&#8221; y otro viejo &#8220;<strong>oldVal</strong>&#8220;,  lo cual nos facilita el trabajo si tenemos que desarrollar una pelicula que detecte si el mouse va hacia la derecha o hacia izquierda, arriba o abajo, este método es muy interesante ya que nos permitiría saber si los valores en <strong>x</strong> e <strong>y</strong> se incrementan o disminuye lo cual con un simple if podríamos saber hacia donde se dirige el cursor. Esta función también puede servir para activar alertas, cuando una variable cambia, se analiza con watch y cuando se cumple una condición se activa una alarma, se ejecuta una función o simplemente se activa una animación.</p>
<p>Esto también se puede hacer con listeners, pero es mas complejo ya que hay que armar la función que permite comparar el valor viejo con el valor nuevo de la variable mientras cambia. No les aconsejo utilizar onEnterFrame ya que consume muchos recursos.</p>
<p><strong>Ejempo:</strong></p>
<p>
<object width="450" height="400">
<param name="movie" value="http://digilabs.com.ar/wp-content/uploads/2010/09/detectar-direccion.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="opaque"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#00000"></param>
<embed type="application/x-shockwave-flash" width="450" height="400" src="http://digilabs.com.ar/wp-content/uploads/2010/09/detectar-direccion.swf" quality="high" bgcolor="#00000" wmode="opaque" menu="false" ></embed>
</object>
</p>
<p><strong>Codigo:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">Mouse</span>.<span style="color: #0066CC;">hide</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
posX = <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>dx, oldVal, newVal<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>oldValnewVal<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Izquierda&quot;</span><span style="color: #66cc66;">&#41;</span>;
        avion_mc.<span style="color: #0066CC;">_rotation</span> = -<span style="color: #cc66cc;">90</span>;
    <span style="color: #66cc66;">&#125;</span>
    <span style="color: #b1b100;">return</span> newVal;
<span style="color: #66cc66;">&#125;</span>;
posY = <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>dy, oldVal, newVal<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>oldValnewVal<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;rriba&quot;</span><span style="color: #66cc66;">&#41;</span>;
        avion_mc.<span style="color: #0066CC;">_rotation</span> = <span style="color: #cc66cc;">360</span>;
    <span style="color: #66cc66;">&#125;</span>
    <span style="color: #b1b100;">return</span> newVal;
<span style="color: #66cc66;">&#125;</span>;
&nbsp;
<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">watch</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;dirx&quot;</span>,posX<span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">watch</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;diry&quot;</span>,posY<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">onMouseMove</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    avion_mc.<span style="color: #0066CC;">_x</span> = <span style="color: #0066CC;">_xmouse</span>;
    avion_mc.<span style="color: #0066CC;">_y</span> = <span style="color: #0066CC;">_ymouse</span>;
    dirx = <span style="color: #0066CC;">_xmouse</span>;
    diry = <span style="color: #0066CC;">_ymouse</span>;
&nbsp;
<span style="color: #66cc66;">&#125;</span>;</pre></div></div>

<p>Para los que estan trabajando con <strong>As3</strong>, el método watch no existe mas, por lo cual les dejo una solución <a href="http://www.myriamspitz.com/2009/01/where-is-the-watch-object-in-as3/" target="_self">AQUI</a></p>
<p><strong>Clase:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
   <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
   <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">EventDispatcher</span>;
   <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Model <span style="color: #0066CC;">extends</span> EventDispatcher
   <span style="color: #66cc66;">&#123;</span>
       <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const VALUE_CHANGED:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">'value_changed'</span>;
       <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _number:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">Number</span>;
       <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Model<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
       <span style="color: #66cc66;">&#123;</span>
           <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'The model was instantiated.'</span><span style="color: #66cc66;">&#41;</span>;
       <span style="color: #66cc66;">&#125;</span>
       <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> <span style="color: #0066CC;">number</span><span style="color: #66cc66;">&#40;</span>newNb:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
       <span style="color: #66cc66;">&#123;</span>
          _number=newNb;
          <span style="color: #0066CC;">this</span>.<span style="color: #006600;">dispatchEvent</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Event<span style="color: #66cc66;">&#40;</span>Model.<span style="color: #006600;">VALUE_CHANGED</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
       <span style="color: #66cc66;">&#125;</span>
       <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> <span style="color: #0066CC;">number</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Number</span>
      <span style="color: #66cc66;">&#123;</span>
          <span style="color: #b1b100;">return</span> _number;
&nbsp;
      <span style="color: #66cc66;">&#125;</span>
   <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><strong>Modo de uso:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> objectToWatch:Model = <span style="color: #000000; font-weight: bold;">new</span> Model<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
objectToWatch.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Model.<span style="color: #006600;">VALUE_CHANGED</span>, onValuedChanged<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> onValuedChanged<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
   <span style="color: #808080; font-style: italic;">//do what you need here</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Espero que les sea útil, la próxima me gustaría completar la pelicula de arriba con algo de trigonometría para simular 100% la dirección.</p>
]]></content:encoded>
			<wfw:commentRss>http://digilabs.com.ar/2010/09/actionscript/detectar-direccion-con-actionscrip-2/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Un sonido luego de otro</title>
		<link>http://digilabs.com.ar/2010/06/actionscript/un-sonido-luego-de-otro</link>
		<comments>http://digilabs.com.ar/2010/06/actionscript/un-sonido-luego-de-otro#comments</comments>
		<pubDate>Sat, 19 Jun 2010 10:31:27 +0000</pubDate>
		<dc:creator>Andrés Argüello Pitt</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://digilabs.com.ar/?p=893</guid>
		<description><![CDATA[El año pasado hice un trabajo donde se necesitaba que se reproducieran unas imágenes y al mismo tiempo se escuchara una voz en voz describiendo la imagen. El tema que eran varia galerías que eran cambiadas dinámicamente por lo que se requería que ésta pseudo película se generara en tiempo de ejecución. El tema estaba [...]]]></description>
			<content:encoded><![CDATA[<p>El año pasado hice un trabajo donde se necesitaba que se reproducieran unas imágenes y al mismo tiempo se escuchara una voz en voz describiendo la imagen.<br />
El tema que eran varia galerías que eran cambiadas dinámicamente por lo que se requería que ésta pseudo película se generara en tiempo de ejecución.<br />
El tema estaba en precargar todas las imágenes y todas los sonidos para que no haya pausas entre imagen e imagen.<br />
Precargar la imágenes es relativamente facil ya que podes cargarlas usando un loadClip ya que son guardadas automáticamente en el caché.<br />
El tema son los sonidos, como asegurarse que los sonidos son precargados de forma que no haya pausas. Hay un par de formas de hacerlo la que me resultó más práctica a mi fue:</p>
<p>La forma normal sería, manual y estática sería:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">media</span>.<span style="color: #0066CC;">Sound</span>;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">media</span>.<span style="color: #006600;">SoundChannel</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> mySoundOne:<span style="color: #0066CC;">Sound</span> = <span style="color: #000000; font-weight: bold;">new</span> SoundOne<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> mySoundTwo:<span style="color: #0066CC;">Sound</span> = <span style="color: #000000; font-weight: bold;">new</span> SoundTwo<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> mySoundThree:<span style="color: #0066CC;">Sound</span> = <span style="color: #000000; font-weight: bold;">new</span> SoundThree<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> mySoundChannel:SoundChannel = mySoundOne.<span style="color: #0066CC;">play</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
mySoundChannel.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">SOUND_COMPLETE</span>, sound_1_Complete<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> mySoundChannel2:SoundChannel;
<span style="color: #000000; font-weight: bold;">var</span> mySoundChannel3:SoundChannel;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> sound_1_Complete<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;one complete&quot;</span><span style="color: #66cc66;">&#41;</span>;
    mySoundChannel2 = mySoundTwo.<span style="color: #0066CC;">play</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    mySoundChannel2.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">SOUND_COMPLETE</span>, sound_2_Complete<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> sound_2_Complete<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;two complete&quot;</span><span style="color: #66cc66;">&#41;</span>;
    mySoundChannel3 = mySoundThree.<span style="color: #0066CC;">play</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    mySoundChannel3.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">SOUND_COMPLETE</span>, sound_3_Complete<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> sound_3_Complete<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;three complete&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Hasta acá todo fácil, lo que fue una novedad para mi es que es posible meter objetos dentro de arrays, por lo que cree un array con sonidos (objetos) adentro y fui cargando un sonido después del otro, de forma que era automatizado, dinámico y que podía ser cambiado en tiempo de ejecución sin problemas.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> sounds:<span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #000000; font-weight: bold;">new</span> SoundOne<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #000000; font-weight: bold;">new</span> SoundTwo<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #000000; font-weight: bold;">new</span> SoundThree<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> channels:<span style="color: #0066CC;">Array</span>;
&nbsp;
channels<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #0066CC;">Sound</span><span style="color: #66cc66;">&#40;</span>sounds<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">play</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
SoundChannel<span style="color: #66cc66;">&#40;</span>channel<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">SOUND_COMPLETE</span>, playNext<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> playNext<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
&nbsp;
<span style="color: #66cc66;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">index</span>:<span style="color: #0066CC;">Number</span> = channels.<span style="color: #0066CC;">indexOf</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">currentTarget</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;played sound &quot;</span> + <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">index</span> + <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">index</span> <span style="color: #66cc66;">&amp;</span>lt; sounds.<span style="color: #006600;">lenth</span> - <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#123;</span>
&nbsp;
<span style="color: #0066CC;">index</span>++;
&nbsp;
channels<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #0066CC;">Sound</span><span style="color: #66cc66;">&#40;</span>sounds<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">play</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
SoundChannel<span style="color: #66cc66;">&#40;</span>channels<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">SOUND_COMPLETE</span>, playNext<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span>
sounds.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> SoundFour<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// sólo habría que asegurarse de llamar a esto antes que el sonido cuatro termine de reproducirse</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://digilabs.com.ar/2010/06/actionscript/un-sonido-luego-de-otro/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Animando huesos con AS3 (bones y actionscript 3)</title>
		<link>http://digilabs.com.ar/2010/06/actionscript/animando-bones-con-as3</link>
		<comments>http://digilabs.com.ar/2010/06/actionscript/animando-bones-con-as3#comments</comments>
		<pubDate>Thu, 03 Jun 2010 01:13:31 +0000</pubDate>
		<dc:creator>Andrés Argüello Pitt</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutoriales]]></category>

		<guid isPermaLink="false">http://digilabs.com.ar/?p=869</guid>
		<description><![CDATA[Éste tutorial es para dar una idea básica de lo que se puede hacer con los huesos y la cinemática inversa. Lo interesante es poder mover éstos huesos por código y así reaccionar en runtime de acuerdo a posición del mouse, ingreso del teclado o como abarca éste tutorial a la música. Ejemplo final: Lo [...]]]></description>
			<content:encoded><![CDATA[<p>Éste tutorial es para dar una idea básica de lo que se puede hacer con los huesos y la cinemática inversa. Lo interesante es poder mover éstos huesos por código y así reaccionar en runtime de acuerdo a posición del mouse, ingreso del teclado o como abarca éste tutorial a la música.<br />
Ejemplo final:<br />

<object width="300" height="300">
<param name="movie" value="http://digilabs.com.ar/wp-content/uploads/2010/06/amplitude.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="opaque"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#00000"></param>
<embed type="application/x-shockwave-flash" width="300" height="300" src="http://digilabs.com.ar/wp-content/uploads/2010/06/amplitude.swf" quality="high" bgcolor="#00000" wmode="opaque" menu="false" ></embed>
</object>
</p>
<p>Lo primero es elegir un objeto que querramos animar, en mi caso la mascota de Homestar Runner, que lo peuden bajar de <a href="http://www.brandsoftheworld.com/logo/homestar-runner" target="_blank">brandsoftheworld</a>. Luego tenemos que convertir en movieclips cada sección de nuestro objeto, por ejemplo: la cabeza, el tronco, la pierna derecha, la pierna izquierda.<br />
Luego elegimos la herramienta &#8220;bones&#8221; (x) y empezamos a unir nuestros objetos<a href="http://digilabs.com.ar/wp-content/uploads/2010/06/Screen-shot-2010-06-03-at-11.36.59.png"><img class="alignleft size-full wp-image-874" title="bones con as3" src="http://digilabs.com.ar/wp-content/uploads/2010/06/Screen-shot-2010-06-03-at-11.36.59.png" alt="" width="136" height="221" /></a>.</p>
<p>Luego seleccionamos el <strong>frame</strong> que contiene nuestros moviclips unidos por los huesos que creamos y veremos que en el panel propiedades aparece el nombre del esqueleto que acabamos de crear. Ahí podemos darle un nuevo nombre a todo nuestro esqueleto, yo voy a utilizar el que me tocó por defecto.<a href="http://digilabs.com.ar/wp-content/uploads/2010/06/Screen-shot-2010-06-03-at-11.38.51.png"><img class="alignleft size-medium wp-image-876" title="ikarmature y as3" src="http://digilabs.com.ar/wp-content/uploads/2010/06/Screen-shot-2010-06-03-at-11.38.51-300x106.png" alt="" width="300" height="106" /></a></p>
<p>Es importante que seleccionar el frame y no el moviclip ya que si seleccionamos un moviclip accedemos a las propiedades del hueso en sí pero no del esqueleto completo.</p>
<p><a href="http://digilabs.com.ar/wp-content/uploads/2010/06/Screen-shot-2010-06-03-at-11.53.27.png"><img style="float: left; margin-right: 7px;" title="runtime bones as3" src="http://digilabs.com.ar/wp-content/uploads/2010/06/Screen-shot-2010-06-03-at-11.53.27.png" alt="" width="263" height="95" /></a>También es importante cambiar y el Type de authotime a runtime, lo que hace que los huesos se van a animen en tiempo de ejecución en vez de ser animados con tween o cuadro por cuadro dentro de Flash. Luego de tener el nombre del esqueleto si pasamos a seleccionar los huesos que queremos mover y le damos nombres, también en ésta parte podemos ajustar los ángulos que vamos a permitir que se mueva y varias otras propiedades, yo no cambié nada pero los resultados pueden variar.</p>
<p>Por último la parte del código.<br />
Básicamente lo que tenemos que hacer es registrar el esqueleto y luego ligar a éste esqueleto los huesos que a su vez tienen dos puntos por lo cual tenemos que decir cual de dichos puntos queremos mover y lo podemos hacer en cualquier eje: x,y o z. El registro del esqueleto se hace una vez, y luego tenemos decidir cuantos huesos se van a mover.<br />
En este caso lo que voy a hacer es cargar un sonido, analizar su espectro y mover el pie izquierdo con lo que haya en el canal izquierdo de la música y luego lo mismo con el derecho.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> tree:IKArmature = IKManager.<span style="color: #006600;">getArmatureByName</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Armature_5&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> right_leg:IKBone = tree.<span style="color: #006600;">getBoneByName</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;ikBoneName9&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> left_leg:IKBone = tree.<span style="color: #006600;">getBoneByName</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;ikBoneName10&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> cabeza:IKBone = tree.<span style="color: #006600;">getBoneByName</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;ikNode_6&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// tailJoint mueve e punto del hueso, si queremos mover la cabeza del hueso debemos usar headJoint</span>
&nbsp;
<span style="color: #808080; font-style: italic;">//para la pierna derecha</span>
<span style="color: #000000; font-weight: bold;">var</span> rtJ:IKJoint = right_leg.<span style="color: #006600;">tailJoint</span>;
<span style="color: #000000; font-weight: bold;">var</span> rposT: Point=rtJ.<span style="color: #0066CC;">position</span>;
<span style="color: #000000; font-weight: bold;">var</span> rikMover:IKMover = <span style="color: #000000; font-weight: bold;">new</span> IKMover<span style="color: #66cc66;">&#40;</span>rtJ, rposT<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//para la pierna izquiera</span>
<span style="color: #000000; font-weight: bold;">var</span> ltJ:IKJoint = left_leg.<span style="color: #006600;">tailJoint</span>;
<span style="color: #000000; font-weight: bold;">var</span> lposT: Point=ltJ.<span style="color: #0066CC;">position</span>;
<span style="color: #000000; font-weight: bold;">var</span> likMover:IKMover = <span style="color: #000000; font-weight: bold;">new</span> IKMover<span style="color: #66cc66;">&#40;</span>ltJ,lposT<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// cargo un sonido para analizar su espectro y mover los huesos según éste.</span>
<span style="color: #000000; font-weight: bold;">var</span> s:<span style="color: #0066CC;">Sound</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Sound</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
s.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://digilabs.com.ar/wp-content/uploads/2010/06/loop.mp3&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> sc:SoundChannel;
sc = s.<span style="color: #0066CC;">play</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">1000</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #0066CC;">this</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, aMoverLosHuesos<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> aMoverLosHuesos<span style="color: #66cc66;">&#40;</span>eventArgs:Event<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	rposT.<span style="color: #006600;">x</span>=<span style="color: #cc66cc;">110</span>+<span style="color: #66cc66;">&#40;</span>sc.<span style="color: #006600;">rightPeak</span><span style="color: #66cc66;">*</span> - <span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//110 es donde esta el punto en reposo</span>
        <span style="color: #808080; font-style: italic;">//y 20 son la cantidad de pixeles que quiero que se mueva que es multiplicado por algo entre 0 y 1.</span>
	lposT.<span style="color: #006600;">x</span>=<span style="color: #cc66cc;">50</span>+<span style="color: #66cc66;">&#40;</span>sc.<span style="color: #006600;">leftPeak</span><span style="color: #66cc66;">*</span> + <span style="color: #cc66cc;">30</span><span style="color: #66cc66;">&#41;</span>;
	rikMover.<span style="color: #0066CC;">moveTo</span><span style="color: #66cc66;">&#40;</span>rposT<span style="color: #66cc66;">&#41;</span>;
	likMover.<span style="color: #0066CC;">moveTo</span><span style="color: #66cc66;">&#40;</span>lposT<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Lo único que le agregué a mi ejemplo final fue un botón de start/stop para no volver loco a los que visiten <a href="http://www.digilabs.com.ar">digilabs</a><br />
Como ejercicio estaría bueno agregar un hueso desde el cuello a la punta de la cabeza ya animar la cabeza también. Para ésto hace falta agregar un movieclip transparente en la punta de la cabeza de lo contrario no sería imposible &#8220;tirar un nuevo hueso&#8221;. Otra cosa seria analizar bien el espectro del sonido cargado y usar los bajos para mover ciertas partes y los altos para otras.</p>
]]></content:encoded>
			<wfw:commentRss>http://digilabs.com.ar/2010/06/actionscript/animando-bones-con-as3/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://digilabs.com.ar/wp-content/uploads/2010/06/loop.mp3" length="467722" type="audio/mpeg" />
		</item>
	</channel>
</rss>

