<?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>LLops Blog &#187; Tips</title>
	<atom:link href="http://llops.com/blog/category/tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://llops.com/blog</link>
	<description>Blog de programación creativa mantenido por llops. Experimentos y artículos entorno a la plataforma flash y as3.</description>
	<lastBuildDate>Mon, 15 Mar 2010 09:56:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Ayuda offline en Flash CS4</title>
		<link>http://llops.com/blog/2009/03/04/ayuda-offline-en-flash-cs4/</link>
		<comments>http://llops.com/blog/2009/03/04/ayuda-offline-en-flash-cs4/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 10:52:38 +0000</pubDate>
		<dc:creator>llops</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[ayuda]]></category>
		<category><![CDATA[flash cs4]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[lenguage reference]]></category>
		<category><![CDATA[offline]]></category>
		<category><![CDATA[online]]></category>

		<guid isPermaLink="false">http://llops.com/blog/?p=58</guid>
		<description><![CDATA[Una de las cosas más molestas de Flash CS4 es que la ayuda (F1) es online, se conecta con http://help.adobe.com y a partir de ahí buscar un simple método es una tarea lenta y tediosa. Afortunadamente, la ayuda también se encuentra en local y se puede poner por defecto.
Para ello debemos ir a Window &#62; [...]]]></description>
			<content:encoded><![CDATA[<p>Una de las cosas más molestas de Flash CS4 es que la ayuda (F1) es online, se conecta con <a href="http://help.adobe.com/en_US/Flash/10.0_UsingFlash/" target="_blank">http://help.adobe.com</a> y a partir de ahí buscar un simple método es una tarea lenta y tediosa. Afortunadamente, la ayuda también se encuentra en local y se puede poner por defecto.</p>
<p>Para ello debemos ir a <em>Window &gt; Extensions </em>y abrir el panel <em>Connections</em>. Al clicar en las opciones (botón superior derecha) veremos que una es <em>Offline options</em>.</p>
<p><img style="margin: 0px 0px 0px 20px" title="Panel Connections" src="http://llops.com/blog/content/articulos/mar09/panel_connections.jpg" alt="Panel Connections" width="381" height="382" /></p>
<p>Marcamos después el check de <em>Keep me offline</em> y aceptamos. Ahora al pulsar F1 dispondremos de toda la referencia en modo local, y aunque sigue abriéndose a través de navegador, al menos nos ahorramos los tiempo de carga.</p>
<blockquote><p><strong>Nota</strong>: a tener en cuenta que al activar este modo perdemos todas las funcionalidades que necesitan conexión (por ejemplo, el panel de Kuler).</p></blockquote>
<p>También hay otras dos opciones interesantes en forma de aplicaciones AIR:</p>
<ul>
<li><a title="Doc?" href="http://airdoc.be" target="_blank">http://airdoc.be</a></li>
<li><a title="AS3 language reference app" href="http://labs.bigspaceship.com/2008/12/09/air-app-as3-language-reference/" target="_blank">http://labs.bigspaceship.com/2008/12/09/air-app-as3-language-reference</a></li>
</ul>
<p>En la primera, Doc?, te tienes que descargar y configurar las distintas referencias de lenguaje que necesites (AS3, Flash CS4, CS3, Flex&#8230;) y la aplicación te permite ver, buscar y guardar la documentación. Yo la tengo instalada y es bastante útil.</p>
<p>La de BigSpaceShip, de similar funcionamiento, tiene integrada la referencia del lenguaje de AS3, pero a mí no me convenció mucho&#8230;</p>
<p>&nbsp;<br />
De todas maneras, la ayuda tal y como estaba planteada en CS3 era perfecta&#8230; :(</p>
<hr />
<p><small>
<a href="http://llops.com/blog/2009/03/04/ayuda-offline-en-flash-cs4/#comments">1 comentario</a> | <a href="http://llops.com/blog/2009/03/04/ayuda-offline-en-flash-cs4/">Permalink</a> | 
Add to
<a href="http://del.icio.us/post?url=http://llops.com/blog/2009/03/04/ayuda-offline-en-flash-cs4/&title=Ayuda offline en Flash CS4">del.icio.us</a>
<br/><br/>
<a href="http://llops.com/blog">LLops Blog</a>, 2009
</small></p>]]></content:encoded>
			<wfw:commentRss>http://llops.com/blog/2009/03/04/ayuda-offline-en-flash-cs4/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Recogiendo variables externas</title>
		<link>http://llops.com/blog/2008/09/19/recogiendo-variables-externas/</link>
		<comments>http://llops.com/blog/2008/09/19/recogiendo-variables-externas/#comments</comments>
		<pubDate>Fri, 19 Sep 2008 17:49:00 +0000</pubDate>
		<dc:creator>llops</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[displayList]]></category>
		<category><![CDATA[loaderInfo]]></category>
		<category><![CDATA[parameters]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://llops.com/blog/?p=37</guid>
		<description><![CDATA[A pesar de tener poco cero tiempo para dedicarle al blog, no quería dejar de escribir este pequeño tip sobre como se recogen variables externas en AS3. No es que sea nada muy complejo (la verdad es que incluso en la ayuda se comenta), pero me resultó curioso cuando el otro día un compañero me [...]]]></description>
			<content:encoded><![CDATA[<p>A pesar de tener <span style="text-decoration: line-through;">poco</span> cero tiempo para dedicarle al blog, no quería dejar de escribir este pequeño tip sobre como se recogen variables externas en AS3. No es que sea nada muy complejo (la verdad es que incluso en la ayuda se comenta), pero me resultó curioso cuando el otro día un compañero me preguntó si lo sabía y me di cuenta que en todo este tiempo tocando AS3 no había tenido necesidad de usarlo... Así que lo documento por si existe por ahí algún despistado como yo :)</p>
<p>Haciendo un poco de memoria, en versiones anteriores se podía acceder a las variables directamente en el  <em>_root </em>(<em>_root.miVariable</em>). Ahora es bastante menos intuitivo, aunque no carece de lógica.</p>
<p>En AS3 se utiliza la clase <em>Loader </em>cuando queremos cargar un swf o una imagen, y su propiedad <em>contentLoaderInfo </em>para acceder a la información del fichero y al proceso de carga (bytesLoaded, etc). Dicha propiedad es en realidad una instancia de la clase <em>LoaderInfo</em>. Así pues, al buscar cualquier información referente al swf, tiene sentido hacerlo en dicha clase, y las variables externas no son una excepción. Por esa razón existe una propiedad llamada <em>parameters</em>, de tipo <em>Object </em>para almacenar pares de nombre-valor.</p>
<p>Y la pregunta evidente es: si el primer swf no está cargado mediante Loader, ¿cómo acceder a esta información? La respuesta consiste en que cualquier objeto de la Display List cuenta con una propiedad <em>loaderInfo</em> que provee la información del SWF principal.</p>
<p>En este punto, si quisiéramos acceder a una variable llamada <em>textoA</em> sabemos que podemos hacerlo de la siguiente forma:</p>
<div class="igBar"><span id="lactionscript3-2"><a href="#" onclick="javascript:showCodeTxt('actionscript3-2'); return false;">Plain Text</a></span></div>
<div class="syntax_hilite">
<div id="actionscript3-2">
<div class="actionscript3">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #1518ff;">var</span> variableA:<span style="color: #000099;">String</span> = <span style="color: #000099;">this</span>.<span style="color: #000099;">loaderInfo</span>.<span style="color: #000000;">parameters</span>.<span style="color: #000000;">textoA</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>donde <em>this</em> puede ser tanto el <em>DocumentClass </em>como cualquier frame del timeline.</p>
<p>Y un par de consideraciones:</p>
<ul>
<li>Debemos asegurarnos que al acceder a <em>loaderInfo </em>en un objeto, además de ser del tipo <em>Display</em>, éste se encuentre en la <em>Display List</em>, ya que sino generará error.</li>
<li>Sino se conocen el número de variables a recibir, podemos usar un <em>for..in</em> sobre <em>parameters</em> para que nos muestre todos los valores, ya que es un Object.</li>
</ul>
<p>Dejo un ejemplo que utiliza <a title="swfobject" href="http://code.google.com/p/swfobject/" target="_blank">swfobject 2.1</a> para cargar un swf y pasarle 2 variables que se muestran en cajas de texto:<br />
<a title="Descargar ejemplo" href="http://llops.com/blog/content/articulos/sep08/ejemplo_variables.zip">Descargar ejemplo</a>.</p>
<hr />
<p><small>
<a href="http://llops.com/blog/2008/09/19/recogiendo-variables-externas/#comments">2 comentarios</a> | <a href="http://llops.com/blog/2008/09/19/recogiendo-variables-externas/">Permalink</a> | 
Add to
<a href="http://del.icio.us/post?url=http://llops.com/blog/2008/09/19/recogiendo-variables-externas/&title=Recogiendo variables externas">del.icio.us</a>
<br/><br/>
<a href="http://llops.com/blog">LLops Blog</a>, 2008
</small></p>]]></content:encoded>
			<wfw:commentRss>http://llops.com/blog/2008/09/19/recogiendo-variables-externas/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Habilitar botón derecho en AS3</title>
		<link>http://llops.com/blog/2008/07/06/habilitar-boton-derecho-en-as3/</link>
		<comments>http://llops.com/blog/2008/07/06/habilitar-boton-derecho-en-as3/#comments</comments>
		<pubDate>Sun, 06 Jul 2008 15:52:20 +0000</pubDate>
		<dc:creator>llops</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[botón derecho]]></category>
		<category><![CDATA[menu contextual]]></category>

		<guid isPermaLink="false">http://llops.com/blog/?p=34</guid>
		<description><![CDATA[Es sabido que en Flash Player no se puede utilizar el botón derecho del mouse de forma "propietaria". Con dicho botón se activa el menú contextual, y aunque se puede modificar, como mínimo encontramos las opciones Configuración y Acerca de Adobe Flash Player 9... 
Pues navegando por Google Code me he encontrado un proyecto llamado [...]]]></description>
			<content:encoded><![CDATA[<p>Es sabido que en Flash Player no se puede utilizar el botón derecho del mouse de forma "propietaria". Con dicho botón se activa el menú contextual, y aunque se puede modificar, como mínimo encontramos las opciones <strong>Configuración</strong> y <strong>Acerca de Adobe Flash Player 9...</strong> </p>
<p>Pues navegando por <a href="http://code.google.com/">Google Code</a> me he encontrado un proyecto llamado <a href="http://code.google.com/p/custom-context-menu/">Custom-context-menu</a> que nos permite utilizar a nuestro antojo el botón derecho. Para ello combina javascript y flash de una manera muy ingeniosa. Básicamente el hack consiste en:</p>
<ul>
<li>Con javascript, capturar el click derecho en HTML antes que llegue al swf</li>
<li>Una vez capturado el evento, informar al swf mediante ExternalInterface</li>
<li>Crear una función en ActionScript que responda a la llamada de ExternalInterface</li>
</ul>
<p>Se puede ver un ejemplo <a href="http://www.uza.lt/rightclick/index.php">aquí</a>.</p>
<p>Aunque puede ser un recurso muy útil, hay que tener en cuenta los siguientes inconvenientes:</p>
<ul>
<li>Funciona en la mayoría de navegadores/so, pero no en todos</li>
<li>Antes de tener el evento en AS, recorre un ciclo de llamadas entre el swf y el html, con lo que el rendimiento es mucho peor que una llamada nativa</li>
<li>En el menú contextual se encuentran las opciones de configuración del Flash Player, y estaríamos quitándoselas al usuario</li>
</ul>
<p>Aún así, en casos específicos en los que sería muy importante tener este botón habilitado, es una gran solución y no está de más conocerla.</p>
<hr />
<p><small>
<a href="http://llops.com/blog/2008/07/06/habilitar-boton-derecho-en-as3/#comments">2 comentarios</a> | <a href="http://llops.com/blog/2008/07/06/habilitar-boton-derecho-en-as3/">Permalink</a> | 
Add to
<a href="http://del.icio.us/post?url=http://llops.com/blog/2008/07/06/habilitar-boton-derecho-en-as3/&title=Habilitar botón derecho en AS3">del.icio.us</a>
<br/><br/>
<a href="http://llops.com/blog">LLops Blog</a>, 2008
</small></p>]]></content:encoded>
			<wfw:commentRss>http://llops.com/blog/2008/07/06/habilitar-boton-derecho-en-as3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Accediendo al stage antes de tiempo</title>
		<link>http://llops.com/blog/2008/02/18/accediendo-al-stage-antes-de-tiempo/</link>
		<comments>http://llops.com/blog/2008/02/18/accediendo-al-stage-antes-de-tiempo/#comments</comments>
		<pubDate>Mon, 18 Feb 2008 15:07:59 +0000</pubDate>
		<dc:creator>llops</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[added]]></category>
		<category><![CDATA[addedToStage]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[Error #1009]]></category>
		<category><![CDATA[stage]]></category>

		<guid isPermaLink="false">http://llops.com/blog/2008/02/18/accediendo-al-stage-antes-de-tiempo/</guid>
		<description><![CDATA[En AS3 es una práctica habitual asociar eventos al stage para cogerlos globalmente. El caso más utilizado probablemente se dé con los del tipo MouseEvent. Por ejemplo, si tenemos varios objetos en pantalla, en vez de definir un evento click para cada uno de ellos, cogemos sólo el click en el escenario (global) y vemos [...]]]></description>
			<content:encoded><![CDATA[<p>En AS3 es una práctica habitual asociar eventos al <em>stage</em> para cogerlos globalmente. El caso más utilizado probablemente se dé con los del tipo <em>MouseEvent</em>. Por ejemplo, si tenemos varios objetos en pantalla, en vez de definir un evento click para cada uno de ellos, cogemos sólo el click en el escenario (global) y vemos sobre quién se está interactuando:</p>
<p>
<div class="igBar"><span id="lactionscript3-7"><a href="#" onclick="javascript:showCodeTxt('actionscript3-7'); return false;">Plain Text</a></span></div>
<div class="syntax_hilite">
<div id="actionscript3-7">
<div class="actionscript3">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000099;">this</span>.<span style="color: #000099;">stage</span>.<span style="color: #000000;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #000099;">MouseEvent</span>.<span style="color: #000000;">CLICK</span>, click<span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #1518ff;">private</span> <span style="color: #1518ff;">function</span> click<span style="color: #000000;">&#40;</span>e:<span style="color: #000099;">MouseEvent</span><span style="color: #000000;">&#41;</span>:<span style="color: #000099;">void</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; trace<span style="color: #000000;">&#40;</span><span style="color: #398EC6;">"Click en"</span>, e.<span style="color: #000000;">target</span><span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p> </p>
<p>Pero a veces, cuando intentamos añadir un evento al <em>stage</em> obtenemos el siguiente error:</p>
<blockquote>
<p>TypeError: Error #1009: No se puede acceder a una propiedad o a un método de una referencia a un objeto nulo.</p>
</blockquote>
<p>Vamos a reproducir el error.</p>
<p><span id="more-25"></span></p>
<p>Tenemos dos clases: <em>Main</em>, asociada al <em>documentClass</em>, y <em>Circulo</em>, que se encarga de dibujar un pequeño circulo y capta un evento <em>click</em>.</p>
<p><u>Clase Main</u></p>
<p>
<div class="igBar"><span id="lactionscript3-8"><a href="#" onclick="javascript:showCodeTxt('actionscript3-8'); return false;">Plain Text</a></span></div>
<div class="syntax_hilite">
<div id="actionscript3-8">
<div class="actionscript3">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #1518ff;">package</span> <span style="color: #000000;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #1518ff;">import</span> flash.<span style="color: #000000;">display</span>.<span style="color: #000099;">Sprite</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #1518ff;">import</span> Circulo;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<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:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #1518ff;">public</span> <span style="color: #1518ff;">class</span> Main <span style="color: #1518ff;">extends</span> <span style="color: #000099;">Sprite</span> <span style="color: #000000;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #1518ff;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #1518ff;">var</span> c:Circulo = <span style="color: #1518ff;">new</span> Circulo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addChild<span style="color: #000000;">&#40;</span>c<span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p> </p>
<p>&nbsp;</p>
<p><u>Clase Circulo</u></p>
<p>
<div class="igBar"><span id="lactionscript3-9"><a href="#" onclick="javascript:showCodeTxt('actionscript3-9'); return false;">Plain Text</a></span></div>
<div class="syntax_hilite">
<div id="actionscript3-9">
<div class="actionscript3">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #1518ff;">package</span> <span style="color: #000000;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #1518ff;">import</span> flash.<span style="color: #000000;">display</span>.<span style="color: #000099;">Sprite</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #1518ff;">import</span> flash.<span style="color: #000000;">events</span>.*;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<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:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #1518ff;">public</span> <span style="color: #1518ff;">class</span> Circulo <span style="color: #1518ff;">extends</span> <span style="color: #000099;">Sprite</span> <span style="color: #000000;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #1518ff;">function</span> Circulo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF9933; font-style: italic;">// Dibujar Circulo</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000099;">this</span>.<span style="color: #000099;">graphics</span>.<span style="color: #000000;">beginFill</span><span style="color: #000000;">&#40;</span>0xFF0000<span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000099;">this</span>.<span style="color: #000099;">graphics</span>.<span style="color: #000000;">drawCircle</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;color:#000099;">50</span>, <span style="color: #FF0000;color:#000099;">50</span>, <span style="color: #FF0000;color:#000099;">10</span><span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000099;">this</span>.<span style="color: #000099;">graphics</span>.<span style="color: #000000;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF9933; font-style: italic;">// Definir el evento click</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000099;">this</span>.<span style="color: #000099;">stage</span>.<span style="color: #000000;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #000099;">MouseEvent</span>.<span style="color: #000000;">CLICK</span>, clic<span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #1518ff;">private</span> <span style="color: #1518ff;">function</span> clic<span style="color: #000000;">&#40;</span>e:<span style="color: #000099;">MouseEvent</span><span style="color: #000000;">&#41;</span>:<span style="color: #000099;">void</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #1518ff;">if</span> <span style="color: #000000;">&#40;</span>e.<span style="color: #000000;">target</span> == <span style="color: #000099;">this</span><span style="color: #000000;">&#41;</span> trace<span style="color: #000000;">&#40;</span><span style="color: #398EC6;">"Click sobre circulo"</span><span style="color: #000000;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #1518ff;">else</span> trace<span style="color: #000000;">&#40;</span><span style="color: #398EC6;">"No es circulo"</span><span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p> </p>
<p>Si compilamos obtenemos:</p>
<blockquote>
<p>TypeError: Error #1009: No se puede acceder a una propiedad o a un método de una referencia a un objeto nulo.<br />&nbsp;&nbsp;&nbsp; at Circulo()<br />&nbsp;&nbsp;&nbsp; at Main()</p>
</blockquote>
<p>&nbsp;</p>
<p><strong><u>¿Por qué obtenemos este error?</u></strong></p>
<p><em>Stage</em> es el contenedor base de todos los objetos visuales y se encuentra en lo más alto de la <em>displayList</em>.&nbsp; Este contenedor no se puede acceder directamente, sino que se tiene que hacer mediante la propiedad stage, que se encuentra en cualquier objeto que extiende de <em>DisplayObject</em>.</p>
<p>Nuestro objeto Circulo extiende de <em>Sprite</em> y por tanto es un <em>DisplayObject</em> que soporta la propiedad <em>stage</em>, pero <strong>cuando intentamos acceder a dicha propiedad el objeto no se encuentra todavía en la displayList y por tanto la referencia es nula</strong>.</p>
<p>&nbsp;</p>
<p><strong><u>Solución</u></strong></p>
<p>Para solucionar esto existen dos eventos muy útiles definidos en <em>DisplayObjet</em>: <em>added</em> y <em>addedToStage</em>. El primero se dispacha cuando un objeto se añade a la <em>displayList</em> y el segundo cuando se añade al escenario.</p>
<p>Así pues, podemos suscribirnos a estos eventos antes de acceder al <em>stage</em> y así garantizar que está disponible y que no genera error.</p>
<p>Finalmente nuestra clase Circulo quedaría:</p>
<p>
<div class="igBar"><span id="lactionscript3-10"><a href="#" onclick="javascript:showCodeTxt('actionscript3-10'); return false;">Plain Text</a></span></div>
<div class="syntax_hilite">
<div id="actionscript3-10">
<div class="actionscript3">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #1518ff;">package</span> <span style="color: #000000;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #1518ff;">import</span> flash.<span style="color: #000000;">display</span>.<span style="color: #000099;">Sprite</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #1518ff;">import</span> flash.<span style="color: #000000;">events</span>.*;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<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:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #1518ff;">public</span> <span style="color: #1518ff;">class</span> Circulo <span style="color: #1518ff;">extends</span> <span style="color: #000099;">Sprite</span> <span style="color: #000000;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #1518ff;">function</span> Circulo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF9933; font-style: italic;">// Dibujar Circulo</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000099;">this</span>.<span style="color: #000099;">graphics</span>.<span style="color: #000000;">beginFill</span><span style="color: #000000;">&#40;</span>0xFF0000<span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000099;">this</span>.<span style="color: #000099;">graphics</span>.<span style="color: #000000;">drawCircle</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;color:#000099;">50</span>, <span style="color: #FF0000;color:#000099;">50</span>, <span style="color: #FF0000;color:#000099;">10</span><span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000099;">this</span>.<span style="color: #000099;">graphics</span>.<span style="color: #000000;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF9933; font-style: italic;">// Escuchar el evento ADDED</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000099;">this</span>.<span style="color: #000000;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #000099;">Event</span>.<span style="color: #000000;">ADDED</span>, init<span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF9933; font-style: italic;">// o en este caso también ADDED_TO_STAGE</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF9933; font-style: italic;">//this.addEventListener(Event.ADDED_TO_STAGE, init);</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #1518ff;">private</span> <span style="color: #1518ff;">function</span> init<span style="color: #000000;">&#40;</span>e:<span style="color: #000099;">Event</span><span style="color: #000000;">&#41;</span>:<span style="color: #000099;">void</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF9933; font-style: italic;">// Definir el evento click</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000099;">this</span>.<span style="color: #000099;">stage</span>.<span style="color: #000000;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #000099;">MouseEvent</span>.<span style="color: #000000;">CLICK</span>, clic<span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #1518ff;">private</span> <span style="color: #1518ff;">function</span> clic<span style="color: #000000;">&#40;</span>e:<span style="color: #000099;">MouseEvent</span><span style="color: #000000;">&#41;</span>:<span style="color: #000099;">void</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #1518ff;">if</span> <span style="color: #000000;">&#40;</span>e.<span style="color: #000000;">target</span> == <span style="color: #000099;">this</span><span style="color: #000000;">&#41;</span> trace<span style="color: #000000;">&#40;</span><span style="color: #398EC6;">"Click sobre circulo"</span><span style="color: #000000;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #1518ff;">else</span> trace<span style="color: #000000;">&#40;</span><span style="color: #398EC6;">"No es circulo"</span><span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#666666;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p> </p>
<p><a title="Descargar ejemplo" href="/blog/content/articulos/feb08/addedToStage.zip" target="_blank">&gt;&gt; Descargar ejemplo</a></p></p>
<hr />
<p><small>
<a href="http://llops.com/blog/2008/02/18/accediendo-al-stage-antes-de-tiempo/#comments">19 comentarios</a> | <a href="http://llops.com/blog/2008/02/18/accediendo-al-stage-antes-de-tiempo/">Permalink</a> | 
Add to
<a href="http://del.icio.us/post?url=http://llops.com/blog/2008/02/18/accediendo-al-stage-antes-de-tiempo/&title=Accediendo al stage antes de tiempo">del.icio.us</a>
<br/><br/>
<a href="http://llops.com/blog">LLops Blog</a>, 2008
</small></p>]]></content:encoded>
			<wfw:commentRss>http://llops.com/blog/2008/02/18/accediendo-al-stage-antes-de-tiempo/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
	</channel>
</rss>
