<?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; POO</title>
	<atom:link href="http://jlc-productions.net/tag/poo/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>Precarga en ActionScript 3</title>
		<link>http://jlc-productions.net/apuntes/as3/2009/01/precarga-en-actionscript-3/</link>
		<comments>http://jlc-productions.net/apuntes/as3/2009/01/precarga-en-actionscript-3/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 21:15:02 +0000</pubDate>
		<dc:creator>Juanlu001</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[POO]]></category>
		<category><![CDATA[precarga]]></category>

		<guid isPermaLink="false">http://jlc-productions.net/?p=595</guid>
		<description><![CDATA[En este apunte voy a tratar diversas maneras para precargar una película Flash en ActionScript 3, desde la más sencilla a una que podamos extender y reutilizar en todos nuestros proyectos. A día de hoy, si eres uno de mis lectores habituales seguramente no te interese lo más mínimo . Si has llegado aquí buscando [...]


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/02/deep-linking-en-flash-con-swfaddress/' rel='bookmark' title='Permanent Link: Deep linking en Flash con SWFAddress'>Deep linking en Flash con SWFAddress</a></li>
<li><a href='http://jlc-productions.net/portfolio/websites/2009/03/centro-medico-betasalud/' rel='bookmark' title='Permanent Link: Centro Médico Betasalud'>Centro Médico Betasalud</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>En este apunte voy a tratar diversas maneras para <strong>precargar una película Flash en ActionScript 3</strong>, desde la más sencilla a una que podamos extender y reutilizar en todos nuestros proyectos. A día de hoy, si eres uno de mis lectores habituales seguramente no te interese lo más mínimo <img src='http://jlc-productions.net/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  . Si has llegado aquí buscando lo que el título indica, ¡adelante! <span id="more-595"></span></p>
<p>Yo usaré para este apunte la versión CS4 de <a href="http://www.adobe.com/es/products/flash/">Adobe Flash</a>, pero puedes emplear también la versión CS3. Todos los documentos y archivos que creemos tendrán que tener como versión del lenguaje, obviamente, AS3. Para este apunte necesitaremos tres archivos .fla, todos ellos con la misma estructura. Los tres tendrán dos fotogramas clave: en el segundo colocaremos una imagen para poder simular la precarga más un comando <code>stop();</code> que detenga la película al final, y en el primero colocaremos las acciones que correspondan a cada uno de los tres casos. Puedes descargar ahora los archivos que he utilizado en el apunte:</p>
<p><a class="download" href="http://jlc-productions.net/wp-content/uploads/2009/01/precarga_as3.zip"><span>Descargar </span>precarga_as3.zip<br />(2,24 MiB)</a></p>

<p>Recuerda que para probar la película como si se estuviera descargando, tienes que pulsar Ctrl + Intro dos veces, o bien ir a <strong>Control -&gt; Probar película</strong> y después <strong>Ver -&gt; Simular descarga</strong>. En <strong>Ver -&gt; Configuración de descarga</strong> se puede ajustar la velocidad.</p>
<p>Primero vamos a hacer una pequeña introducción para comprender el sistema de carga de archivos de ActionScript 3.</p>
<h3>Introducción. Sistema de carga de archivos en AS3; objeto LoaderInfo</h3>
<p>Tal y como podemos leer en la <a href="http://help.adobe.com/es_ES/AS3LCR/Flash_10.0/flash/display/LoaderInfo.html">documentación de Adobe Flash sobre la clase LoaderInfo</a>, esta proporciona información sobre un archivo SWF cargado o un archivo de imagen cargado (JPEG, GIF o PNG), como por ejemplo los bytes cargados y por cargar o la URL del archivo, y distribuye una serie de eventos específicos relacionados con la carga y descarga de archivos. Atendamos ahora al diagrama extraído de la misma página:</p>
<p><a href="http://help.adobe.com/es_ES/AS3LCR/Flash_10.0/flash/display/LoaderInfo.html"><img class="aligncenter" title="Objetos LoaderInfo" src="http://help.adobe.com/es_ES/AS3LCR/Flash_10.0/images/loaderInfo_object.jpg" alt="" width="407" height="318" /></a></p>
<p>Si prescindimos de los objetos Loader, que no nos interesan para este apunte, observamos que podemos acceder a la información de la carga de la <em>instancia de la clase principal del archivo SWF</em> mediante su propiedad loaderInfo (que, mucha atención, no pertenece a Stage). En cuanto a los eventos de esta clase, nos interesan especialmente dos:</p>
<ul>
<li>El evento <a href="http://help.adobe.com/es_ES/AS3LCR/Flash_10.0/flash/display/LoaderInfo.html#event:progress">progress</a>, que se distribuirá durante la carga del archivo.</li>
<li>El evento <a href="http://help.adobe.com/es_ES/AS3LCR/Flash_10.0/flash/display/LoaderInfo.html#event:complete">complete</a>, que se distribuirá cuando la carga del archivo haya finalizado.</li>
</ul>
<p>Además, emplearemos las dos propiedades especiales del evento <a href="http://help.adobe.com/es_ES/AS3LCR/Flash_10.0/flash/events/ProgressEvent.html">ProgressEvent</a>: bytesLoaded y bytesTotal, que creo que no necesitan explicación.</p>
<p>Así pues, la sintaxis que seguiremos será la siguiente:</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: #069;">loaderInfo</span>.<span style="color: #069;">addEventListener</span><span style="color: #666; font-weight: bold;">&#40;</span>evento.TIPO, funcionPersonalizada<span style="color: #666; font-weight: bold;">&#41;</span>;
&nbsp;
<span style="color: #03c; font-weight: bold;">function</span> funcionPersonalizada<span style="color: #666; font-weight: bold;">&#40;</span>e<span style="color: #000; font-weight: bold;">:</span>evento<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;">// ...</span>
	<span style="color: #090; font-style: italic;">// e.bytesLoaded son los bytes cargados</span>
	<span style="color: #090; font-style: italic;">// e.bytesTotal son los bytes totales</span>
<span style="color: #666; font-weight: bold;">&#125;</span></pre></td></tr></table></div>

<p>Y dicho esto, vamos a empezar con nuestro primer ejemplo.</p>
<h3>1. Precarga básica en la línea de tiempo</h3>
<p>Esta es la manera más rápida y más directa de precargar una película: escribiendo unas pocas líneas de código en la línea de tiempo. Si lo que quieres es una aplicación puntual y no te interesa complicarte la vida, este es tu método. Comienza por crear un documento vacío y guárdalo con el nombre <code>precarga_timeline.fla</code>. Lleva al fotograma 2 alguna imagen que pese bastante (un tamaño cercano a 1 <a href="http://es.wikipedia.org/wiki/Prefijo_binario#Est.C3.A1ndar_IEEE">MiB</a> será suficiente, tampoco te pases), y acuérdate de poner un <code>stop();</code>. Ahora escribe en el fotograma 1, como hemos convenido, el siguiente código:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #090; font-style: italic;">// Importamos los paquetes necesarios</span>
<span style="color: #f00;">import</span> <span style="color: #03c;">flash.events</span>.<span style="color: #039;">ProgressEvent</span>;
<span style="color: #f00;">import</span> <span style="color: #03c;">flash.events</span>.<span style="color: #039;">Event</span>;
<span style="color: #f00;">import</span> <span style="color: #03c;">flash.text</span>.<span style="color: #039;">TextField</span>;
&nbsp;
<span style="color: #090; font-style: italic;">// Declaramos las variables</span>
<span style="color: #36c; font-weight: bold;">var</span> cargado<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">Number</span>;
<span style="color: #36c; font-weight: bold;">var</span> total<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">Number</span>;
<span style="color: #36c; font-weight: bold;">var</span> porcentaje<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">Number</span>;
&nbsp;
<span style="color: #090; font-style: italic;">// Detener la película al empezar</span>
<span style="color: #069;">stop</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #666; font-weight: bold;">&#41;</span>;
&nbsp;
<span style="color: #090; font-style: italic;">// Creamos un nuevo campo de texto</span>
<span style="color: #36c; font-weight: bold;">var</span> tf<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">TextField</span> = <span style="color: #f00;">new</span> <span style="color: #039;">TextField</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #666; font-weight: bold;">&#41;</span>;
tf.<span style="color: #069;">text</span> = <span style="color: #900;">&quot;0% Cargado&quot;</span>;
tf.<span style="color: #069;">x</span> = <span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #069;">stage</span>.<span style="color: #069;">stageWidth</span> <span style="color: #000; font-weight: bold;">/</span> <span style="color: #f00;">2</span><span style="color: #666; font-weight: bold;">&#41;</span> <span style="color: #000; font-weight: bold;">-</span> <span style="color: #666; font-weight: bold;">&#40;</span>tf.<span style="color: #069;">width</span> <span style="color: #000; font-weight: bold;">/</span> <span style="color: #f00;">2</span><span style="color: #666; font-weight: bold;">&#41;</span>; <span style="color: #090; font-style: italic;">// Centrado horizontal</span>
tf.<span style="color: #069;">y</span> = <span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #069;">stage</span>.<span style="color: #069;">stageHeight</span> <span style="color: #000; font-weight: bold;">/</span> <span style="color: #f00;">2</span><span style="color: #666; font-weight: bold;">&#41;</span> <span style="color: #000; font-weight: bold;">-</span> <span style="color: #666; font-weight: bold;">&#40;</span>tf.<span style="color: #069;">height</span> <span style="color: #000; font-weight: bold;">/</span> <span style="color: #f00;">2</span><span style="color: #666; font-weight: bold;">&#41;</span>; <span style="color: #090; font-style: italic;">// Centrado vertical</span>
<span style="color: #069;">addChild</span><span style="color: #666; font-weight: bold;">&#40;</span>tf<span style="color: #666; font-weight: bold;">&#41;</span>; <span style="color: #090; font-style: italic;">// Y lo añadimos al escenario</span>
&nbsp;
<span style="color: #090; font-style: italic;">// Función para el comportamiento durante la carga</span>
<span style="color: #03c; font-weight: bold;">function</span> onLoadProgress<span style="color: #666; font-weight: bold;">&#40;</span>e<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">ProgressEvent</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>
	cargado = e.<span style="color: #069;">bytesLoaded</span>;
	total = e.<span style="color: #069;">bytesTotal</span>;
	porcentaje = <span style="color: #039;">Math</span>.<span style="color: #069;">round</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #666; font-weight: bold;">&#40;</span>cargado <span style="color: #000; font-weight: bold;">/</span> total<span style="color: #666; font-weight: bold;">&#41;</span> <span style="color: #000; font-weight: bold;">*</span> <span style="color: #f00;">100</span><span style="color: #666; font-weight: bold;">&#41;</span>;
	tf.<span style="color: #069;">text</span> = porcentaje <span style="color: #000; font-weight: bold;">+</span> <span style="color: #900;">&quot;% Cargado&quot;</span>;
<span style="color: #666; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #090; font-style: italic;">// Función para el comportamiento al finalizar la carga</span>
<span style="color: #03c; font-weight: bold;">function</span> onLoadComplete<span style="color: #666; font-weight: bold;">&#40;</span>e<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">Event</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;">// Eliminamos los listener</span>
	<span style="color: #069;">loaderInfo</span>.<span style="color: #069;">removeEventListener</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #039;">ProgressEvent</span>.<span style="color: #039;">PROGRESS</span>, onLoadProgress<span style="color: #666; font-weight: bold;">&#41;</span>;
	<span style="color: #069;">loaderInfo</span>.<span style="color: #069;">removeEventListener</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #039;">Event</span>.<span style="color: #039;">COMPLETE</span>, onLoadComplete<span style="color: #666; font-weight: bold;">&#41;</span>;
&nbsp;
	<span style="color: #090; font-style: italic;">// Eliminamos el campo de texto</span>
	<span style="color: #069;">removeChild</span><span style="color: #666; font-weight: bold;">&#40;</span>tf<span style="color: #666; font-weight: bold;">&#41;</span>;
&nbsp;
	<span style="color: #090; font-style: italic;">// Que dé comienzo la película</span>
	<span style="color: #069;">play</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #666; font-weight: bold;">&#41;</span>;
<span style="color: #666; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #090; font-style: italic;">// Se agregan los listener para las funciones</span>
<span style="color: #069;">loaderInfo</span>.<span style="color: #069;">addEventListener</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #039;">ProgressEvent</span>.<span style="color: #039;">PROGRESS</span>, onLoadProgress<span style="color: #666; font-weight: bold;">&#41;</span>;
<span style="color: #069;">loaderInfo</span>.<span style="color: #069;">addEventListener</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #039;">Event</span>.<span style="color: #039;">COMPLETE</span>, onLoadComplete<span style="color: #666; font-weight: bold;">&#41;</span>;</pre></td></tr></table></div>

<p>Los comentarios hablan por sí solos: estas líneas detendrán la película y mostrarán un cuadro de texto en el centro del escenario con el porcentaje cargado hasta el momento de la película. Fácil, ¿no?</p>
<p><a href="http://jlc-productions.net/wp-content/uploads/2009/01/precarga_timeline.swf">Ver ejemplo de <em>Precarga básica en la línea de tiempo</em></a></p>
<p>Como dije, esto es un ejemplo muy sencillo que te sacará de apuros cuando estés a punto de perder el avión y necesites añadir una precarga <em>rápidamente</em>, pero personalmente no me gusta nada porque me condena al <em>copy &amp; paste</em> para siempre. De modo que vamos a ver otra manera:</p>
<h3>2. Precarga básica con la <em>clase de documento</em></h3>
<p>Ahora, como buenos programadores en ActionScript 3, vamos a usar una <strong>clase</strong> para nuestro propósito, y la vamos a asignar a nuestro documento para que haga de clase para la <em>instancia del archivo SWF principal</em>. Crea otro documento con el nombre de <code>precarga_dclass.fla</code> (con la misma imagen en el segundo fotograma y su sentencia <code>stop();</code>) y un nuevo <em>archivo ActionScript</em> con el nombre de <code>PrecargaBasica.as</code> y colócalos en el mismo directorio. Al ser una clase de documento, ha de extender de la clase MovieClip de Flash:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="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: #090; font-style: italic;">// Importamos los paquetes necesarios</span>
	<span style="color: #f00;">import</span> <span style="color: #03c;">flash.display</span>.<span style="color: #039;">MovieClip</span>;
&nbsp;
	<span style="color: #090; font-style: italic;">// Declaramos la clase</span>
	<span style="color: #f00;">public</span> <span style="color: #f00; font-weight: bold;">class</span> PrecargaBasica <span style="color: #f00;">extends</span> <span style="color: #039;">MovieClip</span>
	<span style="color: #666; font-weight: bold;">&#123;</span>
		<span style="color: #03c; font-weight: bold;">function</span> PrecargaBasica<span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #666; font-weight: bold;">&#41;</span>
		<span style="color: #666; font-weight: bold;">&#123;</span>
			<span style="color: #090; font-style: italic;">// Función constructora; se ejecutará al iniciarse la película</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, básicamente tendremos que añadir el código que hemos escrito para el primer ejemplo, con algunas modificaciones. Así queda la clase al final:</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
</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: #090; font-style: italic;">// Importamos los paquetes necesarios</span>
	<span style="color: #f00;">import</span> <span style="color: #03c;">flash.display</span>.<span style="color: #039;">MovieClip</span>;
	<span style="color: #f00;">import</span> <span style="color: #03c;">flash.events</span>.<span style="color: #039;">ProgressEvent</span>;
	<span style="color: #f00;">import</span> <span style="color: #03c;">flash.events</span>.<span style="color: #039;">Event</span>;
	<span style="color: #f00;">import</span> <span style="color: #03c;">flash.text</span>.<span style="color: #039;">TextField</span>;
&nbsp;
	<span style="color: #090; font-style: italic;">// Declaramos la clase</span>
	<span style="color: #f00;">public</span> <span style="color: #f00; font-weight: bold;">class</span> PrecargaBasica <span style="color: #f00;">extends</span> <span style="color: #039;">MovieClip</span>
	<span style="color: #666; font-weight: bold;">&#123;</span>
		<span style="color: #090; font-style: italic;">// Declaramos las variables</span>
		<span style="color: #f00;">private</span> <span style="color: #36c; font-weight: bold;">var</span> cargado<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">Number</span>;
		<span style="color: #f00;">private</span> <span style="color: #36c; font-weight: bold;">var</span> total<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">Number</span>;
		<span style="color: #f00;">private</span> <span style="color: #36c; font-weight: bold;">var</span> porcentaje<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">int</span>;
&nbsp;
		<span style="color: #f00;">private</span> <span style="color: #36c; font-weight: bold;">var</span> tf<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">TextField</span>;
&nbsp;
		<span style="color: #03c; font-weight: bold;">function</span> PrecargaBasica<span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #666; font-weight: bold;">&#41;</span>
		<span style="color: #666; font-weight: bold;">&#123;</span>
			<span style="color: #090; font-style: italic;">// Detener la película al empezar</span>
			<span style="color: #069;">stop</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #666; font-weight: bold;">&#41;</span>;
&nbsp;
			<span style="color: #090; font-style: italic;">// Creamos un nuevo campo de texto</span>
			tf = <span style="color: #f00;">new</span> <span style="color: #039;">TextField</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #666; font-weight: bold;">&#41;</span>;
			tf.<span style="color: #069;">text</span> = <span style="color: #900;">&quot;0% Cargado&quot;</span>;
			tf.<span style="color: #069;">x</span> = <span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #069;">stage</span>.<span style="color: #069;">stageWidth</span> <span style="color: #000; font-weight: bold;">/</span> <span style="color: #f00;">2</span><span style="color: #666; font-weight: bold;">&#41;</span> <span style="color: #000; font-weight: bold;">-</span> <span style="color: #666; font-weight: bold;">&#40;</span>tf.<span style="color: #069;">width</span> <span style="color: #000; font-weight: bold;">/</span> <span style="color: #f00;">2</span><span style="color: #666; font-weight: bold;">&#41;</span>; <span style="color: #090; font-style: italic;">// Centrado horizontal</span>
			tf.<span style="color: #069;">y</span> = <span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #069;">stage</span>.<span style="color: #069;">stageHeight</span> <span style="color: #000; font-weight: bold;">/</span> <span style="color: #f00;">2</span><span style="color: #666; font-weight: bold;">&#41;</span> <span style="color: #000; font-weight: bold;">-</span> <span style="color: #666; font-weight: bold;">&#40;</span>tf.<span style="color: #069;">height</span> <span style="color: #000; font-weight: bold;">/</span> <span style="color: #f00;">2</span><span style="color: #666; font-weight: bold;">&#41;</span>; <span style="color: #090; font-style: italic;">// Centrado vertical</span>
			<span style="color: #069;">addChild</span><span style="color: #666; font-weight: bold;">&#40;</span>tf<span style="color: #666; font-weight: bold;">&#41;</span>; <span style="color: #090; font-style: italic;">// Y lo añadimos al escenario</span>
&nbsp;
			<span style="color: #090; font-style: italic;">// Se agregan los listener para las funciones</span>
			<span style="color: #069;">loaderInfo</span>.<span style="color: #069;">addEventListener</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #039;">ProgressEvent</span>.<span style="color: #039;">PROGRESS</span>, onLoadProgress<span style="color: #666; font-weight: bold;">&#41;</span>;
			<span style="color: #069;">loaderInfo</span>.<span style="color: #069;">addEventListener</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #039;">Event</span>.<span style="color: #039;">COMPLETE</span>, onLoadComplete<span style="color: #666; font-weight: bold;">&#41;</span>;
		<span style="color: #666; font-weight: bold;">&#125;</span>
&nbsp;
		<span style="color: #090; font-style: italic;">// Función para el comportamiento durante la carga</span>
		<span style="color: #f00;">private</span> <span style="color: #03c; font-weight: bold;">function</span> onLoadProgress<span style="color: #666; font-weight: bold;">&#40;</span>e<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">ProgressEvent</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>
			cargado = e.<span style="color: #069;">bytesLoaded</span>;
			total = e.<span style="color: #069;">bytesTotal</span>;
			porcentaje = <span style="color: #666; font-weight: bold;">&#40;</span>cargado <span style="color: #000; font-weight: bold;">/</span> total<span style="color: #666; font-weight: bold;">&#41;</span> <span style="color: #000; font-weight: bold;">*</span> <span style="color: #f00;">100</span>;
			tf.<span style="color: #069;">text</span> = porcentaje <span style="color: #000; font-weight: bold;">+</span> <span style="color: #900;">&quot;% Cargado&quot;</span>;
		<span style="color: #666; font-weight: bold;">&#125;</span>
&nbsp;
		<span style="color: #090; font-style: italic;">// Función para el comportamiento al finalizar la carga</span>
		<span style="color: #f00;">private</span> <span style="color: #03c; font-weight: bold;">function</span> onLoadComplete<span style="color: #666; font-weight: bold;">&#40;</span>e<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">Event</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;">// Eliminamos los listener</span>
			<span style="color: #069;">loaderInfo</span>.<span style="color: #069;">removeEventListener</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #039;">ProgressEvent</span>.<span style="color: #039;">PROGRESS</span>, onLoadProgress<span style="color: #666; font-weight: bold;">&#41;</span>;
			<span style="color: #069;">loaderInfo</span>.<span style="color: #069;">removeEventListener</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #039;">Event</span>.<span style="color: #039;">COMPLETE</span>, onLoadComplete<span style="color: #666; font-weight: bold;">&#41;</span>;
&nbsp;
			<span style="color: #090; font-style: italic;">// Eliminamos el campo de texto</span>
			<span style="color: #069;">removeChild</span><span style="color: #666; font-weight: bold;">&#40;</span>tf<span style="color: #666; font-weight: bold;">&#41;</span>;
&nbsp;
			<span style="color: #090; font-style: italic;">// Que dé comienzo la película</span>
			<span style="color: #069;">play</span><span style="color: #666; font-weight: bold;">&#40;</span><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>Y esto es todo; tiene la misma funcionalidad que el primer ejemplo. Como veis, esto nos da más posibilidades: simplemente tengo que tener la clase accesible para poder reutilizarla en mis proyectos, asignándoles a cada uno esta clase de documento.</p>
<p><a href="http://jlc-productions.net/wp-content/uploads/2009/01/precarga_dclass.swf">Ver ejemplo de <em>Precarga básica con la clase de documento</em></a></p>
<p>No obstante, y aunque esto contentará a la mayoría, yo <em>todavía</em> tengo algunas pegas:</p>
<ul>
<li>¿Qué pasa si no me interesa que salga un cuadro de texto, sino, por ejemplo, una barra? Tendré que reescribir la clase cada vez que la quiera usar. Yo no llamaría a eso &#8220;reutilizar&#8221;.</li>
<li>¿Qué pasa si yo <em>ya quería usar una clase de documento</em>? Tendré que meter el comportamiento de mi película dentro de la clase PrecargaBasica. Un poco raro, ¿no?</li>
</ul>
<p>Por estas razones, y esta es mi aportación personal para aquellos a quienes les surjan las mismas dudas, vamos a definir un tercer método con el que hacer una clase de precarga <em>reutilizable de verdad</em> (¿acaso no se inventaron las clases para eso?), aprovechando los métodos de herencia de la <a href="http://es.wikipedia.org/wiki/Programación_orientada_a_objetos">programación orientada a objetos</a>.</p>
<h3>3. Precarga personalizada con una clase extensible</h3>
<p>Vamos a repasar los objetivos que queremos lograr a la hora de desarrollar nuestra clase:</p>
<ol>
<li>Independencia de la clase de documento</li>
<li>Mínima cantidad de código para activar la precarga</li>
<li>Clase ampliable</li>
</ol>
<p>Crea otro documento con la misma estructura que los anteriores y llámalo <code>precarga_custom.fla</code>. Copia ahora la clase que hemos desarrollado en el ejemplo 2 en una carpeta llamada <code>precarga</code>, dentro de otra llamada <code>clases</code>, y cámbiale el nombre a <code>PrecargaSuper.fla</code>. Las primeras líneas tienen que quedar 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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #f00; font-weight: bold;">package</span> clases.precarga
<span style="color: #666; font-weight: bold;">&#123;</span>
	<span style="color: #090; font-style: italic;">// Importamos los paquetes necesarios</span>
	<span style="color: #f00;">import</span> <span style="color: #03c;">flash.display</span>.<span style="color: #039;">MovieClip</span>;
	<span style="color: #f00;">import</span> <span style="color: #03c;">flash.events</span>.<span style="color: #039;">ProgressEvent</span>;
	<span style="color: #f00;">import</span> <span style="color: #03c;">flash.events</span>.<span style="color: #039;">Event</span>;
	<span style="color: #f00;">import</span> <span style="color: #03c;">flash.text</span>.<span style="color: #039;">TextField</span>;
&nbsp;
	<span style="color: #090; font-style: italic;">// Declaramos la clase</span>
	<span style="color: #f00;">public</span> <span style="color: #f00; font-weight: bold;">class</span> PrecargaSuper <span style="color: #f00;">extends</span> <span style="color: #039;">MovieClip</span>
	<span style="color: #666; font-weight: bold;">&#123;</span></pre></td></tr></table></div>

<p>No obstante, si ahora mismo creamos una instancia de PrecargaSuper, bien desde la línea de tiempo o desde la nueva clase de documento, para imitar el comportamiento que hemos diseñado en los dos ejemplos anteriores:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #f00;">import</span> clases.precarga.PrecargaSuper;
&nbsp;
<span style="color: #36c; font-weight: bold;">var</span> precarga<span style="color: #000; font-weight: bold;">:</span>PrecargaSuper = <span style="color: #f00;">new</span> PrecargaSuper<span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #666; font-weight: bold;">&#41;</span>;</pre></td></tr></table></div>

<p>Vemos que no ocurre nada especial; la película se detiene, sí, pero no aparece ningún cuadro de texto. Esto es así porque todas las propiedades y métodos estaban referidos a <code>this</code> (que se omitía) al ser la clase del documento, pero esto ya no sirve si no es así. De modo que tenemos dos opciones: o añadir la instancia de PrecargaSuper al escenario, o pasarle <em>el escenario</em> como parámetro al constructor. Creo que habéis adivinado que esta última me gusta mucho:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #f00;">import</span> clases.precarga.PrecargaSuper;
&nbsp;
<span style="color: #36c; font-weight: bold;">var</span> precarga<span style="color: #000; font-weight: bold;">:</span>PrecargaSuper = <span style="color: #f00;">new</span> PrecargaSuper<span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #f00;">this</span><span style="color: #666; font-weight: bold;">&#41;</span>;</pre></td></tr></table></div>

<p>Y ahora haremos algunas modificaciones a la clase. En primer lugar, ya no hace falta que extienda de MovieClip, ya que no la vamos a añadir al escenario; en segundo, habrá que especificar un parámetro del tipo DisplayObjectContainer en la función constructora; y en tercero, habrá que referir todas las propiedades y métodos a la propiedad <em>root</em> de ese parámetro. Además, para cumplir el tercero de nuestros objetivos (hacer que la clase sea ampliable), vamos a hacer un par de modificaciones más en PrecargaSuper: vamos a quitar todo el comportamiento complementario y vamos a hacerla extensible, cambiando los <code>private</code> por <code>protected</code>. Después de lo dicho este debería ser el aspecto de la clase:</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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #f00; font-weight: bold;">package</span> clases.precarga
<span style="color: #666; font-weight: bold;">&#123;</span>
	<span style="color: #090; font-style: italic;">// Importamos los paquetes necesarios</span>
	<span style="color: #f00;">import</span> <span style="color: #03c;">flash.display</span>.<span style="color: #039;">MovieClip</span>;
	<span style="color: #f00;">import</span> <span style="color: #03c;">flash.events</span>.<span style="color: #039;">ProgressEvent</span>;
	<span style="color: #f00;">import</span> <span style="color: #03c;">flash.events</span>.<span style="color: #039;">Event</span>;
&nbsp;
	<span style="color: #090; font-style: italic;">// Declaramos la clase</span>
	<span style="color: #f00;">public</span> <span style="color: #f00; font-weight: bold;">class</span> PrecargaSuper
	<span style="color: #666; font-weight: bold;">&#123;</span>
		<span style="color: #090; font-style: italic;">// Declaramos las variables</span>
		<span style="color: #f00;">protected</span> <span style="color: #36c; font-weight: bold;">var</span> <span style="color: #069;">target</span><span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">MovieClip</span>;
&nbsp;
		<span style="color: #f00;">protected</span> <span style="color: #36c; font-weight: bold;">var</span> cargado<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">Number</span>;
		<span style="color: #f00;">protected</span> <span style="color: #36c; font-weight: bold;">var</span> total<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">Number</span>;
		<span style="color: #f00;">protected</span> <span style="color: #36c; font-weight: bold;">var</span> porcentaje<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">int</span>;
&nbsp;
		<span style="color: #03c; font-weight: bold;">function</span> PrecargaSuper<span style="color: #666; font-weight: bold;">&#40;</span>_target<span style="color: #000; font-weight: bold;">:*</span><span style="color: #666; font-weight: bold;">&#41;</span>
		<span style="color: #666; font-weight: bold;">&#123;</span>
			<span style="color: #090; font-style: italic;">// Se asigna a la propiedad target de la instancia la referida en la</span>
			<span style="color: #090; font-style: italic;">// función constructora</span>
			<span style="color: #069;">target</span> = _target.<span style="color: #069;">root</span>;
&nbsp;
			<span style="color: #090; font-style: italic;">// Detener la película al empezar</span>
			<span style="color: #069;">target</span>.<span style="color: #069;">stop</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #666; font-weight: bold;">&#41;</span>;
&nbsp;
			<span style="color: #090; font-style: italic;">// Se agregan los listener para las funciones</span>
			<span style="color: #069;">target</span>.<span style="color: #069;">loaderInfo</span>.<span style="color: #069;">addEventListener</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #039;">ProgressEvent</span>.<span style="color: #039;">PROGRESS</span>, onLoadProgress<span style="color: #666; font-weight: bold;">&#41;</span>;
			<span style="color: #069;">target</span>.<span style="color: #069;">loaderInfo</span>.<span style="color: #069;">addEventListener</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #039;">Event</span>.<span style="color: #039;">COMPLETE</span>, onLoadComplete<span style="color: #666; font-weight: bold;">&#41;</span>;
		<span style="color: #666; font-weight: bold;">&#125;</span>
&nbsp;
		<span style="color: #090; font-style: italic;">// Función para el comportamiento durante la carga</span>
		<span style="color: #f00;">protected</span> <span style="color: #03c; font-weight: bold;">function</span> onLoadProgress<span style="color: #666; font-weight: bold;">&#40;</span>e<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">ProgressEvent</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>
			cargado = e.<span style="color: #069;">bytesLoaded</span>;
			total = e.<span style="color: #069;">bytesTotal</span>;
			porcentaje = <span style="color: #666; font-weight: bold;">&#40;</span>cargado <span style="color: #000; font-weight: bold;">/</span> total<span style="color: #666; font-weight: bold;">&#41;</span> <span style="color: #000; font-weight: bold;">*</span> <span style="color: #f00;">100</span>;
		<span style="color: #666; font-weight: bold;">&#125;</span>
&nbsp;
		<span style="color: #090; font-style: italic;">// Función para el comportamiento al finalizar la carga</span>
		<span style="color: #f00;">protected</span> <span style="color: #03c; font-weight: bold;">function</span> onLoadComplete<span style="color: #666; font-weight: bold;">&#40;</span>e<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">Event</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;">// Eliminamos los listener</span>
			<span style="color: #069;">target</span>.<span style="color: #069;">loaderInfo</span>.<span style="color: #069;">removeEventListener</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #039;">ProgressEvent</span>.<span style="color: #039;">PROGRESS</span>, onLoadProgress<span style="color: #666; font-weight: bold;">&#41;</span>;
			<span style="color: #069;">target</span>.<span style="color: #069;">loaderInfo</span>.<span style="color: #069;">removeEventListener</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #039;">Event</span>.<span style="color: #039;">COMPLETE</span>, onLoadComplete<span style="color: #666; font-weight: bold;">&#41;</span>;
&nbsp;
			<span style="color: #090; font-style: italic;">// Que dé comienzo la película</span>
			<span style="color: #069;">target</span>.<span style="color: #069;">play</span><span style="color: #666; font-weight: bold;">&#40;</span><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 la clase PrecargaSuper se limita a parar la película al principio, asignar valores a las variables <code>cargado</code>, <code>total</code> y <code>porcentaje</code> y reanudar la reproducción cuando finaliza la carga. Y ahora es cuando viene lo interesante: vamos a hacer una clase llamada <code>Precarga</code> que extienda de PrecargaSuper y que añada el ya famoso cuadro de texto, empleando la palabra clave <code>override</code> para sustituir los métodos de la clase padre y <code>super</code> para invocarlos:</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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #f00; font-weight: bold;">package</span> clases.precarga
<span style="color: #666; font-weight: bold;">&#123;</span>
	<span style="color: #090; font-style: italic;">// Importamos los paquetes necesarios</span>
	<span style="color: #f00;">import</span> <span style="color: #03c;">flash.display</span>.<span style="color: #039;">MovieClip</span>;
	<span style="color: #f00;">import</span> <span style="color: #03c;">flash.events</span>.<span style="color: #039;">ProgressEvent</span>;
	<span style="color: #f00;">import</span> <span style="color: #03c;">flash.events</span>.<span style="color: #039;">Event</span>;
	<span style="color: #f00;">import</span> <span style="color: #03c;">flash.text</span>.<span style="color: #039;">TextField</span>;
&nbsp;
	<span style="color: #090; font-style: italic;">// Declaramos la clase</span>
	<span style="color: #f00;">public</span> <span style="color: #f00;">final</span> <span style="color: #f00; font-weight: bold;">class</span> Precarga <span style="color: #f00;">extends</span> PrecargaSuper
	<span style="color: #666; font-weight: bold;">&#123;</span>
		<span style="color: #090; font-style: italic;">// Declaramos las variables</span>
		<span style="color: #36c; font-weight: bold;">var</span> tf<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">TextField</span>;
&nbsp;
		<span style="color: #03c; font-weight: bold;">function</span> Precarga<span style="color: #666; font-weight: bold;">&#40;</span>_target<span style="color: #000; font-weight: bold;">:*</span><span style="color: #666; font-weight: bold;">&#41;</span>
		<span style="color: #666; font-weight: bold;">&#123;</span>
			<span style="color: #f00;">super</span><span style="color: #666; font-weight: bold;">&#40;</span>_target<span style="color: #666; font-weight: bold;">&#41;</span>;
&nbsp;
			<span style="color: #090; font-style: italic;">// Creamos un nuevo campo de texto</span>
			tf = <span style="color: #f00;">new</span> <span style="color: #039;">TextField</span><span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #666; font-weight: bold;">&#41;</span>;
			tf.<span style="color: #069;">text</span> = <span style="color: #900;">&quot;0% Cargado&quot;</span>;
			tf.<span style="color: #069;">x</span> = <span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #069;">target</span>.<span style="color: #069;">stage</span>.<span style="color: #069;">stageWidth</span> <span style="color: #000; font-weight: bold;">/</span> <span style="color: #f00;">2</span><span style="color: #666; font-weight: bold;">&#41;</span> <span style="color: #000; font-weight: bold;">-</span> <span style="color: #666; font-weight: bold;">&#40;</span>tf.<span style="color: #069;">width</span> <span style="color: #000; font-weight: bold;">/</span> <span style="color: #f00;">2</span><span style="color: #666; font-weight: bold;">&#41;</span>; <span style="color: #090; font-style: italic;">// Centrado horizontal</span>
			tf.<span style="color: #069;">y</span> = <span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #069;">target</span>.<span style="color: #069;">stage</span>.<span style="color: #069;">stageHeight</span> <span style="color: #000; font-weight: bold;">/</span> <span style="color: #f00;">2</span><span style="color: #666; font-weight: bold;">&#41;</span> <span style="color: #000; font-weight: bold;">-</span> <span style="color: #666; font-weight: bold;">&#40;</span>tf.<span style="color: #069;">height</span> <span style="color: #000; font-weight: bold;">/</span> <span style="color: #f00;">2</span><span style="color: #666; font-weight: bold;">&#41;</span>; <span style="color: #090; font-style: italic;">// Centrado vertical</span>
			<span style="color: #069;">target</span>.<span style="color: #069;">addChild</span><span style="color: #666; font-weight: bold;">&#40;</span>tf<span style="color: #666; font-weight: bold;">&#41;</span>; <span style="color: #090; font-style: italic;">// Y lo añadimos al escenario</span>
		<span style="color: #666; font-weight: bold;">&#125;</span>
&nbsp;
		<span style="color: #090; font-style: italic;">// Función para el comportamiento durante la carga</span>
		<span style="color: #f00;">override</span> <span style="color: #f00;">protected</span> <span style="color: #03c; font-weight: bold;">function</span> onLoadProgress<span style="color: #666; font-weight: bold;">&#40;</span>e<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">ProgressEvent</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: #f00;">super</span>.onLoadProgress<span style="color: #666; font-weight: bold;">&#40;</span>e<span style="color: #666; font-weight: bold;">&#41;</span>;
&nbsp;
			tf.<span style="color: #069;">text</span> = porcentaje <span style="color: #000; font-weight: bold;">+</span> <span style="color: #900;">&quot;% Cargado&quot;</span>;
		<span style="color: #666; font-weight: bold;">&#125;</span>
&nbsp;
		<span style="color: #090; font-style: italic;">// Función para el comportamiento al finalizar la carga</span>
		<span style="color: #f00;">override</span> <span style="color: #f00;">protected</span> <span style="color: #03c; font-weight: bold;">function</span> onLoadComplete<span style="color: #666; font-weight: bold;">&#40;</span>e<span style="color: #000; font-weight: bold;">:</span><span style="color: #039;">Event</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;">// Eliminamos el campo de texto</span>
			<span style="color: #069;">target</span>.<span style="color: #069;">removeChild</span><span style="color: #666; font-weight: bold;">&#40;</span>tf<span style="color: #666; font-weight: bold;">&#41;</span>;
&nbsp;
			<span style="color: #f00;">super</span>.onLoadComplete<span style="color: #666; font-weight: bold;">&#40;</span>e<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>Y después de cambiar tres palabras en nuestra película:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #f00;">import</span> clases.precarga.<span style="color: #000; font-weight: bold;">*</span>;
&nbsp;
<span style="color: #36c; font-weight: bold;">var</span> precarga<span style="color: #000; font-weight: bold;">:</span>Precarga = <span style="color: #f00;">new</span> Precarga<span style="color: #666; font-weight: bold;">&#40;</span><span style="color: #f00;">this</span><span style="color: #666; font-weight: bold;">&#41;</span>;</pre></td></tr></table></div>

<p>&#8230;ya hemos llegado al final de nuestro ejemplo: tenemos una clase, <code>PrecargaSuper</code>, con el comportamiento básico de la carga y que <em>realmente</em> podremos <strong>extender en cada uno de nuestros proyectos</strong>; y una clase <code>Precarga</code>, que <strong>implementa ese comportamiento básico</strong> y además <strong>añade funciones nuevas</strong>: en este caso mostrar un cuadro de texto, pero puede ser una barra, el típico círculo&#8230; Depende de tu creatividad <img src='http://jlc-productions.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  , tan sólo tienes que seguir el modelo que hemos escrito usando <code>super.funcionPadre(parámetros);</code> en cada uno de los métodos.</p>
<p><a href="http://jlc-productions.net/wp-content/uploads/2009/01/precarga_custom.swf">Ver ejemplo de <em>Precarga personalizada con una clase extensible</em></a></p>
<p>Y hasta aquí hemos llegado con nuestros ejemplos de <strong>cómo hacer una precarga con ActionScript 3</strong>. Espero que te sean muy útiles; siéntete libre de descargar ahora los archivos que yo he utilizado y de adaptarlos a tu gusto y no dudes en poner tus <a href="#respond">comentarios y sugerencias</a>.</p>
<p><a class="download" href="http://jlc-productions.net/wp-content/uploads/2009/01/precarga_as3.zip"><span>Descargar </span>precarga_as3.zip<br />(2,24 MiB)</a></p>

<p>Así mismo, no olvides <a href="http://jlc-productions.net/suscribirse/">suscribirte a mi blog por correo</a> o a mi <a href="http://jlc-productions.net/feed/">feed RSS</a> si quieres estar al día sobre las novedades en <a href="http://jlc-productions.net/">JLC Productions</a>. ¡Muchísimas gracias!</p>
<p><em><ins datetime="2009-01-17T14:30:49+00:00"><strong>Actualización</strong></ins>: Archivos .fla actualizados para poder ser abiertos con Flash CS3</em><br />
<em><ins datetime="2009-01-21T19:26:36+00:00"><strong>Actualización 2</strong></ins>: Error corregido que impedía usar una clase de documento con PrecargaSuper (<a href="http://jlc-productions.net/apuntes/2009/01/precarga-en-actionscript-3/#comment-116">gracias a AndyX®</a>)</em><br />
<em><ins datetime="2009-03-24T22:55:20+00:00"><strong>Actualización 3</strong></ins>: En este apunte se trata el problema de la <a href="http://jlc-productions.net/apuntes/2009/03/precarga-en-flash-aparece-a-la-mitad/">precarga que empieza a medias</a></em><br />
<em><ins datetime="2009-08-04T12:04:03+00:00"><strong>Actualización 4</strong></ins>: Corregido error en el ejemplo básico <a href="http://jlc-productions.net/apuntes/2009/01/precarga-en-actionscript-3/#comment-526">gracias a Pedro Antonio</a></em></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/02/deep-linking-en-flash-con-swfaddress/' rel='bookmark' title='Permanent Link: Deep linking en Flash con SWFAddress'>Deep linking en Flash con SWFAddress</a></li>
<li><a href='http://jlc-productions.net/portfolio/websites/2009/03/centro-medico-betasalud/' rel='bookmark' title='Permanent Link: Centro Médico Betasalud'>Centro Médico Betasalud</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://jlc-productions.net/apuntes/as3/2009/01/precarga-en-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>
