<?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>CODIGO.actionscript &#187; mouse</title>
	<atom:link href="http://www.codigoactionscript.org/tag/mouse/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codigoactionscript.org</link>
	<description>Blog de programación en ActionScript. Tips, tutoriales, ejemplos de Adobe Flash, Flex y AIR</description>
	<lastBuildDate>Fri, 30 Sep 2011 11:25:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Otener parámetros en eventos de Actionscript 3</title>
		<link>http://www.codigoactionscript.org/otener-parametros-en-eventos-de-actionscript-3/</link>
		<comments>http://www.codigoactionscript.org/otener-parametros-en-eventos-de-actionscript-3/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 22:03:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Básico]]></category>
		<category><![CDATA[Trucos]]></category>
		<category><![CDATA[color]]></category>
		<category><![CDATA[eventos]]></category>
		<category><![CDATA[listener]]></category>
		<category><![CDATA[mouse]]></category>

		<guid isPermaLink="false">http://www.codigoactionscript.org/?p=252</guid>
		<description><![CDATA[<p>Cuando lanzamos un evento en Actionscript 3, por ejemplo de la clase MouseEvent, ponemos recuperar una serie de parámetros lanzados con ese evento.</p>
<p>Por ejemplo, en este código:</p>

PLAIN TEXT
Actionscript:




boton.addEventListener&#40;MouseEvent.MOUSE_DOWN, onBotonEvent&#41;;


&#160;


function onBotonEvent&#40;e:MouseEvent&#41;:void


&#123;


&#160; &#160; trace&#40;e&#41;;


&#125; 






<p></p>
<p>El trace() nos mostraría el evento que ha lanzado la función mostrando también todos los parámetros. En este caso serían estos:</p>

PLAIN TEXT
Actionscript:




MouseEvent type="mouseDown" bubbles=true cancelable=false eventPhase=2 localX=43 localY=30 stageX=170.55 stageY=106 relatedObject=null ctrlKey=false altKey=false shiftKey=false delta=0 






<p></p>
<p>Recuperar estos parámetros y saber con detalle el evento que ha lanzado la función nos puede resultar muy útil en muchos casos.</p>
<p>por ejemplo, [...]
Related posts:<ol>
<li><a href='http://www.codigoactionscript.org/eventos-click-y-doble-click-en-un-boton-con-actionscript-3/' rel='bookmark' title='Eventos click y doble click en un botón con Actionscript 3'>Eventos click y doble click en un botón con Actionscript 3</a></li>
<li><a href='http://www.codigoactionscript.org/eventos-de-boton-en-as3/' rel='bookmark' title='Eventos de botón en AS3'>Eventos de botón en AS3</a></li>
<li><a href='http://www.codigoactionscript.org/botones-con-parametros-en-actionscript-3/' rel='bookmark' title='Botones con parámetros en Actionscript 3'>Botones con parámetros en Actionscript 3</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Cuando lanzamos un evento en <a href="http://www.cristalab.com/tips/tags/actionscript_3">Actionscript 3</a>, por ejemplo de la clase <strong>MouseEvent</strong>, ponemos recuperar una serie de parámetros lanzados con ese evento.</p>
<p>Por ejemplo, en este código:</p>
<div id="codigo">
<div class="igBar"><span id="lactionscript-5"><a href="#" onclick="javascript:showPlainTxt('actionscript-5'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-5">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">boton.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>, onBotonEvent<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">function</span> onBotonEvent<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></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
</div>
<p></p>
<p>El <strong>trace()</strong> nos mostraría el evento que ha lanzado la función mostrando también todos los parámetros. En este caso serían estos:</p>
<div id="codigo">
<div class="igBar"><span id="lactionscript-6"><a href="#" onclick="javascript:showPlainTxt('actionscript-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-6">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">MouseEvent <span style="color: #0066CC;">type</span>=<span style="color: #ff0000;">"mouseDown"</span> bubbles=<span style="color: #000000; font-weight: bold;">true</span> cancelable=<span style="color: #000000; font-weight: bold;">false</span> eventPhase=<span style="color: #cc66cc;color:#800000;">2</span> localX=<span style="color: #cc66cc;color:#800000;">43</span> localY=<span style="color: #cc66cc;color:#800000;">30</span> stageX=<span style="color: #cc66cc;color:#800000;">170</span>.<span style="color: #cc66cc;color:#800000;">55</span> stageY=<span style="color: #cc66cc;color:#800000;">106</span> relatedObject=<span style="color: #000000; font-weight: bold;">null</span> ctrlKey=<span style="color: #000000; font-weight: bold;">false</span> altKey=<span style="color: #000000; font-weight: bold;">false</span> shiftKey=<span style="color: #000000; font-weight: bold;">false</span> delta=<span style="color: #cc66cc;color:#800000;">0</span> </div>
</li>
</ol>
</div>
</div>
</div>
</div>
<p></p>
<p>Recuperar estos parámetros y saber con detalle el evento que ha lanzado la función nos puede resultar muy útil en muchos casos.</p>
<p>por ejemplo, su quisiésemos ejecutar una acción u otra al clicar sobre el botón dependiendo si estamos pulsando la tecla <strong><ctrl></strong> podríamos recuperar ese parámetro del evento:</p>
<div id="codigo">
<div class="igBar"><span id="lactionscript-7"><a href="#" onclick="javascript:showPlainTxt('actionscript-7'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-7">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">boton.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>, onBotonEvent<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">function</span> onBotonEvent<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></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0066CC;">e</span>.<span style="color: #006600;">ctrlKey</span> == <span style="color: #000000; font-weight: bold;">true</span> ? accion1<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : accion2<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
</div>
<p></p>
<p>Aquí, si clicamos al botón sin tener pulsada la tecla <strong><ctrl></strong> ejecutaremos la función <strong>accion2</strong>, mientras que con el mismo clic con la tecla pulsada ejecutaríamos la función <strong>accion1</strong>.</p>
<p>También podemos utilizar este recurso para asignar la misma función a varios eventos y poder asignar diferentes parámetros a la función dependiendo del tipo de evento:</p>
<div id="codigo">
<div class="igBar"><span id="lactionscript-8"><a href="#" onclick="javascript:showPlainTxt('actionscript-8'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-8">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">import</span> fl.<span style="color: #006600;">motion</span>.<span style="color: #0066CC;">Color</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">boton.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">ROLL_OVER</span>, onBotonEvent<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">boton.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">ROLL_OUT</span>, onBotonEvent<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">boton.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>, onBotonEvent<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">boton.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_UP</span>, onBotonEvent<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">function</span> onBotonEvent<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></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span>&nbsp; &nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> code:uint;&nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">type</span> == <span style="color: #ff0000;">"rollOver"</span> ? code = 0xCCCCCC : <span style="color: #000000; font-weight: bold;">null</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">type</span> == <span style="color: #ff0000;">"rollOut"</span> ? code = 0x999999 : <span style="color: #000000; font-weight: bold;">null</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">type</span> == <span style="color: #ff0000;">"mouseDown"</span> ? code = 0x666666 : <span style="color: #000000; font-weight: bold;">null</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">type</span> == <span style="color: #ff0000;">"mouseUp"</span> ? code = 0xCCCCCC : <span style="color: #000000; font-weight: bold;">null</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">color</span>:<span style="color: #0066CC;">Color</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Color</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0066CC;">color</span>.<span style="color: #006600;">setTint</span><span style="color: #66cc66;">&#40;</span>code, <span style="color: #cc66cc;color:#800000;">1</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">transform</span>.<span style="color: #006600;">colorTransform</span> = <span style="color: #0066CC;">color</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
</div>
<p></p>
<p>En este ejemplo, todos los eventos del botón ejecutan la misma función pero dependiendo de cada uno se coloreará el clip de un color u otro.</p>
<p>Related posts:<ol>
<li><a href='http://www.codigoactionscript.org/eventos-click-y-doble-click-en-un-boton-con-actionscript-3/' rel='bookmark' title='Eventos click y doble click en un botón con Actionscript 3'>Eventos click y doble click en un botón con Actionscript 3</a></li>
<li><a href='http://www.codigoactionscript.org/eventos-de-boton-en-as3/' rel='bookmark' title='Eventos de botón en AS3'>Eventos de botón en AS3</a></li>
<li><a href='http://www.codigoactionscript.org/botones-con-parametros-en-actionscript-3/' rel='bookmark' title='Botones con parámetros en Actionscript 3'>Botones con parámetros en Actionscript 3</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.codigoactionscript.org/otener-parametros-en-eventos-de-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

