<?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>JLC Productions &#187; SEO</title>
	<atom:link href="http://jlc-productions.net/tag/seo/feed/" rel="self" type="application/rss+xml" />
	<link>http://jlc-productions.net</link>
	<description>Diseño Web, Animación Flash y mucho más</description>
	<lastBuildDate>Mon, 06 Sep 2010 10:45:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Deep linking en Flash con SWFAddress</title>
		<link>http://jlc-productions.net/apuntes/as3/2009/02/deep-linking-en-flash-con-swfaddress/</link>
		<comments>http://jlc-productions.net/apuntes/as3/2009/02/deep-linking-en-flash-con-swfaddress/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 21:17:02 +0000</pubDate>
		<dc:creator>Juanlu001</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[SWFAddress]]></category>

		<guid isPermaLink="false">http://jlc-productions.net/?p=689</guid>
		<description><![CDATA[Cuando estamos trabajando en una web 100% hecha en Flash, lo que más nos preocupa a los desarrolladores es el SEO, es decir, que dicha web esté correctamente posicionada en los buscadores. El hecho de que los robots de los motores de búsqueda no puedan acceder al contenido de un archivo .swf (salvo, quizás, el [...]


Related posts:<ol><li><a href='http://jlc-productions.net/apuntes/as3/2009/03/precarga-en-flash-aparece-a-la-mitad/' rel='bookmark' title='Permanent Link: Precarga en Flash aparece a la mitad'>Precarga en Flash aparece a la mitad</a></li>
<li><a href='http://jlc-productions.net/apuntes/as3/2009/01/precarga-en-actionscript-3/' rel='bookmark' title='Permanent Link: Precarga en ActionScript 3'>Precarga en ActionScript 3</a></li>
<li><a href='http://jlc-productions.net/blog/2008/01/he-recuperado-los-fla/' rel='bookmark' title='Permanent Link: ¡¡He recuperado los fla!!'>¡¡He recuperado los fla!!</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Cuando estamos trabajando en una <strong>web 100% hecha en Flash</strong>, lo que más nos preocupa a los desarrolladores es el <acronym title="Search Engine Optimization">SEO</acronym>, es decir, que dicha web esté <em>correctamente posicionada en los buscadores</em>. El hecho de que los robots de los motores de búsqueda no puedan acceder al contenido de un archivo .swf (salvo, quizás, el caso de Google, pero yo no me relajaría demasiado) y, sobre todo, el problema de que una sola URL corresponda a todo el contenido del sitio, pueden acarrear serios problemas a la hora de querer aparecer en las primeras posiciones de los buscadores <em>sin pagar</em>. Ya que el primer punto no depende de nosotros y nada podemos hacer para remediarlo (salvo olvidarnos de Flash), vamos a aprender cómo solucionar el segundo. Para ello, nos serviremos de una pequeña pero potente librería que cambiará totalmente nuestra filosofía a la hora de enfocar nuestros nuevos proyectos: <a href="http://www.asual.com/swfaddress/">SWFAddress</a>, la cual nos permitirá <strong>asignar a cada estado de nuestra película una URL distinta</strong>, lo que nos permitirá <strong>usar los botones atrás y adelante en Flash</strong>, <strong>asignar un título a cada sección de la web</strong> y <strong>agregar una parte concreta a favoritos</strong>, entre otras cosas. <span id="more-689"></span></p>
<p>Soy consciente de que el tema esta <strong>muy</strong> mal documentado en castellano; de hecho, yo encontré muy poca información en los buscadores cuando quise aprender a utilizar esta librería (salvo el <a href="http://www.decabeza.net/2008/12/17/nuevo-video-tutorial-swfaddress-2-con-as3/">videotutorial en DeCabeza.net</a>, que me ayudó muchísimo). Además, los ejemplos que hay disponibles para descargar en su sitio web, aparte de estar repetidos, son, en mi opinión, malísimos. Por esta razón me ha parecido conveniente escribir mi propia aportación para gente que esté interesada en <strong>mejorar la indexación de sus webs en Flash</strong> y que tenga pereza de buscar información en inglés o que simplemente necesite una explicación detallada de cómo implementar la librería de manera sencilla.</p>
<p>Para este apunte voy a utilizar <strong>ActionScript 3</strong> (ya hay un <a href="http://blog.unijimpe.net/swfaddress/">ejemplo muy bueno en AS2 en unijimpe</a>), que es el que recomiendo utilizar. Además, necesitaremos también la librería <a href="http://code.google.com/p/swfobject/">SWFObject</a> para incrustar nuestros archivos .swf en el documento HTML. Si lo deseas, puedes descargar ya los archivos que he utilizado para el apunte para poder comprobar cómo quedan los ejemplos:</p>
<p><a class="download" href="http://jlc-productions.net/wp-content/uploads/2009/02/swfaddress.zip"><span>Descargar </span>swfaddress.zip<br />(66,63 KiB)</a></p>

<h3>Introducción: Descargar las librerías SWFAddress y SWFObject</h3>
<p>En primer lugar, dirígete al sitio web de SWFAddress: <a href="http://www.asual.com/swfaddress/">http://www.asual.com/swfaddress/</a>, y haz click en el enlace &#8220;Descargar SWFAddress 2.2&#8243; (esa es la última versión en el momento de escribir esto). El archivo contiene varias carpetas, con montones de ejemplos y documentación además de los archivos en sí, pero nos vamos a dirigir al directorio <code>samples</code> y, dentro de este, al de <code>CS3</code>. Esta carpeta contiene un ejemplo de uso de <strong>SWFAddress en ActionScript 3</strong>, al que puedes echar una ojeada, pero vamos a construir nosotros nuestro propio ejemplo. Para ello, extrae en un mismo directorio las carpetas <code>swfaddress</code> y <code>swfobject</code> y las clases de ActionScript <code>SWFAddress.as</code> y <code>SWFAddressEvent.as</code>. Ahora ya tenemos todo lo necesario para comenzar a trabajar en nuestro mini sitio web en Flash.</p>
<h3>1. Preparar el documento Flash</h3>
<p>Crea un nuevo documento en Flash con ActionScript 3 con las dimensiones y la velocidad de fotogramas por segundo que consideres convenientes, y titúlalo <code>swfaddress_web.fla</code>. Yo he utilizado el tamaño estándar de Flash, 550 px de ancho y 400 px de alto, y 30fps. Ahora vamos a incluir algunos elementos para que nuestra película tenga la pinta de un <em>microsite</em> en Flash. Yo he agregado los siguientes elementos:</p>
<ul>
<li>En una capa, un campo de texto estático con el texto &#8220;SWFAddress fácil con Juanlu&#8221; que hace las veces de título.</li>
<li>En otra, tres botones para la navegación, con el texto &#8220;Inicio&#8221;, &#8220;¿Qué?&#8221; y &#8220;¿Cómo?&#8221;, y los nombres de instancia <code>inicio_bt</code>, <code>que_bt</code> y <code>como_bt</code> respectivamente.</li>
<li>En una tercera, dos campos de texto dinámicos donde cargaremos el contenido.</li>
</ul>
<p>El aspecto de la película en este momento es este:</p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_0" width="550" height="400">
      <param name="movie" value="http://jlc-productions.net/wp-content/uploads/2009/02/swfaddress_inicio.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://jlc-productions.net/wp-content/uploads/2009/02/swfaddress_inicio.swf" width="550" height="400">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<p>Ya tenemos preparada nuestra película; vamos ahora a añadirle funcionalidad.</p>
<h3>2. Agregar el código para el manejo de SWFAddress</h3>
<p>Vamos a crear un nuevo documento de ActionScript llamado <code>Document.as</code> y se lo vamos a asignar como clase de documento a nuestra película. Para empezar, escribe las siguientes líneas:</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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #f00; font-weight: bold;">package</span>
<span style="color: #666; font-weight: bold;">&#123;</span>
	<span style="color: #f00;">import</span> <span style="color: #03c;">flash.display</span>.<span style="color: #039;">Sprite</span>;
	<span style="color: #f00;">import</span> <span style="color: #03c;">flash.events</span>.<span style="color: #039;">MouseEvent</span>;
&nbsp;
	<span style="color: #f00;">import</span> SWFAddress;
	<span style="color: #f00;">import</span> SWFAddressEvent;
&nbsp;
	<span style="color: #f00;">public</span> <span style="color: #f00; font-weight: bold;">class</span> Document <span style="color: #f00;">extends</span> <span style="color: #039;">Sprite</span>
	<span style="color: #666; font-weight: bold;">&#123;</span>
		<span style="color: #36c; font-weight: bold;">var</span> webXMLData<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">XML</span>;
&nbsp;
		<span style="color: #03c; font-weight: bold;">function</span> Document<span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #666; font-weight: bold;">&#41;</span><span style="color: #000; font-weight: bold;">:</span><span style="color: #f00;">void</span>
		<span style="color: #666; font-weight: bold;">&#123;</span>
			<span style="color: #090; font-style: italic;">// Función constructora</span>
		<span style="color: #666; font-weight: bold;">&#125;</span>
	<span style="color: #666; font-weight: bold;">&#125;</span>
<span style="color: #666; font-weight: bold;">&#125;</span></pre></td></tr></table></div>

<p>No tiene ningún misterio. Ahora, vamos a definir en una variable XML el contenido de la web para después cargar la parte que corresponda mediante tres listener que se activen al hacer clic en cada uno de los botones que tenemos en el escenario. Hay que añadir este código a la clase:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #03c; font-weight: bold;">function</span> Document<span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #666; font-weight: bold;">&#41;</span><span style="color: #000; font-weight: bold;">:</span><span style="color: #f00;">void</span>
<span style="color: #666; font-weight: bold;">&#123;</span>
	<span style="color: #090; font-style: italic;">// Definimos el contenido de la web</span>
	webXMLData =
&nbsp;
			<span style="color: #000; font-weight: bold;">/</span>
&nbsp;
			<span style="color: #000; font-weight: bold;">&lt;!</span><span style="color: #666; font-weight: bold;">&#91;</span>CDATA<span style="color: #666; font-weight: bold;">&#91;</span>Cuando estamos trabajando en una web <span style="color: #f00;">100</span><span style="color: #000; font-weight: bold;">%</span> hecha en Flash, lo que más nos preocupa a los desarrolladores es el <span style="color: #000; font-weight: bold;">&lt;</span>u<span style="color: #000; font-weight: bold;">&gt;</span>SEO<span style="color: #000; font-weight: bold;">&lt;/</span>u<span style="color: #000; font-weight: bold;">&gt;</span>, es decir, que dicha web esté <span style="color: #000; font-weight: bold;">&lt;</span>i<span style="color: #000; font-weight: bold;">&gt;</span>correctamente posicionada en los buscadores<span style="color: #000; font-weight: bold;">&lt;/</span>i<span style="color: #000; font-weight: bold;">&gt;</span>. Para mejorar este aspecto, nos serviremos de una pequeña pero potente librería que cambiará totalmente nuestra filosofía a la hora de enfocar nuestros nuevos proyectos<span style="color: #000; font-weight: bold;">:</span> <span style="color: #000; font-weight: bold;">&lt;</span>b<span style="color: #000; font-weight: bold;">&gt;</span>SWFAddress<span style="color: #000; font-weight: bold;">&lt;/</span>b<span style="color: #000; font-weight: bold;">&gt;</span>, la cual nos permitirá asignar a cada estado de nuestra película una URL distinta.
			<span style="color: #666; font-weight: bold;">&#93;</span><span style="color: #666; font-weight: bold;">&#93;</span><span style="color: #000; font-weight: bold;">&gt;</span>
			<span style="color: #000; font-weight: bold;">&lt;/</span>content<span style="color: #000; font-weight: bold;">&gt;</span>
		<span style="color: #000; font-weight: bold;">&lt;/</span>seccion<span style="color: #000; font-weight: bold;">&gt;</span>
		<span style="color: #000; font-weight: bold;">&lt;</span>seccion<span style="color: #000; font-weight: bold;">&gt;</span>
&nbsp;
			<span style="color: #000; font-weight: bold;">&lt;</span>url<span style="color: #000; font-weight: bold;">&gt;/</span>que<span style="color: #000; font-weight: bold;">/&lt;/</span>url<span style="color: #000; font-weight: bold;">&gt;</span>
			<span style="color: #000; font-weight: bold;">&lt;</span>content<span style="color: #000; font-weight: bold;">&gt;</span>
			<span style="color: #000; font-weight: bold;">&lt;!</span> <span style="color: #666; font-weight: bold;">&#91;</span>CDATA<span style="color: #666; font-weight: bold;">&#91;</span>Qué 			<span style="color: #666; font-weight: bold;">&#93;</span><span style="color: #666; font-weight: bold;">&#93;</span><span style="color: #000; font-weight: bold;">&gt;</span>
			<span style="color: #000; font-weight: bold;">&lt;/</span>content<span style="color: #000; font-weight: bold;">&gt;</span>
		<span style="color: #000; font-weight: bold;">&lt;/</span>seccion<span style="color: #000; font-weight: bold;">&gt;</span>
		<span style="color: #000; font-weight: bold;">&lt;</span>seccion<span style="color: #000; font-weight: bold;">&gt;</span>
&nbsp;
			<span style="color: #000; font-weight: bold;">&lt;</span>url<span style="color: #000; font-weight: bold;">&gt;/</span>como<span style="color: #000; font-weight: bold;">/&lt;/</span>url<span style="color: #000; font-weight: bold;">&gt;</span>
			<span style="color: #000; font-weight: bold;">&lt;</span>content<span style="color: #000; font-weight: bold;">&gt;</span>
			<span style="color: #000; font-weight: bold;">&lt;!</span><span style="color: #666; font-weight: bold;">&#91;</span>CDATA<span style="color: #666; font-weight: bold;">&#91;</span>Cómo 			<span style="color: #666; font-weight: bold;">&#93;</span><span style="color: #666; font-weight: bold;">&#93;</span><span style="color: #000; font-weight: bold;">&gt;</span>
&nbsp;
	;
&nbsp;
	<span style="color: #090; font-style: italic;">// Añadimos los listener</span>
	inicio_bt.<span style="color: #069;">addEventListener</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #039;">MouseEvent</span>.<span style="color: #039;">CLICK</span>, mouseHandler<span style="color: #666; font-weight: bold;">&#41;</span>;
	que_bt.<span style="color: #069;">addEventListener</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #039;">MouseEvent</span>.<span style="color: #039;">CLICK</span>, mouseHandler<span style="color: #666; font-weight: bold;">&#41;</span>;
	como_bt.<span style="color: #069;">addEventListener</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #039;">MouseEvent</span>.<span style="color: #039;">CLICK</span>, mouseHandler<span style="color: #666; font-weight: bold;">&#41;</span>;
<span style="color: #666; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #03c; font-weight: bold;">function</span> mouseHandler<span style="color: #666; font-weight: bold;">&#40;</span>e<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">MouseEvent</span><span style="color: #666; font-weight: bold;">&#41;</span><span style="color: #000; font-weight: bold;">:</span><span style="color: #f00;">void</span>
<span style="color: #666; font-weight: bold;">&#123;</span>
	<span style="color: #090; font-style: italic;">// Manejo de los botones</span>
<span style="color: #666; font-weight: bold;">&#125;</span></pre></td></tr></table></div>

<p>Ahora es cuando viene lo interesante: en la función <code>mouseHandler</code> que acabamos de definir, para no complicarnos más la vida ya podríamos cargar en nuestro campo de texto la sección correspondiente al botón en el que se hizo click, pero con SWFAddress esto no se hace así. Este es el código de la función <code>mouseHandler</code>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #03c; font-weight: bold;">function</span> mouseHandler<span style="color: #666; font-weight: bold;">&#40;</span>e<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">MouseEvent</span><span style="color: #666; font-weight: bold;">&#41;</span><span style="color: #000; font-weight: bold;">:</span><span style="color: #f00;">void</span>
<span style="color: #666; font-weight: bold;">&#123;</span>
	<span style="color: #36c; font-weight: bold;">var</span> _url<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">String</span> = <span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #039;">String</span><span style="color: #666; font-weight: bold;">&#40;</span>e.<span style="color: #069;">target</span>.<span style="color: #069;">name</span><span style="color: #666; font-weight: bold;">&#41;</span> == <span style="color: #900;">&quot;inicio_bt&quot;</span><span style="color: #666; font-weight: bold;">&#41;</span> <span style="color: #000; font-weight: bold;">?</span> <span style="color: #900;">&quot;/&quot;</span> <span style="color: #000; font-weight: bold;">:</span> <span style="color: #900;">&quot;/&quot;</span> <span style="color: #000; font-weight: bold;">+</span> <span style="color: #039;">String</span><span style="color: #666; font-weight: bold;">&#40;</span>e.<span style="color: #069;">target</span>.<span style="color: #069;">name</span><span style="color: #666; font-weight: bold;">&#41;</span>.<span style="color: #069;">replace</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #900;">&quot;_bt&quot;</span>, <span style="color: #900;">&quot;/&quot;</span><span style="color: #666; font-weight: bold;">&#41;</span>;
	<span style="color: #090; font-style: italic;">// Este código producirá, en función del nombre del botón, esto:</span>
	<span style="color: #090; font-style: italic;">// nombre_bt --&amp;gt; /nombre/</span>
	<span style="color: #090; font-style: italic;">// que será lo que tomemos como &quot;url&quot;</span>
	<span style="color: #090; font-style: italic;">// NOTA: El condicional terciario es para transformar /inicio/ en /, más útil</span>
&nbsp;
	<span style="color: #090; font-style: italic;">// Línea clave</span>
	SWFAddress.setValue<span style="color: #666; font-weight: bold;">&#40;</span>_url<span style="color: #666; font-weight: bold;">&#41;</span>;
<span style="color: #666; font-weight: bold;">&#125;</span></pre></td></tr></table></div>

<p>Este es un punto importante en el flujo del programa: aunque si ahora probamos la película no notaremos ningún cambio, le estamos <em>diciendo</em> a la clase SWFAddress que <em>estamos en la URL definida en la variable</em> <code>_url</code>. Ahora escribiremos la función que manejará esos cambios de URL, la pieza central de nuestro apunte:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #03c; font-weight: bold;">function</span> Document<span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #666; font-weight: bold;">&#41;</span><span style="color: #000; font-weight: bold;">:</span><span style="color: #f00;">void</span>
<span style="color: #666; font-weight: bold;">&#123;</span>
	<span style="color: #090; font-style: italic;">// Añadimos un listener para la función</span>
	SWFAddress.<span style="color: #069;">addEventListener</span><span style="color: #666; font-weight: bold;">&#40;</span>SWFAddressEvent.<span style="color: #039;">CHANGE</span>, onSWFAddressChange<span style="color: #666; font-weight: bold;">&#41;</span>;
	<span style="color: #090; font-style: italic;">// El valor al inicio es /</span>
&nbsp;
	<span style="color: #090; font-style: italic;">// [...]</span>
<span style="color: #666; font-weight: bold;">&#125;</span></pre></td></tr></table></div>


<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="actionscript3" style="font-family:monospace;"><span style="color: #03c; font-weight: bold;">function</span> onSWFAddressChange<span style="color: #666; font-weight: bold;">&#40;</span>e<span style="color: #000; font-weight: bold;">:</span>SWFAddressEvent<span style="color: #666; font-weight: bold;">&#41;</span><span style="color: #000; font-weight: bold;">:</span><span style="color: #f00;">void</span>
<span style="color: #666; font-weight: bold;">&#123;</span>
	<span style="color: #090; font-style: italic;">// URL actual</span>
	<span style="color: #36c; font-weight: bold;">var</span> _url<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">String</span> = e.<span style="color: #069;">value</span>;
&nbsp;
	<span style="color: #090; font-style: italic;">// Almacenamos en una variable XMLList la sección actual</span>
	<span style="color: #36c; font-weight: bold;">var</span> seccion<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">XMLList</span> = webXMLData.seccion.<span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #069;">url</span> == _url<span style="color: #666; font-weight: bold;">&#41;</span>;
&nbsp;
	<span style="color: #069;">trace</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #900;">&quot;SWFAddress value: &quot;</span> <span style="color: #000; font-weight: bold;">+</span> _url<span style="color: #666; font-weight: bold;">&#41;</span>;
&nbsp;
	<span style="color: #090; font-style: italic;">// Cargamos el contenido</span>
	contenido.<span style="color: #069;">htmlText</span> = seccion.<span style="color: #069;">content</span>;
&nbsp;
	<span style="color: #090; font-style: italic;">// Cambiamos el título</span>
	titulo.<span style="color: #069;">text</span> = seccion.title;
	SWFAddress.setTitle<span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #900;">&quot;SWFAddress Fácil - &quot;</span> <span style="color: #000; font-weight: bold;">+</span> seccion.title<span style="color: #666; font-weight: bold;">&#41;</span>;
<span style="color: #666; font-weight: bold;">&#125;</span></pre></td></tr></table></div>

<p>El código de la clase <code>Document</code> queda ahora así:</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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #f00; font-weight: bold;">package</span>
<span style="color: #666; font-weight: bold;">&#123;</span>
	<span style="color: #f00;">import</span> <span style="color: #03c;">flash.display</span>.<span style="color: #039;">Sprite</span>;
	<span style="color: #f00;">import</span> <span style="color: #03c;">flash.events</span>.<span style="color: #039;">MouseEvent</span>;
&nbsp;
	<span style="color: #f00;">import</span> SWFAddress;
	<span style="color: #f00;">import</span> SWFAddressEvent;
&nbsp;
	<span style="color: #f00;">public</span> <span style="color: #f00; font-weight: bold;">class</span> Document <span style="color: #f00;">extends</span> <span style="color: #039;">Sprite</span>
	<span style="color: #666; font-weight: bold;">&#123;</span>
		<span style="color: #36c; font-weight: bold;">var</span> webXMLData<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">XML</span>;
&nbsp;
		<span style="color: #03c; font-weight: bold;">function</span> Document<span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #666; font-weight: bold;">&#41;</span><span style="color: #000; font-weight: bold;">:</span><span style="color: #f00;">void</span>
		<span style="color: #666; font-weight: bold;">&#123;</span>
			<span style="color: #090; font-style: italic;">// Añadimos un listener para la función</span>
			SWFAddress.<span style="color: #069;">addEventListener</span><span style="color: #666; font-weight: bold;">&#40;</span>SWFAddressEvent.<span style="color: #039;">CHANGE</span>, onSWFAddressChange<span style="color: #666; font-weight: bold;">&#41;</span>;
			<span style="color: #090; font-style: italic;">// El valor al inicio es /</span>
&nbsp;
			<span style="color: #090; font-style: italic;">// Definimos el contenido de la web</span>
			webXMLData =
&nbsp;
					<span style="color: #000; font-weight: bold;">/</span>
&nbsp;
					<span style="color: #000; font-weight: bold;">&lt;</span>span style=<span style="color: #900;">&quot;text-decoration: underline;&quot;</span><span style="color: #000; font-weight: bold;">&gt;</span>SEO<span style="color: #000; font-weight: bold;">&lt;/</span>span<span style="color: #000; font-weight: bold;">&gt;</span>, es decir, que dicha web esté <span style="color: #000; font-weight: bold;">&lt;</span>em<span style="color: #000; font-weight: bold;">&gt;</span>correctamente posicionada en los buscadores<span style="color: #000; font-weight: bold;">&lt;/</span>em<span style="color: #000; font-weight: bold;">&gt;</span>. Para mejorar este aspecto, nos serviremos de una pequeña pero potente librería que cambiará totalmente nuestra filosofía a la hora de enfocar nuestros nuevos proyectos<span style="color: #000; font-weight: bold;">:</span> <span style="color: #000; font-weight: bold;">&lt;</span>strong<span style="color: #000; font-weight: bold;">&gt;</span>SWFAddress<span style="color: #000; font-weight: bold;">&lt;/</span>strong<span style="color: #000; font-weight: bold;">&gt;</span>, la cual nos permitirá asignar a cada estado de nuestra película una URL distinta.
					<span style="color: #666; font-weight: bold;">&#93;</span><span style="color: #666; font-weight: bold;">&#93;</span><span style="color: #000; font-weight: bold;">&amp;</span>gt;
&nbsp;
					<span style="color: #000; font-weight: bold;">/</span>que<span style="color: #000; font-weight: bold;">/</span>
&nbsp;
					<span style="color: #000; font-weight: bold;">/</span>como<span style="color: #000; font-weight: bold;">/</span>
&nbsp;
			;
&nbsp;
			<span style="color: #090; font-style: italic;">// Añadimos los listener</span>
			inicio_bt.<span style="color: #069;">addEventListener</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #039;">MouseEvent</span>.<span style="color: #039;">CLICK</span>, mouseHandler<span style="color: #666; font-weight: bold;">&#41;</span>;
			que_bt.<span style="color: #069;">addEventListener</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #039;">MouseEvent</span>.<span style="color: #039;">CLICK</span>, mouseHandler<span style="color: #666; font-weight: bold;">&#41;</span>;
			como_bt.<span style="color: #069;">addEventListener</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #039;">MouseEvent</span>.<span style="color: #039;">CLICK</span>, mouseHandler<span style="color: #666; font-weight: bold;">&#41;</span>;
		<span style="color: #666; font-weight: bold;">&#125;</span>
&nbsp;
		<span style="color: #03c; font-weight: bold;">function</span> onSWFAddressChange<span style="color: #666; font-weight: bold;">&#40;</span>e<span style="color: #000; font-weight: bold;">:</span>SWFAddressEvent<span style="color: #666; font-weight: bold;">&#41;</span><span style="color: #000; font-weight: bold;">:</span><span style="color: #f00;">void</span>
		<span style="color: #666; font-weight: bold;">&#123;</span>
			<span style="color: #090; font-style: italic;">// URL actual</span>
			<span style="color: #36c; font-weight: bold;">var</span> _url<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">String</span> = e.<span style="color: #069;">value</span>;
&nbsp;
			<span style="color: #090; font-style: italic;">// Almacenamos en una variable XMLList la sección actual</span>
			<span style="color: #36c; font-weight: bold;">var</span> seccion<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">XMLList</span> = webXMLData.seccion.<span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #069;">url</span> == _url<span style="color: #666; font-weight: bold;">&#41;</span>;
&nbsp;
			<span style="color: #069;">trace</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #900;">&quot;SWFAddress value: &quot;</span> <span style="color: #000; font-weight: bold;">+</span> _url<span style="color: #666; font-weight: bold;">&#41;</span>;
&nbsp;
			<span style="color: #090; font-style: italic;">// Cargamos el contenido</span>
			contenido.<span style="color: #069;">htmlText</span> = seccion.<span style="color: #069;">content</span>;
&nbsp;
			<span style="color: #090; font-style: italic;">// Cambiamos el título</span>
			titulo.<span style="color: #069;">text</span> = seccion.title;
			SWFAddress.setTitle<span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #900;">&quot;SWFAddress Fácil - &quot;</span> <span style="color: #000; font-weight: bold;">+</span> seccion.title<span style="color: #666; font-weight: bold;">&#41;</span>;
		<span style="color: #666; font-weight: bold;">&#125;</span>
&nbsp;
		<span style="color: #03c; font-weight: bold;">function</span> mouseHandler<span style="color: #666; font-weight: bold;">&#40;</span>e<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">MouseEvent</span><span style="color: #666; font-weight: bold;">&#41;</span><span style="color: #000; font-weight: bold;">:</span><span style="color: #f00;">void</span>
		<span style="color: #666; font-weight: bold;">&#123;</span>
			<span style="color: #36c; font-weight: bold;">var</span> _url<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">String</span> = <span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #039;">String</span><span style="color: #666; font-weight: bold;">&#40;</span>e.<span style="color: #069;">target</span>.<span style="color: #069;">name</span><span style="color: #666; font-weight: bold;">&#41;</span> == <span style="color: #900;">&quot;inicio_bt&quot;</span><span style="color: #666; font-weight: bold;">&#41;</span> <span style="color: #000; font-weight: bold;">?</span> <span style="color: #900;">&quot;/&quot;</span> <span style="color: #000; font-weight: bold;">:</span> <span style="color: #900;">&quot;/&quot;</span> <span style="color: #000; font-weight: bold;">+</span> <span style="color: #039;">String</span><span style="color: #666; font-weight: bold;">&#40;</span>e.<span style="color: #069;">target</span>.<span style="color: #069;">name</span><span style="color: #666; font-weight: bold;">&#41;</span>.<span style="color: #069;">replace</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #900;">&quot;_bt&quot;</span>, <span style="color: #900;">&quot;/&quot;</span><span style="color: #666; font-weight: bold;">&#41;</span>;
			<span style="color: #090; font-style: italic;">// Este código producirá, en función del nombre del botón, esto:</span>
			<span style="color: #090; font-style: italic;">// nombre_bt --&amp;gt; /nombre/</span>
			<span style="color: #090; font-style: italic;">// que será lo que tomemos como &quot;url&quot;</span>
			<span style="color: #090; font-style: italic;">// NOTA: El condicional terciario es para transformar /inicio/ en /, más útil</span>
&nbsp;
			<span style="color: #090; font-style: italic;">// Línea clave</span>
			SWFAddress.setValue<span style="color: #666; font-weight: bold;">&#40;</span>_url<span style="color: #666; font-weight: bold;">&#41;</span>;
		<span style="color: #666; font-weight: bold;">&#125;</span>
	<span style="color: #666; font-weight: bold;">&#125;</span>
<span style="color: #666; font-weight: bold;">&#125;</span></pre></td></tr></table></div>

<p>Ahora sí: si probamos nuestra película, podemos ver cómo el texto de las secciones cambia al hacer clic en cada uno de los botones:</p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_1" width="550" height="400">
      <param name="movie" value="http://jlc-productions.net/wp-content/uploads/2009/02/swfaddress_web.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://jlc-productions.net/wp-content/uploads/2009/02/swfaddress_web.swf" width="550" height="400">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<p>Pero la magia no acaba aquí: la gracia está en que queremos que funcione como una página web. Para eso necesitamos, como no podía ser de otra manera, un documento HTML.</p>
<h3>3. Final: el documento HTML</h3>
<p>Ahora, para finalizar, vamos a crear el documento HTML en el que insertaremos la película. En un nuevo archivo llamado <code>index.htm</code> escribe este código:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #666; font-style: italic;">&lt;!-- Importamos las dos librerías necesarias --&gt;</span>
<span style="color: #090;">&lt;<span style="color: #000; font-weight: bold;">script</span> <span style="color: #006;">src</span><span style="color: #6c6;">=</span><span style="color: #f00;">&quot;swfobject/swfobject.js&quot;</span> <span style="color: #006;">type</span><span style="color: #6c6;">=</span><span style="color: #f00;">&quot;text/javascript&quot;</span>&gt;</span><span style="color: #666; font-style: italic;">&lt;!--mce:0--&gt;</span><span style="color: #090;">&lt;<span style="color: #6c6;">/</span><span style="color: #000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #090;">&lt;<span style="color: #000; font-weight: bold;">script</span> <span style="color: #006;">src</span><span style="color: #6c6;">=</span><span style="color: #f00;">&quot;swfaddress/swfaddress.js&quot;</span> <span style="color: #006;">type</span><span style="color: #6c6;">=</span><span style="color: #f00;">&quot;text/javascript&quot;</span>&gt;</span><span style="color: #666; font-style: italic;">&lt;!--mce:1--&gt;</span><span style="color: #090;">&lt;<span style="color: #6c6;">/</span><span style="color: #000; font-weight: bold;">script</span>&gt;</span>
&nbsp;
<span style="color: #666; font-style: italic;">&lt;!-- Insertamos el contenido Flash --&gt;</span>
<span style="color: #090;">&lt;<span style="color: #000; font-weight: bold;">script</span> <span style="color: #006;">type</span><span style="color: #6c6;">=</span><span style="color: #f00;">&quot;text/javascript&quot;</span>&gt;</span><span style="color: #666; font-style: italic;">&lt;!--mce:2--&gt;</span><span style="color: #090;">&lt;<span style="color: #6c6;">/</span><span style="color: #000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #090;">&lt;<span style="color: #000; font-weight: bold;">div</span> <span style="color: #006;">id</span><span style="color: #6c6;">=</span><span style="color: #f00;">&quot;flashcontent&quot;</span> <span style="color: #006;">style</span><span style="color: #6c6;">=</span><span style="color: #f00;">&quot;margin: 0 auto&quot;</span>&gt;</span>
&nbsp;
<span style="color: #090;">&lt;<span style="color: #000; font-weight: bold;">strong</span>&gt;</span>Necesitas Flash Player. <span style="color: #090;">&lt;<span style="color: #6c6;">/</span><span style="color: #000; font-weight: bold;">strong</span>&gt;&lt;<span style="color: #6c6;">/</span><span style="color: #000; font-weight: bold;">div</span>&gt;</span></pre></td></tr></table></div>

<p>Y ya hemos terminado nuestro ejemplo. Para comprobar las posibilidades de SWFAddress, sigue el siguiente enlace:</p>
<p><a href="http://jlc-productions.net/jlc/apuntes/swfaddress/">Ver ejemplo terminado de SWFAddress en Flash</a></p>
<p>Ahora puedes comprobar que, cuando haces clic en las diferentes secciones, además de variar el contenido varía la URL y el título de la página. Esas distintas URL funcionan como una dirección de internet normal: por ejemplo, las puedes agregar a favoritos y acceder siempre que quieras a <em>esa parte de la web</em> que te interesa. Y por si fuera poco, se pueden emplear los botones atrás y adelante del navegador, algo a lo que los usuarios están muy acostumbrados y que agradecerán enormemente al visitar tu sitio.</p>
<p>Aquí tienes los archivos que he utilizado disponibles para descargar:</p>
<p><a class="download" href="http://jlc-productions.net/wp-content/uploads/2009/02/swfaddress.zip"><span>Descargar </span>swfaddress.zip<br />(66,63 KiB)</a></p>

<p>Te animo a que los utilices y a que, si te he ayudado, puntúes este apunte o <a href="#respond">escribas un comentario</a>. No olvides <a href="http://jlc-productions.net/suscribirse/">suscribirte a mi blog por correo</a> o <a href="http://jlc-productions.net/feed/">vía RSS</a> si quieres tener noticias sobre mi actividad <img src='http://jlc-productions.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>¡Muchas gracias!</p>


<p>Related posts:<ol><li><a href='http://jlc-productions.net/apuntes/as3/2009/03/precarga-en-flash-aparece-a-la-mitad/' rel='bookmark' title='Permanent Link: Precarga en Flash aparece a la mitad'>Precarga en Flash aparece a la mitad</a></li>
<li><a href='http://jlc-productions.net/apuntes/as3/2009/01/precarga-en-actionscript-3/' rel='bookmark' title='Permanent Link: Precarga en ActionScript 3'>Precarga en ActionScript 3</a></li>
<li><a href='http://jlc-productions.net/blog/2008/01/he-recuperado-los-fla/' rel='bookmark' title='Permanent Link: ¡¡He recuperado los fla!!'>¡¡He recuperado los fla!!</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://jlc-productions.net/apuntes/as3/2009/02/deep-linking-en-flash-con-swfaddress/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
