<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet title="XSL formatting" type="text/xsl" href="http://www.ekameleon.net/blog/index.php?feed/rss2/xslt" ?><rss version="2.0"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:wfw="http://wellformedweb.org/CommentAPI/"
  xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
  <title>EKAMELEON - DevBlog ActionScript &amp; ECMAScript</title>
  <link>http://www.ekameleon.net/blog/index.php?</link>
  <description>DevBlog Flex - AIR - ActionScript3 - Flash Media Interactive Server - ECMAScript</description>
  <language>fr</language>
  <pubDate>Fri, 25 Jun 2010 10:05:53 +0200</pubDate>
  <copyright></copyright>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Dotclear</generator>
  
    
  <item>
    <title>Signals and Receivers</title>
    <link>http://www.ekameleon.net/blog/index.php?post/2010/02/10/Signals-and-Receivers</link>
    <guid isPermaLink="false">urn:md5:62130a38035550622f584935359dd5f5</guid>
    <pubDate>Mon, 01 Mar 2010 19:30:00 +0100</pubDate>
    <dc:creator>eKameleon</dc:creator>
        <category>VEGAS</category>
        <category>as3</category><category>events</category><category>framework</category><category>opensource</category><category>receivers</category><category>signals</category><category>vegas</category>    
    <description>&lt;h2&gt;Generality&lt;/h2&gt;


&lt;p&gt;The &quot;&lt;strong&gt;signal engine&lt;/strong&gt;&quot; include in the package &lt;strong&gt;system.signals&lt;/strong&gt; is a very easy &lt;strong&gt;ActionScript 3&lt;/strong&gt; messaging tools.&lt;/p&gt;


&lt;p&gt;With the &lt;strong&gt;Signaler&lt;/strong&gt; interface we can define objects who communicates by signals and can be use to create a light-weight implementation of the &lt;strong&gt;Observer&lt;/strong&gt; pattern. A signal emit simple values with its own array of receivers (&lt;em&gt;slots&lt;/em&gt;). This values can be &lt;strong&gt;strongly-typed&lt;/strong&gt; with an optional internal checking process.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Receivers&lt;/strong&gt; can be defines with a &lt;strong&gt;simple function reference&lt;/strong&gt; or a custom objects who implements the interface &lt;strong&gt;system.signals.Receiver&lt;/strong&gt; .&lt;/p&gt;


&lt;p&gt;Receivers subscribe to real objects, not to string-based channels and&lt;strong&gt;Event&lt;/strong&gt; string constants are no longer needed like &lt;a href=&quot;http://www.w3.org/TR/DOM-Level-2-Events/events.html&quot;&gt;W3C DOM 2/3 event model&lt;/a&gt;.&lt;/p&gt;


&lt;h2&gt;Interfaces&lt;/h2&gt;


&lt;p&gt;The &lt;strong&gt;system.signals&lt;/strong&gt; package contains two interfaces : &lt;strong&gt;Signaler and Receiver&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;The &lt;strong&gt;Signaler&lt;/strong&gt; interface is simple but contains all important methods to deploy your signals.&lt;/p&gt;    &lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt; system.signals
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; interface Signaler
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #3f5fbf;&quot;&gt;/**
         * Indicates the number of receivers connected.
         */&lt;/span&gt;
        &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;get&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;uint&lt;/span&gt; ;
&amp;nbsp;
        &lt;span style=&quot;color: #3f5fbf;&quot;&gt;/**
         * Connects a Function reference or a Receiver object.
         * @param receiver The receiver to connect : a Function reference or a Receiver object.
         * @param priority Determinates the priority level of the receiver.
         * @param autoDisconnect Apply a disconnect after the first trigger
         * @return true If the receiver is connected with the signal emitter.
         */&lt;/span&gt;
        &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;connect&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; receiver&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:*&lt;/span&gt; , priority&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;uint&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;0&lt;/span&gt; , autoDisconnect&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Boolean&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;false&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Boolean&lt;/span&gt; ;
&amp;nbsp;
        &lt;span style=&quot;color: #3f5fbf;&quot;&gt;/**
         * Returns true if one or more receivers are connected.
         * @return true if one or more receivers are connected.
         */&lt;/span&gt;
        &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;connected&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Boolean&lt;/span&gt; ;
&amp;nbsp;
        &lt;span style=&quot;color: #3f5fbf;&quot;&gt;/**
         * Disconnect the specified object or all objects if the parameter is null.
         * @return true if the specified receiver exist and can be unregister.
         */&lt;/span&gt;
        &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; disconnect&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; receiver&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:*&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;null&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Boolean&lt;/span&gt; ;
&amp;nbsp;
        &lt;span style=&quot;color: #3f5fbf;&quot;&gt;/**
         * Emit the specified values to the receivers.
         * @param ...values All values to emit to the receivers.
         */&lt;/span&gt;
        &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; emit&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; ...values&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Array&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt; ;
&amp;nbsp;
        &lt;span style=&quot;color: #3f5fbf;&quot;&gt;/**
         * Returns true if specified receiver is connected.
         * @return true if specified receiver is connected.
         */&lt;/span&gt;
        &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; hasReceiver&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; receiver&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:*&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Boolean&lt;/span&gt; ;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;The &lt;strong&gt;Receiver&lt;/strong&gt; interface is optional and can be use to defines a basic slot connected with &lt;strong&gt;Signaler&lt;/strong&gt; objects with the &lt;strong&gt;connect&lt;/strong&gt;() method (only the receive method is connected with the signal not the &lt;strong&gt;Receiver&lt;/strong&gt; reference).&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt; system.signals
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #3f5fbf;&quot;&gt;/**
     * The Receiver defines a simple method for receiving values from Signaler objects.
     */&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; interface Receiver
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #3f5fbf;&quot;&gt;/**
         * This method is called when the receiver is connected with a Signal object.
         * @param ...values All the values emitting by the signals connected with this object.
         */&lt;/span&gt;
        &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; receive&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; ...values&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Array&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt; ;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;h2&gt;Hello World&lt;/h2&gt;


&lt;p&gt;We begin with a first basic example. In this example we use the &lt;strong&gt;system.signals.Signal&lt;/strong&gt;, this class is a basic but full implementation of the &lt;strong&gt;Signaler&lt;/strong&gt; interface. This script can be compiled as an application with &lt;strong&gt;mxmlc&lt;/strong&gt; or as a document class in Flash Professional or all ActionScript IDE (&lt;strong&gt;FDT&lt;/strong&gt;, etc.)&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt; examples
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; system.signals.Signal;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.display&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;Sprite&lt;/span&gt;;
&amp;nbsp;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;SWF&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;width&lt;/span&gt;=&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;740&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #004993;&quot;&gt;height&lt;/span&gt;=&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;480&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #004993;&quot;&gt;frameRate&lt;/span&gt;=&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;24&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #004993;&quot;&gt;backgroundColor&lt;/span&gt;=&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;#666666&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
&amp;nbsp;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;class&lt;/span&gt; SignalExample extends &lt;span style=&quot;color: #004993;&quot;&gt;Sprite&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; SignalExample &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; signal&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Signal = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; Signal&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
            signal.&lt;span style=&quot;color: #004993;&quot;&gt;connect&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; write &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
            signal.emit&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;hello world&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// hello world&lt;/span&gt;
            signal.emit&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;thank you&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// thank you&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; write&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;h2&gt;Features&lt;/h2&gt;


&lt;p&gt;&lt;strong&gt;Signals&lt;/strong&gt; have many features.&lt;/p&gt;


&lt;h3&gt;Restrict the types and the number of arguments passed-in the emit method.&lt;/h3&gt;


&lt;p&gt;A signal can be initialized with specific value classes that will validate value objects on dispatch (optional).&lt;/p&gt;


&lt;p&gt;The '&lt;strong&gt;types&lt;/strong&gt;' property is an optional &lt;em&gt;read-write&lt;/em&gt; Array attribute who can register &lt;strong&gt;Class&lt;/strong&gt; references to defines a validation when the signal emit. If this property is null the signal not check the emit parameters.&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; signal&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Signal = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; Signal&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;Number&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;uint&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;restricted types : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; signal.types &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;If the 'types' property is null the signal not check the types and the number of the passed-in arguments when the emit method is invoked.&lt;/p&gt;


&lt;p&gt;Basic example to restrict the emit method with &lt;strong&gt;3 arguments&lt;/strong&gt; with the types &lt;strong&gt;String&lt;/strong&gt; , &lt;strong&gt;Number&lt;/strong&gt; and &lt;strong&gt;uint&lt;/strong&gt;.&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; system.signals.Signal ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; slot&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Function&lt;/span&gt; = &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; ...values&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Array&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;receive : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; values &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; signal&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Signal ;
&amp;nbsp;
signal = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; Signal&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
signal.types = &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;Number&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;uint&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt; ;
&amp;nbsp;
signal.&lt;span style=&quot;color: #004993;&quot;&gt;connect&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; slot &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
signal.emit&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;hello&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;2.5&lt;/span&gt;, &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;4&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// receive : hello,2.5,4&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;try&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    signal.emit&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;hello&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;2.5&lt;/span&gt; , &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;4.5&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;catch&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; e&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Error&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; e.&lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
    &lt;span style=&quot;color: #009900;&quot;&gt;// The parameter with the index 2 in the emit method isn't valid,&lt;/span&gt;
    &lt;span style=&quot;color: #009900;&quot;&gt;// must be an instance of the [class uint] class but is an instance of the Number class.&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;try&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    signal.emit&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;hello&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;catch&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; e&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Error&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; e.&lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
    &lt;span style=&quot;color: #009900;&quot;&gt;// The number of arguments in the emit method is not valid,&lt;/span&gt;
    &lt;span style=&quot;color: #009900;&quot;&gt;// must be invoked with 3 argument(s) and you call it with 1 argument(s).&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;try&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    signal.emit&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;catch&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; e&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Error&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; e.&lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
    &lt;span style=&quot;color: #009900;&quot;&gt;// The number of arguments in the emit method is not valid,&lt;/span&gt;
    &lt;span style=&quot;color: #009900;&quot;&gt;// must be invoked with 3 argument(s) and you call it with 0 argument(s).&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;h3&gt;Disconnect a specific receiver or all receiver&lt;/h3&gt;


&lt;p&gt;You can disconnect the receivers registered in a Signaler object with the method &lt;strong&gt;disconnect&lt;/strong&gt;(). This method can target a specific receiver (&lt;strong&gt;function&lt;/strong&gt; reference or &lt;strong&gt;Receiver&lt;/strong&gt; instance) but you can disconnect all registered receivers if you don't passed-in value.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Example :&lt;/strong&gt;&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; system.signals.Signal ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; signal&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Signal = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; Signal&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
signal.&lt;span style=&quot;color: #004993;&quot;&gt;connect&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; slot1 &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
signal.&lt;span style=&quot;color: #004993;&quot;&gt;connect&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; slot2 &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
signal.&lt;span style=&quot;color: #004993;&quot;&gt;connect&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; slot3 &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; signal.&lt;span style=&quot;color: #004993;&quot;&gt;length&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// 3&lt;/span&gt;
&amp;nbsp;
signal.disconnect&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; slot2 &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; signal.&lt;span style=&quot;color: #004993;&quot;&gt;length&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// 2&lt;/span&gt;
&amp;nbsp;
signal.disconnect&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// disconnect all&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; signal.&lt;span style=&quot;color: #004993;&quot;&gt;length&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// 0&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;&lt;strong&gt;Note :&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can retrieve the number of receivers with the read-only attribute : &lt;strong&gt;signal.length&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;You can retrieve if the signal contains one or more receivers with the method : &lt;strong&gt;signal.connected():Boolean&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;You can retrieve if a specific receiver is connected with the method : &lt;strong&gt;signal.hasReceiver( receiver:* ):Boolean&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Auto disconnect feature&lt;/h3&gt;


&lt;p&gt;&lt;strong&gt;Receivers&lt;/strong&gt; can be added for a one-time call and removed automatically on dispatch&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; system.signals.Signal ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; receiver&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Function&lt;/span&gt; = &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; signal&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Signal = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; Signal&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
signal.&lt;span style=&quot;color: #004993;&quot;&gt;connect&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; receiver , &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;0&lt;/span&gt; , &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
signal.emit&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;hello world&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// hello world&lt;/span&gt;
signal.emit&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;bonjour monde&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;Only the first message is dispatched, the reveiver is automatically disconnected and can't receive the next messages.&lt;/p&gt;


&lt;h3&gt;Receiver priority&lt;/h3&gt;


&lt;p&gt;When you connect a receiver with the connect method you can apply a priority over your reference.&lt;/p&gt;


&lt;p&gt;The priority is designated by an uint value( an integer &amp;gt; 0 ). The higher the number, the higher the priority. All receivers with priority n are processed before receivers of priority n-1. If two or more receivers share the same priority, they are processed in the order in which they were added. The default priority is 0.&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; system.signals.Signal ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; slot1&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Function&lt;/span&gt; = &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;slot1: &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; slot2&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Function&lt;/span&gt; = &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;slot2: &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; slot3&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Function&lt;/span&gt; = &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;slot3: &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; signal&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Signal = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; Signal&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
signal.&lt;span style=&quot;color: #004993;&quot;&gt;connect&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; slot1 ,  &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;10&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
signal.&lt;span style=&quot;color: #004993;&quot;&gt;connect&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; slot2 , &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;999&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
signal.&lt;span style=&quot;color: #004993;&quot;&gt;connect&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; slot3 , &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;400&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
signal.emit&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;hello world&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #009900;&quot;&gt;// slot2: hello world&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;// slot3: hello world&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;// slot1: hello world&lt;/span&gt;&lt;/pre&gt;


&lt;h2&gt;Use composition with the system.signals.Signaler interface&lt;/h2&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt; examples.signals
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; system.signals.Signal;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; system.signals.Signaler;
&amp;nbsp;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.display&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;Sprite&lt;/span&gt;;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.events&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;MouseEvent&lt;/span&gt;;
&amp;nbsp;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;class&lt;/span&gt; SignalButton extends &lt;span style=&quot;color: #004993;&quot;&gt;Sprite&lt;/span&gt; implements Signaler
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; SignalButton&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;width&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Number&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;160&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;height&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Number&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;20&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;color&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Number&lt;/span&gt; = 0xA2A2A2 &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            _signal = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; Signal&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; , SignalButton &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
            &lt;span style=&quot;color: #004993;&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;MouseEvent&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;CLICK&lt;/span&gt; , _click &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
            &lt;span style=&quot;color: #004993;&quot;&gt;graphics&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;beginFill&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;color&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
            &lt;span style=&quot;color: #004993;&quot;&gt;graphics&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;drawRect&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;0&lt;/span&gt; , &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;0&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;width&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;height&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
            &lt;span style=&quot;color: #004993;&quot;&gt;buttonMode&lt;/span&gt;    = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ;
            &lt;span style=&quot;color: #004993;&quot;&gt;mouseEnabled&lt;/span&gt;  = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ;
            &lt;span style=&quot;color: #004993;&quot;&gt;useHandCursor&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;get&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;uint&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;return&lt;/span&gt; _signal.&lt;span style=&quot;color: #004993;&quot;&gt;length&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;connect&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; receiver&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:*&lt;/span&gt; , priority&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;uint&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;0&lt;/span&gt; , autoDisconnect&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Boolean&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;false&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Boolean&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;return&lt;/span&gt; _signal.&lt;span style=&quot;color: #004993;&quot;&gt;connect&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; receiver , priority , autoDisconnect &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;connected&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Boolean&lt;/span&gt;
         &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;return&lt;/span&gt; _signal.&lt;span style=&quot;color: #004993;&quot;&gt;connected&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; disconnect&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; receiver&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:*&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;null&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Boolean&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;return&lt;/span&gt; _signal.disconnect&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; receiver &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; emit&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; ...values&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Array&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            _signal.emit.&lt;span style=&quot;color: #004993;&quot;&gt;apply&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; values &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; hasReceiver&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; receiver&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:*&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Boolean&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;return&lt;/span&gt; _signal.hasReceiver&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; receiver &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; _signal&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Signal ;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; _click&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; e&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;MouseEvent&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            _signal.emit&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;click&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;this&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Now we can write a little example to use the previous class :&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt; examples
 &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; examples.signals.SignalButton;
&amp;nbsp;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.display&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;Sprite&lt;/span&gt;;
&amp;nbsp;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;SWF&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;width&lt;/span&gt;=&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;760&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #004993;&quot;&gt;height&lt;/span&gt;=&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;480&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #004993;&quot;&gt;frameRate&lt;/span&gt;=&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;24&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #004993;&quot;&gt;backgroundColor&lt;/span&gt;=&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;#666666&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
&amp;nbsp;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;class&lt;/span&gt; SignalButtonExample extends &lt;span style=&quot;color: #004993;&quot;&gt;Sprite&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; SignalButtonExample&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; button&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;SignalButton = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; SignalButton&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;200&lt;/span&gt; , &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;24&lt;/span&gt; , 0xCCCCCC &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
            button.&lt;span style=&quot;color: #004993;&quot;&gt;x&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;25&lt;/span&gt; ;
            button.&lt;span style=&quot;color: #004993;&quot;&gt;y&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;24&lt;/span&gt; ;
&amp;nbsp;
            button.&lt;span style=&quot;color: #004993;&quot;&gt;connect&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; notify &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
            &lt;span style=&quot;color: #004993;&quot;&gt;addChild&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; button &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; notify&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;target&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;SignalButton &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;notify : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;type&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot; in &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;target&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
 &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;h2&gt;Basic example to use the system.signals.Receiver interface&lt;/h2&gt;


&lt;p&gt;First we defines a little class &lt;strong&gt;Messenger&lt;/strong&gt; who format a specific receiving message with a name and a string pattern.&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt; examples.signals
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; system.Strings;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; system.console;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; system.signals.Receiver;
&amp;nbsp;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;class&lt;/span&gt; Messenger implements Receiver
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; Messenger&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; pattern&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; = &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;{0}:{1}&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;this&lt;/span&gt;.pattern = pattern ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; pattern&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; ;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; receive&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; ...values&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Array&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt;    = values&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; ;
            &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; = values&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; ;
            console.writeLine&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; Strings.format&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; pattern , &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Now the document class to compile the basic example.&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt; examples 
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; examples.signals.Messenger;
&amp;nbsp;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; system.console;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; system.diagnostics.TextFieldConsole;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; system.signals.Signal;
&amp;nbsp;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.display&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;Sprite&lt;/span&gt;;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.display&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;StageAlign&lt;/span&gt;;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.display&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;StageScaleMode&lt;/span&gt;;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.events&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;Event&lt;/span&gt;;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.text&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;TextField&lt;/span&gt;;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.text&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;TextFormat&lt;/span&gt;;
&amp;nbsp;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;SWF&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;width&lt;/span&gt;=&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;760&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #004993;&quot;&gt;height&lt;/span&gt;=&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;480&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #004993;&quot;&gt;frameRate&lt;/span&gt;=&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;24&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #004993;&quot;&gt;backgroundColor&lt;/span&gt;=&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;#666666&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
&amp;nbsp;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;class&lt;/span&gt; MessengerExample extends &lt;span style=&quot;color: #004993;&quot;&gt;Sprite&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; MessengerExample&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #009900;&quot;&gt;// stage&lt;/span&gt;
&amp;nbsp;
            &lt;span style=&quot;color: #004993;&quot;&gt;stage&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;align&lt;/span&gt;     = &lt;span style=&quot;color: #004993;&quot;&gt;StageAlign&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;TOP_LEFT&lt;/span&gt;;
            &lt;span style=&quot;color: #004993;&quot;&gt;stage&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;scaleMode&lt;/span&gt; = &lt;span style=&quot;color: #004993;&quot;&gt;StageScaleMode&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;NO_SCALE&lt;/span&gt;;
&amp;nbsp;
            &lt;span style=&quot;color: #004993;&quot;&gt;stage&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;Event&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;RESIZE&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;resize&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
            &lt;span style=&quot;color: #009900;&quot;&gt;// console&lt;/span&gt;
&amp;nbsp;
            textfield                   = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;TextField&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
            textfield.&lt;span style=&quot;color: #004993;&quot;&gt;defaultTextFormat&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;TextFormat&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;Courier New&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;14&lt;/span&gt; , 0xFFFFFF &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
            textfield.&lt;span style=&quot;color: #004993;&quot;&gt;multiline&lt;/span&gt;         = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ;
            textfield.&lt;span style=&quot;color: #004993;&quot;&gt;selectable&lt;/span&gt;        = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ;
            textfield.&lt;span style=&quot;color: #004993;&quot;&gt;wordWrap&lt;/span&gt;          = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ;
&amp;nbsp;
            &lt;span style=&quot;color: #004993;&quot;&gt;addChild&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; textfield &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
            &lt;span style=&quot;color: #004993;&quot;&gt;resize&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
            console = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; TextFieldConsole&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; textfield &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
            &lt;span style=&quot;color: #009900;&quot;&gt;// receiver&lt;/span&gt;
&amp;nbsp;
            &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; messenger&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Messenger = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; Messenger&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;{0} say: {1}&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;  ;
&amp;nbsp;
            &lt;span style=&quot;color: #009900;&quot;&gt;// signaler&lt;/span&gt;
&amp;nbsp;
            signal = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; Signal&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt;,&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
            signal.&lt;span style=&quot;color: #004993;&quot;&gt;connect&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; messenger &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
            signal.emit&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;john&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;hello world&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
            signal.emit&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;jack&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;Hi !&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
            signal.emit&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;jack&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;signals are fast&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; signal&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Signal ;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; textfield&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;TextField&lt;/span&gt; ;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;resize&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; e&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Event&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;null&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;stage&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; textfield &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                textfield.&lt;span style=&quot;color: #004993;&quot;&gt;width&lt;/span&gt;  = &lt;span style=&quot;color: #004993;&quot;&gt;stage&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;stageWidth&lt;/span&gt; ;
                textfield.&lt;span style=&quot;color: #004993;&quot;&gt;height&lt;/span&gt; = &lt;span style=&quot;color: #004993;&quot;&gt;stage&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;stageHeight&lt;/span&gt; ;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;&lt;strong&gt;Note :&lt;/strong&gt; you can read this article in my google site with the &lt;a href=&quot;http://sites.google.com/site/ekameleon/Home/opensource/vegas-opensource-project/vegas-tutorials/signalers-and-receivers&quot; hreflang=&quot;en&quot;&gt;article &quot;Signals and Receivers&quot;&lt;/a&gt; (this version is always updated with Google Documents)&lt;/p&gt;


&lt;p&gt;More informations about &lt;a href=&quot;http://code.google.com/p/vegas/&quot;&gt;VEGAS the ActionScript/ECMAScript opensource framework&lt;/a&gt; in Google code :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://code.google.com/p/vegas/wiki/InstallVEGASwithSVN&quot;&gt;Install and download VEGAS&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description>
    
    
    
          <comments>http://www.ekameleon.net/blog/index.php?post/2010/02/10/Signals-and-Receivers#comment-form</comments>
      <wfw:comment>http://www.ekameleon.net/blog/index.php?post/2010/02/10/Signals-and-Receivers#comment-form</wfw:comment>
      <wfw:commentRss>http://www.ekameleon.net/blog/index.php?feed/rss2/comments/122</wfw:commentRss>
      </item>
    
  <item>
    <title>Vacances à New York ... rattrapé par Flash et Adobe :)</title>
    <link>http://www.ekameleon.net/blog/index.php?post/2009/09/30/Vacances-a-New-York-rattrape-par-Flash-et-Adobe-%3A</link>
    <guid isPermaLink="false">urn:md5:90f1c49dd1d7a2235bbd4ff969863ab9</guid>
    <pubDate>Wed, 30 Sep 2009 22:10:00 +0200</pubDate>
    <dc:creator>eKameleon</dc:creator>
        <category>General</category>
            
    <description>&lt;p&gt;Petit message super minimaliste pour vous annoncer mon retour de vacances (premières vraies vacances depuis des années) et forcément bientôt des nouveautés...&lt;/p&gt;


&lt;pre&gt;&lt;img src=&quot;http://www.ekameleon.net/blog/public/images/photos/flash_in_timesquare_03.jpg&quot; alt=&quot;Flash in Times Square (zoom&quot; /&gt;)&lt;/pre&gt;


&lt;p&gt;En attendant voici deux petites photos qui montrent que même en vacances de l'autre côté de l'atlantique il est vraiment très difficile de ne pas me retrouver proche de la communauté &lt;strong&gt;Flash&lt;/strong&gt; :D&lt;/p&gt;    &lt;p&gt;&lt;img src=&quot;http://www.ekameleon.net/blog/public/images/photos/flash_in_timesquare_01.jpg&quot; alt=&quot;Times Square la surprise&quot; /&gt;&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://www.ekameleon.net/blog/public/images/photos/flash_in_timesquare_02.jpg&quot; alt=&quot;Adobe Flash in Times Square&quot; /&gt;&lt;/p&gt;


&lt;p&gt;Photos prises sur Times Square au milieu des tas d'écrans publicitaires ... franchement faut le faire &lt;img src=&quot;/blog/themes/default/smilies/smile.png&quot; alt=&quot;:)&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;</description>
    
    
    
          <comments>http://www.ekameleon.net/blog/index.php?post/2009/09/30/Vacances-a-New-York-rattrape-par-Flash-et-Adobe-%3A#comment-form</comments>
      <wfw:comment>http://www.ekameleon.net/blog/index.php?post/2009/09/30/Vacances-a-New-York-rattrape-par-Flash-et-Adobe-%3A#comment-form</wfw:comment>
      <wfw:commentRss>http://www.ekameleon.net/blog/index.php?feed/rss2/comments/121</wfw:commentRss>
      </item>
    
  <item>
    <title>D - Chargement de ressources externes ( Partie 5 - localization )</title>
    <link>http://www.ekameleon.net/blog/index.php?post/2009/08/27/D-Chargement-de-ressources-externes-Partie-5-localization</link>
    <guid isPermaLink="false">urn:md5:1461e63afd66f3a7306b81687dc20782</guid>
    <pubDate>Thu, 27 Aug 2009 17:45:00 +0200</pubDate>
    <dc:creator>eKameleon</dc:creator>
        <category>VEGAS</category>
        <category>as3</category><category>design pattern</category><category>i18n</category><category>IoC</category><category>opensource</category><category>resources</category><category>vegas</category>    
    <description>&lt;h2&gt;Les ressources de type &quot;i18n&quot; (localisation)&lt;/h2&gt;


&lt;h3&gt;Généralités&lt;/h3&gt;


&lt;p&gt;Il est très important de pouvoir&lt;a href=&quot;http://fr.wikipedia.org/wiki/Localisation_%28informatique%29&quot;&gt; &quot;localiser&quot; (ou régionaliser)&lt;/a&gt; nos applications. Localiser une application permet de rendre dynamique son contenu (texte, sonore ou autres) en créant une interface utilisateur qui peut changer en fonction d'une langue en particulier. La localisation d'une application permet d'améliorer l'accessibilité pour différents utilisateurs et il est certain qu'avec toutes les difficultés que l'on peut avoir pour communiquer de façon général, il est tout de même sympathique de pouvoir le faire avec le plus grand nombre dans le monde entier.&lt;/p&gt;


&lt;p&gt;Une bon moteur de localisation permet de changer à tout moment les traductions et éléments graphiques de l'application en fonction de données traduites dans plusieurs langues. Il est certain que le plus souvent la localisation d'un site passe par une page d'accueil simple qui permet de diriger l'utilisateur vers une version spécifique de l'application avec un contenu régionalisé.&lt;/p&gt;


&lt;p&gt;Fonctionnalités importantes du moteur de localisations définies dans &lt;strong&gt;AndromedAS&lt;/strong&gt;&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Externalisation des traductions et documents.&lt;/li&gt;
&lt;li&gt;Utilisation de fichiers ou données externes encodées en &lt;strong&gt;UTF8&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Moteur dynamique au &quot;runtime&quot;. La localisation doit être totalement dynamique et doit intervenir après la compilation (plus léger et plus simple à maintenir)&lt;/li&gt;
&lt;li&gt;API simplifiée permettant de centraliser les mises à jours de l'interface utilisateur via un mapping utilisant plusieurs stratégies selon les besoins.&lt;/li&gt;
&lt;li&gt;Par défaut, utilisation du format de donnée &lt;strong&gt;eden&lt;/strong&gt; ou &lt;strong&gt;JSON&lt;/strong&gt; (&lt;a href=&quot;http://www.json.org&quot;&gt;http://www.json.org&lt;/a&gt;). Malgré tout il est assez simple de créer un module de parsing basé sur une autre notation comme du &lt;strong&gt;XML&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Dans &lt;strong&gt;Flash&lt;/strong&gt; et surtout dans le framework de base &lt;strong&gt;ActionScript&lt;/strong&gt; nous trouvons la propriété &lt;a href=&quot;http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/system/Capabilities.html#language&quot;&gt;flash.system.Capabilites.language&lt;/a&gt; qui permet à tout moment de renvoyer le code langue du système dans lequel l'application &lt;strong&gt;swf&lt;/strong&gt; vient d'être lancée. L'&lt;strong&gt;ActionScript&lt;/strong&gt; se base sur des noms des &quot;codes langue&quot; au format &lt;strong&gt;ISO 639-1&lt;/strong&gt;, par exemple la propriété &lt;strong&gt;language&lt;/strong&gt; aura pour valeur &quot;&lt;strong&gt;fr&lt;/strong&gt;&quot; si le système par défaut est un système français.&lt;/p&gt;


&lt;h3&gt;Implémentation du moteur de localisation de AndromedAS&lt;/h3&gt;


&lt;p&gt;Dans &lt;strong&gt;AndromedAS&lt;/strong&gt; le moteur de localisation se trouve dans le package &lt;strong&gt;andromeda.i18n&lt;/strong&gt;.&lt;/p&gt;


&lt;h4&gt;1 - La classe andromeda.i18n.Lang&lt;/h4&gt;


&lt;p&gt;La première classe que nous allons étudier dans ce package est la classe &lt;a href=&quot;http://www.ekameleon.net/vegas/docs/andromeda/i18n/Lang.html&quot;&gt;andromeda.i18n.Lang&lt;/a&gt; qui permet d'énumérer les &quot;codes langue&quot; par défaut définis par la norme &lt;strong&gt;ISO 639-1&lt;/strong&gt; dans le &lt;strong&gt;FlashPlayer&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;Cette classe donne un outil simple pour valider dans vos applications les langues disponibles.&lt;/p&gt;


&lt;p&gt;Il est ainsi possible d'ajouter d'autres langues en cas de besoin dans la liste des langues par défaut du &lt;strong&gt;FlashPlayer&lt;/strong&gt; mais bien entendu elle ne seront pas prises en compte automatiquement par la propriété &lt;strong&gt;flash.system.Capabilities.language&lt;/strong&gt; (AS3) du FlashPlayer.&lt;/p&gt;


&lt;p&gt;Voici un exemple d'utilisation de cette classe&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; asgard.i18n.Lang ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;Lang.ES.toString() : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; Lang.ES.&lt;span style=&quot;color: #004993;&quot;&gt;toString&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// es&lt;/span&gt;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;Lang.ES.valueOf()  : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; Lang.ES.&lt;span style=&quot;color: #004993;&quot;&gt;valueOf&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;  &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// es&lt;/span&gt;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;Lang.ES.toSource() : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; Lang.ES.toSource&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// new andromeda.i18n.Lang( &amp;quot;es&amp;quot; , &amp;quot;Spanish&amp;quot; )&lt;/span&gt;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;Lang.ES.label      : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; Lang.ES.label      &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// Spanish&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;Lang.get('fr') == Lang.FR : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; Lang.&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;fr&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; == Lang.FR &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// true&lt;/span&gt;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;Lang.validate('fr') : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; Lang.validate&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;'fr'&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// true&lt;/span&gt;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;Lang.validate( Lang.FR ) : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; Lang.validate&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; Lang.FR &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// true&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;Lang.LANGS : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; Lang.LANGS &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&lt;span style=&quot;color: #009900;&quot;&gt;// {pl:pl,nl:nl,es:es,tr:tr,it:it,da:da,pt:pt,fi:fi,zh-CN:zh-CN,no:no,ja:ja,de:de,ru:ru,fr:fr,zh-TW:zh-TW,xu:xu,ko:ko,en:en,sv:sv,cs:cs,hu:hu}&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;Lang.LANGS.size() : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; Lang.LANGS.&lt;span style=&quot;color: #004993;&quot;&gt;size&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// 21&lt;/span&gt;&lt;/pre&gt;


&lt;h4&gt;2 - Fichier externe et nomenclature&lt;/h4&gt;


&lt;p&gt;Les données externes permettant la création des différentes versions du contenu de l'application localisée doivent être par défaut au format &lt;strong&gt;eden&lt;/strong&gt;. Le format &lt;strong&gt;eden&lt;/strong&gt; permet de créer rapidement des fichiers de configuration simples.&lt;/p&gt;


&lt;p&gt;En général, il est possible d'utiliser une nomenclature spécifique pour créer les fichiers textes externes de localisation. Par exemple pour créer un fichier de configuration en français avec un contexte spécifique, il suffira de créer le fichier&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&quot;locale/localize_fr.eden&quot;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Nous isolons donc cette notation en la divisant en 4 éléments distincts&amp;nbsp;:  &lt;strong&gt;{path}{prefix}{lang}[suffix}&lt;/strong&gt;&lt;/p&gt;


&lt;p&gt;Il existe une interface simple qui permet de créer facilement des objets qui permettent de charger les fichiers de localisation.&lt;/p&gt;    &lt;p&gt;Cette interface en &lt;strong&gt;AS3&lt;/strong&gt; est l'interface &lt;a href=&quot;http://www.ekameleon.net/vegas/docs/andromeda/i18n/ILocalizationLoader.html&quot;&gt;andromeda.i18n.ILocalizationLoader&lt;/a&gt; est définie avec la signature suivante&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #3f5fbf;&quot;&gt;/**
 * Indicates the Localization reference of the loader.
 */&lt;/span&gt;
&lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;get&lt;/span&gt; localization&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Localization ;
&lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;set&lt;/span&gt; localization&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; localization&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Localization &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #3f5fbf;&quot;&gt;/**
 * The path of the external file.
 */&lt;/span&gt;
&lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;get&lt;/span&gt; path&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; ;
&lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;set&lt;/span&gt; path&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #3f5fbf;&quot;&gt;/**
 * Determinates the prefix value of the localization files.
 */&lt;/span&gt;
&lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;get&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;prefix&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; ;
&lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;set&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;prefix&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;s&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #3f5fbf;&quot;&gt;/**
 * The suffix of the localization file.
 */&lt;/span&gt;
&lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;get&lt;/span&gt; suffix&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; ;
&lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;set&lt;/span&gt; suffix&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #3f5fbf;&quot;&gt;/**
 * Sends and loads data from the specified passed-in lang value (the passed-in argument must be a Lang reference or a valid string).
 * @param lang The localization Lang value
 */&lt;/span&gt;
&lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; loadLang&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; lang&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:*&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;Ainsi par défaut vous pouvez utiliser la classe &lt;a href=&quot;http://www.ekameleon.net/vegas/docs/andromeda/i18n/EdenLocalizationLoader.html&quot;&gt;andromeda.i18n.EdenLocalizationLoader&lt;/a&gt; ou la classe &lt;a href=&quot;http://www.ekameleon.net/vegas/docs/andromeda/i18n/JSONLocalizationLoader.html&quot;&gt;andromeda.i18n.JSONLocalizationLoader&lt;/a&gt; pour charger vos fichiers de localisation et mettre à jour automatiquement la ou les moteur de localisation de votre application.&lt;/p&gt;


&lt;p&gt;Donc imaginons une application qui doit charger des textes et des contenus en version français et anglais, nous pouvons mettre en place 2 fichiers textes (&lt;strong&gt;UTF8&lt;/strong&gt;) au format &lt;strong&gt;eden&lt;/strong&gt;&amp;nbsp;:&lt;/p&gt;


&lt;p&gt;Contenu du fichier localize_fr.eden (français)&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
    lang        &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;fr&amp;quot;&lt;/span&gt; ,
    &lt;span style=&quot;color: #004993;&quot;&gt;namespace&lt;/span&gt;   &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;http://www.ekameleon.net/2009/andromeda&amp;quot;&lt;/span&gt; ,
    &lt;span style=&quot;color: #004993;&quot;&gt;version&lt;/span&gt;     &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;1.0.0.0&amp;quot;&lt;/span&gt; ,
    &lt;span style=&quot;color: #004993;&quot;&gt;type&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;eden&amp;quot;&lt;/span&gt; ,
&amp;nbsp;
    door &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        connectStarted    &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;DEBUT CONNEXION&amp;quot;&lt;/span&gt; ,
        connectFinished   &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;FIN CONNEXION&amp;quot;&lt;/span&gt; ,       
        connectInProgress &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;CONNEXION EN COURS&amp;quot;&lt;/span&gt; ,       
        connectOutOfTime  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;DELAIS DE CONNEXION DEPASSE&amp;quot;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    ,
    &lt;span style=&quot;color: #004993;&quot;&gt;info&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        finish_loading   &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;Fin du chargement&amp;quot;&lt;/span&gt;   ,
        progress_loading &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;Chargement en cours&amp;quot;&lt;/span&gt; ,
        start_loading    &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;Début du chargement&amp;quot;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    ,  
    myField &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #004993;&quot;&gt;selectable&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ,
        &lt;span style=&quot;color: #004993;&quot;&gt;text&lt;/span&gt;       &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;Bonjour le monde&amp;quot;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Contenu du fichier localize_en.eden (anglais)&amp;nbsp;:&lt;/p&gt;
&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;     
    lang        &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;en&amp;quot;&lt;/span&gt; ,
    &lt;span style=&quot;color: #004993;&quot;&gt;namespace&lt;/span&gt;   &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;http://www.ekameleon.net/2009/andromeda&amp;quot;&lt;/span&gt; ,
    &lt;span style=&quot;color: #004993;&quot;&gt;version&lt;/span&gt;     &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;1.0.0.0&amp;quot;&lt;/span&gt; ,
    &lt;span style=&quot;color: #004993;&quot;&gt;type&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;eden&amp;quot;&lt;/span&gt; ,
    door &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;    
         connectStarted    &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;START CONNECTION&amp;quot;&lt;/span&gt; ,
         connectFinished   &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;FINISH CONNECTION&amp;quot;&lt;/span&gt; ,       
         connectInProgress &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;CONNECTION IN PROGRESS&amp;quot;&lt;/span&gt; ,       
         connectOutOfTime  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;THE CONNECTION IS OUT OF TIME&amp;quot;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    ,
    &lt;span style=&quot;color: #004993;&quot;&gt;info&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        finish_loading   &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;THE LOADING IS FINISHED&amp;quot;&lt;/span&gt; ,
        progress_loading &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;THE LOADING IS IN PROGRESS&amp;quot;&lt;/span&gt; ,
        start_loading    &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;THE LOADING IS STARTED&amp;quot;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    ,
    myField &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
          &lt;span style=&quot;color: #004993;&quot;&gt;selectable&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;false&lt;/span&gt; ,
          &lt;span style=&quot;color: #004993;&quot;&gt;text&lt;/span&gt;       &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;Hello world&amp;quot;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;h4&gt;3 - La classe Localization&lt;/h4&gt;


&lt;p&gt;La classe &lt;strong&gt;andromeda.i18n.Localization&lt;/strong&gt; centralise le moteur de localisation de &lt;strong&gt;VEGAS&lt;/strong&gt; avec une gestion globale via multi-singletons des références de type &lt;strong&gt;Localization&lt;/strong&gt;. En effet il est possible de créer plusieurs références distinctes et globales pour gérer de façon séparé plusieurs localisations dans une même application. Malgré cela je vous avoue qu'il est assez rare d'utiliser plusieurs référence de type &lt;strong&gt;Localization&lt;/strong&gt; dans une même application.&lt;/p&gt;


&lt;p&gt;La classe Localization contient donc une méthode statique &lt;strong&gt;getInstance(id:String)&lt;/strong&gt; qui renvoie à tout moment un singleton de type &lt;strong&gt;Localization&lt;/strong&gt; dans le code de l'application. Exemple&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; localization&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Localization  = Localization.getInstance&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;Je vous conseille de lire tranquillement la documentation de cette classe avant de lire la suite&amp;nbsp;: &lt;a href=&quot;http://www.ekameleon.net/vegas/docs/andromeda/i18n/Localization.html&quot;&gt;http://www.ekameleon.net/vegas/docs/andromeda/i18n/Localization.html&lt;/a&gt;&lt;/p&gt;


&lt;p&gt;La classe &lt;strong&gt;Localization&lt;/strong&gt; contient une &lt;strong&gt;HashMap&lt;/strong&gt; qui lui permet de stocker simplement des objets de type &lt;strong&gt;andromeda.i18n.Locale&lt;/strong&gt; dynamiques qui contiendront les propriétés chargées dans les fichiers de texte externes en fonction des &quot;code langues&quot; utilisés dans l'application.&lt;/p&gt;


&lt;p&gt;La classe &lt;strong&gt;Locale&lt;/strong&gt; est une classe très très simple et surtout &quot;&lt;strong&gt;dynamique&lt;/strong&gt;&quot; qui permet de créer des objets typés compatibles avec le moteur de localisation. Les instances de type &lt;strong&gt;Locale&lt;/strong&gt; servent avant tout à récupérer les données contenus dans les objets externes.&lt;/p&gt;


&lt;p&gt;La classe &lt;strong&gt;Localization&lt;/strong&gt; peut diffuser des événements, le plus important de tous est l'événement &lt;strong&gt;LocalizationEvent.CHANGE&lt;/strong&gt; qui notifie la mise à jour du moteur de localisation. L'application utilisateur peut ainsi changer si la langue courante du moteur change. Exemple&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; andromeda.events.LocalizationEvent ;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; andromeda.i18n.Localization ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;change&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Function&lt;/span&gt; = &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; e&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;LocalizationEvent &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; e &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// changer les vues de l'application maintenant&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; localization&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Localization = Localization.getInstance&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
localization.&lt;span style=&quot;color: #004993;&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; LocalizationEvent.&lt;span style=&quot;color: #004993;&quot;&gt;CHANGE&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;change&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;Voyons maintenant de plus prêt comment fonctionne le moteur de localisation.&lt;/p&gt;


&lt;p&gt;La classe &lt;strong&gt;Localization&lt;/strong&gt; possède une gestion des langues basée sur un &quot;&lt;strong&gt;buffer&lt;/strong&gt;&quot;, pour toutes les langues utilisées dans l'application un objet de type Locale est créé et permet de récupérer simplement les textes et données. Si pour un identifiant de langue donné l'instance de type Localization ne possède pas encore les données (aucun objet Locale n'existe encore), alors la &lt;strong&gt;Localization&lt;/strong&gt; utilise un objet spécialisé qui va charger automatiquement les données nécessaires dans le fichier externe correspondant à la langue courante sélectionnée.&lt;/p&gt;


&lt;p&gt;Pour changer à tout moment de langue courante il suffit donc sur l'objet de type Localization d'utiliser la propriété virtuelle &quot;current&quot; comme ceci&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;Localization.getInstance&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.current = Lang.FR ; &lt;span style=&quot;color: #009900;&quot;&gt;// français avec utilisation de l'énumération Lang.&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;ou directement&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;Localization.getInstance&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.current = &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;en&amp;quot;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// anglais utilisation directe d'un identifiant String valide.&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Pour charger les données externes, la localisation utilise en interne un chargeur qui implémente l'interface &lt;strong&gt;andromeda.i18n.ILocalizationLoader&lt;/strong&gt; comme défini au début de cet tutoriel. Il est possible à tout moment de récupérer ou modifier la référence interne du loader de la &lt;strong&gt;Localization&lt;/strong&gt; via la propriété &quot;&lt;strong&gt;loader&lt;/strong&gt;&quot;&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; system.events.ActionEvent ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;loader&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;EdenLocalizationLoader = localization.&lt;span style=&quot;color: #004993;&quot;&gt;loader&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;as&lt;/span&gt; EdenLocalizationLoader ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;loader&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; ActionEvent.START , debug &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&lt;span style=&quot;color: #004993;&quot;&gt;loader&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; ActionEvent.FINISH , debug &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;loader&lt;/span&gt;.path = &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;locale/&amp;quot;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;Dans ce petit bout de code je récupère la référence du chargeur et j'écoute les événements &lt;strong&gt;ActionEvent.START&lt;/strong&gt; et &lt;strong&gt;ActionEvent.FINISH&lt;/strong&gt; qui notifient le début et la fin du chargement opéré par le &lt;strong&gt;loader&lt;/strong&gt;. Je modifie aussi la propriété &quot;&lt;strong&gt;path&lt;/strong&gt;&quot; de l'objet pour définir un chemin différent pour le fichier &quot;&lt;strong&gt;localize_ID.eden&lt;/strong&gt;&quot; que je vais charger quand la propriété &quot;&lt;strong&gt;current&lt;/strong&gt;&quot; sera utilisé pour la première fois pour un identifiant de langue donné&lt;/p&gt;


&lt;p&gt;A noter que si pour un identifiant de langue, l'objet de type Locale existe déjà dans la &lt;strong&gt;Localization&lt;/strong&gt;, l'événement &lt;strong&gt;LocalizationEvent.CHANGE&lt;/strong&gt; et directement invoqué étant donné que le moteur n'a pas besoin de charger à nouveau les données. Cette optimisation permet d'éviter certaines lourdeurs dans une application. Il est évidant qu'il est assez rare de devoir modifier plusieurs fois dynamiquement le contenu pour une langue donnée des données externes d'une même application.&lt;/p&gt;


&lt;p&gt;En cas de soucis il est tout de même possible à tout moment d'utiliser la méthode &quot;&lt;strong&gt;remove( id )&lt;/strong&gt;&quot; pour vider pour un identifiant de langue spécifique le &lt;strong&gt;buffer&lt;/strong&gt; interne de la &lt;strong&gt;Localization&lt;/strong&gt;. Par la suite si la propriété &quot;&lt;strong&gt;current&lt;/strong&gt;&quot; est réutilisé pour le même identifiant de langue, les données externes seront chargées à nouveau et remplies dans le &lt;strong&gt;buffer&lt;/strong&gt; du moteur de localisation.&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;Localization.getInstance&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.remove&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; Lang.FR &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// vider le cache&lt;/span&gt;
&amp;nbsp;
Localization.getInstance&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.current = Lang.FR ; &lt;span style=&quot;color: #009900;&quot;&gt;// recharger et remettre à jour la vue&lt;/span&gt;&lt;/pre&gt;


&lt;h4&gt;4 - La méthode Localization.getLocale()&lt;/h4&gt;


&lt;p&gt;Dans les points précédents nous avons pu voir comment charger les données externes et modifier à tout moment la langue courante du moteur de localisation avec notification de ce changement par un événement.&lt;/p&gt;


&lt;p&gt;Maintenant il reste à comprendre comment récupérer les données contenues dans l'objet de type &lt;strong&gt;Locale&lt;/strong&gt; défini pour la langue courante.&lt;/p&gt;


&lt;p&gt;Pour récupérer à tout moment l'objet de type &lt;strong&gt;Locale&lt;/strong&gt; il suffit donc d'utiliser la méthode &lt;strong&gt;getLocale()&lt;/strong&gt; comme ceci&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; locale&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Locale = Localization.getInstance&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.getLocale&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; prop&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;in&lt;/span&gt; locale&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;  * &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; prop&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot; : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; locale&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;prop&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// énumération des données contenues dans l'objet &lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Si par exemple je cherche à récupérer dans les exemples définis au début du tutoriel un texte en particulier je peux taper par exemple directement&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; = Localization.getInstance&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.getLocale&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;info&lt;/span&gt;.start_loading ;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// Début du chargement&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Maintenant j'ai ajouté une petite fonctionnalité particulière dans cette méthode avec la possibilité d'inclure un paramètre dans la méthode &quot;getLocale&quot; qui permet de localiser plus finement un attribut en particulier dans l'objet Locale, par exemple&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; = Localization.getInstance&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.getLocale&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;info.start_loading&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// Début du chargement&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Je vais récupérer automatiquement dans l'objet &quot;info&quot; contenu dans l'objet Locale la valeur voulue.&lt;/p&gt;


&lt;p&gt;J'utilise beaucoup cette fonctionnalité avec un câblage un peu particulier de mes éléments graphiques. En effet de façon général tous mes éléments graphiques (clips, champs de texte etc... ) sont identifiables et possèdent tous un identifiant unique qui leur permet d'être unique dans l'application. Mais je me sers beaucoup de cette fonctionnalité pour récupérer pour chacun de mes éléments graphiques le contenu localisé qui leur est destiné.&lt;/p&gt;


&lt;h4&gt;5 - La méthode Localization.init()&lt;/h4&gt;


&lt;p&gt;Dernière petite méthode particulière du moteur de localisation avec la méthode &quot;init()&quot;, cette méthode est définie comme ceci&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;init&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; o&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Object&lt;/span&gt; , id&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt;=&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;null&lt;/span&gt; , callback&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Function&lt;/span&gt;=&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;null&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Elle prend en paramètre les arguments suivant&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;o&amp;nbsp;: un objet que l'on souhaite mapper avec toutes les valeurs contenues dans la localisation pour un identifiant donné.&lt;/li&gt;
&lt;li&gt;id&amp;nbsp;: un identifiant de type String qui permet une recherche dans l'objet Locale pour la langue courante et qui permet de copier membre à membre toutes les propriétés contenus dans l'attribut spécifique dans l'objet spécifié dans la méthode. Si cet argument n'est pas défini, la recherche se fait dans l'objet Locale directement.&lt;/li&gt;
&lt;li&gt;callback&amp;nbsp;: une méthode optionnelle que l'on souhaite invoquer une fois que l'opération est terminée.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Exemple complet&lt;/h3&gt;


&lt;p&gt;Voici un exemple simple des fonctionnalités décrites ci-dessus.&lt;/p&gt;


&lt;p&gt;A noter que tous les exemples de ce tutoriel se trouvent dans le repository SVN dans le répertoire AS3/trunk/bin/test/andromeda/i18n .&lt;/p&gt;


&lt;p&gt;Vous trouverez dans ce répertoire des exemples utilisant eden ou JSON avec les FLA pour Flash et les fichiers textes encodés en UTF8 (voir définition de ces fichiers plus haut).&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; andromeda.events.LocalizationEvent ;
&amp;nbsp;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; andromeda.i18n.EdenLocalizationLoader ;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; andromeda.i18n.Lang ;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; andromeda.i18n.Locale ;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; andromeda.i18n.Localization ;
&amp;nbsp;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; asgard.&lt;span style=&quot;color: #004993;&quot;&gt;text&lt;/span&gt;.CoreTextField ;  
&amp;nbsp;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.text&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;TextFormat&lt;/span&gt; ; 
&amp;nbsp;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; system.events.ActionEvent ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; field&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;CoreTextField = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; CoreTextField&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;myField&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
field.&lt;span style=&quot;color: #004993;&quot;&gt;defaultTextFormat&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;TextFormat&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;arial&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
field.&lt;span style=&quot;color: #004993;&quot;&gt;width&lt;/span&gt;  = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;300&lt;/span&gt; ;
field.&lt;span style=&quot;color: #004993;&quot;&gt;height&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;20&lt;/span&gt;  ;
&amp;nbsp;
field.&lt;span style=&quot;color: #004993;&quot;&gt;x&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;25&lt;/span&gt;  ;
field.&lt;span style=&quot;color: #004993;&quot;&gt;y&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;25&lt;/span&gt;  ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; debug&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Function&lt;/span&gt; = &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; e&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Event&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;------- &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; e.&lt;span style=&quot;color: #004993;&quot;&gt;type&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;change&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Function&lt;/span&gt; = &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; e&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;LocalizationEvent &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;target&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Localization = e.&lt;span style=&quot;color: #004993;&quot;&gt;target&lt;/span&gt; ;
    &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; current&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Lang        = e.current ;
    &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; locale&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Locale       = e.getLocale&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
    &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;# change current &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; current &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
    &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;# change locale  &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; locale  &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;each&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;in&lt;/span&gt; locale&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;  * &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;each&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot; : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; locale&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;each&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; prop&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;in&lt;/span&gt; locale&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;each&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;    * &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; prop &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot; : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; locale&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;each&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;prop&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
    &lt;span style=&quot;color: #009900;&quot;&gt;// map the CoreTextField instance with this id attribute &lt;/span&gt;
&amp;nbsp;
    Localization.getInstance&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;init&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; field , field.id &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
    &lt;span style=&quot;color: #009900;&quot;&gt;// field.id == &amp;quot;myField&amp;quot;, see this attribute in the localize_fr.eden file for example&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; localization&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Localization  = Localization.getInstance&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
localization.&lt;span style=&quot;color: #004993;&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; LocalizationEvent.&lt;span style=&quot;color: #004993;&quot;&gt;CHANGE&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;change&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;loader&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;EdenLocalizationLoader = localization.&lt;span style=&quot;color: #004993;&quot;&gt;loader&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;as&lt;/span&gt; EdenLocalizationLoader ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;loader&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; ActionEvent.START  , debug &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&lt;span style=&quot;color: #004993;&quot;&gt;loader&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; ActionEvent.FINISH , debug &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;loader&lt;/span&gt;.path = &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;locale/&amp;quot;&lt;/span&gt; ;
&amp;nbsp;
localization.current = Lang.FR ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;keyDown&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Function&lt;/span&gt; = &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; e&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;KeyboardEvent&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;code&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;int&lt;/span&gt; = e.&lt;span style=&quot;color: #004993;&quot;&gt;keyCode&lt;/span&gt; ;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;switch&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;code&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;case&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;Keyboard&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;UP&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            localization.current = Lang.EN ;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;break&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;case&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;Keyboard&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;DOWN&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            localization.current = &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;fr&amp;quot;&lt;/span&gt; ;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;break&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;stage&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;KeyboardEvent&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;KEY_DOWN&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;keyDown&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;Dans cet exemple j'utilise à peu prêt toutes les fonctionnalités décrites précédemment. A noter que pour le petit test, j'utilise la classe &lt;strong&gt;asgard.text.CoreTextField&lt;/strong&gt; qui est une superclasse de la classe &lt;strong&gt;flash.text.TextField&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;Cette classe implémente l'interface &lt;strong&gt;system.data.Identifiable&lt;/strong&gt; comme toutes les implémentations visuelles de &lt;strong&gt;ASGard&lt;/strong&gt; (CoreSprite, CoreMovieClip, CoreBitmap, etc.), ainsi chaque instance possède un identifiant unique &quot;&lt;strong&gt;id&lt;/strong&gt;&quot; dans l'application.&lt;/p&gt;


&lt;p&gt;Nous nous servons donc de cet identifiant dans les fichiers de configuration ou de localisation de l'application pour retrouver rapidement dans la structure objet de l'objet &lt;strong&gt;Locale&lt;/strong&gt; l'attribut correspondant à l'élément graphique voulu,  exemple&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;Localization.getInstance&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;init&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; field , field.id &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// field.id == &amp;quot;myField&amp;quot;, see this attribute in the localize_fr.eden file for example&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;4 - Initialisation du moteur de localisation avec des ressources de types &quot;i18n&quot;&lt;/p&gt;


&lt;p&gt;Les ressources de type &quot;i18n&quot; permettent de charger un ou plusieurs fichier de localisation (par défaut au format eden) qui contiennent des variables qui seront utilisées par la suite dans les définitions d'objet de la fabrique mais aussi directement dans l'application en ciblant un singleton de la classe Localization via la méthode statique Localization.getInstance().&lt;/p&gt;


&lt;p&gt;Regardons la signature minimale de l'objet générique qu'il est possible de définir dans l'attribut &quot;imports&quot; pour charger une ressource de type &quot;i18n&quot;&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; resource &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;fr&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;type&lt;/span&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;i18n&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Dans cet objet générique il est possible d'utiliser les attributs suivant&amp;nbsp;:&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Attributs obligatoires :&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;resource&amp;nbsp;: indique la référence de la langue que l'on souhaite charger (obligatoire), cette chaine de caractère est définie en fonction des langues disponibles dans l'application (fr, en, it, etc.)&lt;/li&gt;
&lt;li&gt;type&amp;nbsp;: indispensable pour indiquer au chargeur que la ressource est de type &quot;&lt;strong&gt;i18n&lt;/strong&gt;&quot;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Attributs optionnels :&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;path&lt;/strong&gt;&amp;nbsp;: indique le chemin du fichier à charger (exemple&amp;nbsp;: &lt;strong&gt;path:&quot;locale/&quot;&lt;/strong&gt; ).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;prefix&lt;/strong&gt;&amp;nbsp;: Indique le préfixe utilisé pour créer le nom du fichier externe (par défaut le préfixe est défini avec la valeur &quot;localize_&quot;)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;suffix&lt;/strong&gt;&amp;nbsp;: Représente le nom de l'extension utilisée pour charger le fichier de localisation, par défaut cette extension a pour valeur la chaine de caractère&amp;nbsp;: &lt;strong&gt;&quot;.eden&quot;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;verbose&lt;/strong&gt;&amp;nbsp;: Un booléean qui active le mode debug de la ressource pour énumérer son contenu une fois chargée dans les logs de l'applications.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;loader&lt;/strong&gt;&amp;nbsp;: Représente directement une référence vers une classe de type &lt;strong&gt;ILocalizationLoader&lt;/strong&gt; ou une chaine de caractère qui représente le nom complet d'une classe de type &lt;strong&gt;ILocalizationLoader&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A noter que l'attribut &quot;loader&quot; permet de remplacer la classe EdenLocalizationLoader utilisée par défaut par la ressource pour chager le fichier de configuration externe. Il sera donc possible en cas de besoin d'utiliser un autre type de chargeur de localisation (JSON, XML, etc...). Il est préférable d'être un utilisateur avancé du framework pour toucher à cet attribut.&lt;/p&gt;


&lt;p&gt;Les ressources de type &quot;&lt;strong&gt;i18n&lt;/strong&gt;&quot; permettent d'initialiser des objets de type &quot;&lt;strong&gt;andromeda.i18n.LocalResource&lt;/strong&gt;&quot; au niveau du chargeur de la fabrique &lt;strong&gt;IoC&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Exemple d'utilisation :&lt;/strong&gt;&lt;/p&gt;


&lt;p&gt;Le but de notre exemple est simple&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Créer un champ de texte dynamique et l'attacher sur la scène principale.&lt;/li&gt;
&lt;li&gt;Afficher dans le champ de texte un message localisé en français ou anglais.&lt;/li&gt;
&lt;li&gt;Avoir la possibilité de changer la langue de l'application à tout moment en appuyant sur une touche du clavier.&lt;/li&gt;
&lt;li&gt;Enregistrer un événement pour écouter le moteur de localisation de l'application et changer le message du champ de texte en fonction de la langue courante.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Commençons par créer 2 fichiers textes encodés en &lt;strong&gt;UTF8&lt;/strong&gt; &quot;&lt;strong&gt;locale/localize_fr.eden&lt;/strong&gt;&quot; et &quot;&lt;strong&gt;locale/localize_en.eden&lt;/strong&gt;&quot; permettant respectivement de définir le message que nous voudrons afficher dans le champ de texte dynamique.&lt;/p&gt;


&lt;p&gt;Contenu du fichier &quot;&lt;strong&gt;localize_fr.eden&lt;/strong&gt;&quot; (langue française, code &quot;&lt;strong&gt;fr&lt;/strong&gt;&quot;)&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;field =
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #004993;&quot;&gt;text&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;Bonjour le monde&amp;quot;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;&lt;/pre&gt;


&lt;p&gt;Contenu du fichier &quot;&lt;strong&gt;localize_en.eden&lt;/strong&gt;&quot; (langue anglaise, code &quot;&lt;strong&gt;en&lt;/strong&gt;&quot;)&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;field =
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #004993;&quot;&gt;text&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;Hello world&amp;quot;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;&lt;/pre&gt;


&lt;p&gt;&lt;strong&gt;Note :&lt;/strong&gt; Nous pouvons créer autant de fichier de configuration que de langues disponibles dans l'application, il suffira pour chaque langue de standardiser le nom des fichiers textes avec la nomenclature désirée, ici &quot;localize_xx.eden&quot; avec xx le code de la langue définie dans le fichier de configuration au format eden.&lt;/p&gt;


&lt;p&gt;Nous pouvons maintenant créer un fichier externe de configuration et de définition de la &lt;strong&gt;fabrique IoC&lt;/strong&gt; de notre application&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;imports =
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; resource &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;fr&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;i18n&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;prefix&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;localize_&amp;quot;&lt;/span&gt; , path    &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;locale/&amp;quot;&lt;/span&gt; , suffix &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;.eden&amp;quot;&lt;/span&gt; , verbose &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; ,
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; resource &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;en&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;i18n&amp;quot;&lt;/span&gt; , path   &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;locale/&amp;quot;&lt;/span&gt;   , verbose &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt; ;
&amp;nbsp;
objects =
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        id         &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;localization&amp;quot;&lt;/span&gt; ,
        &lt;span style=&quot;color: #004993;&quot;&gt;type&lt;/span&gt;       &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;andromeda.i18n.Localization&amp;quot;&lt;/span&gt; ,
        singleton  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ,
        lazyInit   &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ,
        staticFactoryMethod &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #004993;&quot;&gt;type&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;andromeda.i18n.Localization&amp;quot;&lt;/span&gt; ,
            &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;getInstance&amp;quot;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    ,
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        id         &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;field&amp;quot;&lt;/span&gt; ,
        &lt;span style=&quot;color: #004993;&quot;&gt;type&lt;/span&gt;       &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;flash.text.TextField&amp;quot;&lt;/span&gt; ,
        singleton  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ,
        lazyInit   &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ,
        properties &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;autoSize&amp;quot;&lt;/span&gt;          , &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;left&amp;quot;&lt;/span&gt;                                           &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; ,
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;defaultTextFormat&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.text&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;TextFormat&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;Arial&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;14&lt;/span&gt;, 0xEEED2B&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; ,
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;text&amp;quot;&lt;/span&gt;              , locale &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;field.text&amp;quot;&lt;/span&gt;                                     &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; ,
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;x&amp;quot;&lt;/span&gt;                 , &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;25&lt;/span&gt;                                               &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; ,
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;y&amp;quot;&lt;/span&gt;                 , &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;25&lt;/span&gt;                                               &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    ,
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        id               &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;application&amp;quot;&lt;/span&gt; ,
        &lt;span style=&quot;color: #004993;&quot;&gt;type&lt;/span&gt;             &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;examples.Application&amp;quot;&lt;/span&gt; ,
        factoryReference &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;#root&amp;quot;&lt;/span&gt; ,
        singleton        &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ,
        properties       &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;
            &lt;span style=&quot;color: #009900;&quot;&gt;// dependencies&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;field&amp;quot;&lt;/span&gt;        , ref &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;field&amp;quot;&lt;/span&gt;        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; ,
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;localization&amp;quot;&lt;/span&gt; , ref &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;localization&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; ,
&amp;nbsp;
            &lt;span style=&quot;color: #009900;&quot;&gt;// childs&lt;/span&gt;
             &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;addChild&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;arguments&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; ref &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;field&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
        ,
        listeners &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; dispatcher &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;localization&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;type&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;change&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;method&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;changeLocalization&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Nous définissons tout d'abord deux ressources de type &lt;strong&gt;i18n&lt;/strong&gt; pour charger directement en mémoire les configurations localisées pour les langues &quot;&lt;strong&gt;en&lt;/strong&gt;&quot; et &quot;&lt;strong&gt;fr&lt;/strong&gt;&quot;.&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;imports =
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; resource &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;fr&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;i18n&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;prefix&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;localize_&amp;quot;&lt;/span&gt; , path    &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;locale/&amp;quot;&lt;/span&gt; , suffix &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;.eden&amp;quot;&lt;/span&gt; , verbose &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; ,
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; resource &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;en&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;i18n&amp;quot;&lt;/span&gt; , path   &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;locale/&amp;quot;&lt;/span&gt;   , verbose &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;Il ne faut pas oublier que le chargement des ressources se fait de bas en haut dans l'objet &quot;imports&quot;. La dernière langue chargée (ici &quot;fr&quot;) sera donc la langue courante par défaut de l'application une fois la fabrique IoC initialisée.&lt;/p&gt;


&lt;p&gt;En utilisant un chargeur de type &lt;strong&gt;ECMAObjectLoader&lt;/strong&gt; par défaut c'est le singleton de la classe andromeda.i18n.Localization défini avec la méthode statique &lt;strong&gt;Localization.getInstance()&lt;/strong&gt; qui est initialisé. Il est bien entendu tout à fait possible de modifier l'objet de localisation utilisé dans le loader de la fabrique.&lt;/p&gt;


&lt;p&gt;Nous avons vu que la fabrique &lt;strong&gt;IoC&lt;/strong&gt; contient par défaut une référence magique &lt;strong&gt;#locale&lt;/strong&gt; mais aussi un attribut dans les définitions d'objet &quot;&lt;strong&gt;locale&lt;/strong&gt;&quot; qui permet de cibler à tout moment l'objet courant de type &lt;strong&gt;andromeda.i18n.Locale&lt;/strong&gt; de la localisation si une langue courante est définie et initialisée avec un fichier externe de configuration.&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    id         &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;field&amp;quot;&lt;/span&gt; ,
    &lt;span style=&quot;color: #004993;&quot;&gt;type&lt;/span&gt;       &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;flash.text.TextField&amp;quot;&lt;/span&gt; ,
    singleton  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ,
    lazyInit   &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ,
    properties &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;autoSize&amp;quot;&lt;/span&gt;          , &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;left&amp;quot;&lt;/span&gt;                                           &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; ,
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;defaultTextFormat&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.text&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;TextFormat&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;Arial&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;14&lt;/span&gt;, 0xEEED2B&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; ,
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;text&amp;quot;&lt;/span&gt;              , locale &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;field.text&amp;quot;&lt;/span&gt;                                     &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; ,
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;x&amp;quot;&lt;/span&gt;                 , &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;25&lt;/span&gt;                                               &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; ,
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;y&amp;quot;&lt;/span&gt;                 , &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;25&lt;/span&gt;                                               &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Nous voyons dans la définition d'objet précédente l'utilisation très simple de l'attribut &quot;locale&quot; qui permet de récupérer dans la localisation courante la valeur de la chaine de caractère field.text défini dans nos fichiers eden localisés au début de cet exemple.&lt;/p&gt;


&lt;p&gt;Nous pouvons donc définir facilement la valeur d'un champ de texte ou l'url d'une image ou d'un swf externe en ciblant l'objet de localisation courant. Nous trouvons donc ici une réponse à la problématique d'injection de dépendance entre un objet défini dans l'application et un objet ou une valeur définie dans la localisation courante.&lt;/p&gt;


&lt;p&gt;A noter que le context &lt;strong&gt;IoC&lt;/strong&gt; externe ci-dessus est chargé avec le code &lt;strong&gt;ActionScript&lt;/strong&gt; suivant&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt; examples
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; andromeda.events.LocalizationEvent;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; andromeda.i18n.Lang;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; andromeda.i18n.Localization;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; asgard.net.ECMAObjectLoader;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.display&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;MovieClip&lt;/span&gt;;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.events&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;KeyboardEvent&lt;/span&gt;;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.text&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;TextField&lt;/span&gt;;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.ui&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;Keyboard&lt;/span&gt;;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;class&lt;/span&gt; Application extends &lt;span style=&quot;color: #004993;&quot;&gt;MovieClip&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; Application&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;loader&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;ECMAObjectLoader = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; ECMAObjectLoader&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;application_i18n_resource.eden&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;context/&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
                &lt;span style=&quot;color: #004993;&quot;&gt;loader&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;root&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;this&lt;/span&gt; ;
&amp;nbsp;
                &lt;span style=&quot;color: #004993;&quot;&gt;loader&lt;/span&gt;.run&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
                &lt;span style=&quot;color: #004993;&quot;&gt;stage&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;KeyboardEvent&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;KEY_DOWN&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;keyDown&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
            &lt;span style=&quot;color: #3f5fbf;&quot;&gt;/**
             * The TextField reference.
             */&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; field&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;TextField&lt;/span&gt; ;
&amp;nbsp;
            &lt;span style=&quot;color: #3f5fbf;&quot;&gt;/**
             * The Localization reference of the application to change the current lang.
             */&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; localization&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Localization ;
&amp;nbsp;
            &lt;span style=&quot;color: #3f5fbf;&quot;&gt;/**
             * Invoked when the localization of the application is changed.
             */&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; changeLocalization&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; e&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;LocalizationEvent &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; e &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
                &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; field &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;!&lt;/span&gt;= &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;null&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
                &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                    field.&lt;span style=&quot;color: #004993;&quot;&gt;text&lt;/span&gt; = e.getLocale&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;field.text&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
                &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
            &lt;span style=&quot;color: #3f5fbf;&quot;&gt;/**
             * Invoked to change the current lang with the Keyboard.UP and Keyboard.DOWN keys.
             */&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;keyDown&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; e&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;KeyboardEvent&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;code&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;uint&lt;/span&gt; = e.&lt;span style=&quot;color: #004993;&quot;&gt;keyCode&lt;/span&gt; ;
                &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;switch&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;code&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
                &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;case&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;Keyboard&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;UP&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
                    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                        localization.current = Lang.EN ;
                        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;break&lt;/span&gt; ;
                    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
                    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;case&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;Keyboard&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;DOWN&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
                    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                        localization.current = &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;fr&amp;quot;&lt;/span&gt; ;
                        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;break&lt;/span&gt; ;
                    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
                &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Nous avons donc défini la classe &quot;&lt;strong&gt;main&lt;/strong&gt;&quot; de notre application avec la classe &lt;strong&gt;examples.Application&lt;/strong&gt; qui hérite de la classe &lt;strong&gt;flash.display.MovieClip&lt;/strong&gt;.&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    id               &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;application&amp;quot;&lt;/span&gt; ,
    &lt;span style=&quot;color: #004993;&quot;&gt;type&lt;/span&gt;             &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;examples.Application&amp;quot;&lt;/span&gt; ,
    factoryReference &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;#root&amp;quot;&lt;/span&gt; ,
    singleton        &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ,
    properties       &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;
        &lt;span style=&quot;color: #009900;&quot;&gt;// dependencies&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;field&amp;quot;&lt;/span&gt;        , ref &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;field&amp;quot;&lt;/span&gt;        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; ,
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;localization&amp;quot;&lt;/span&gt; , ref &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;localization&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; ,
&amp;nbsp;
        &lt;span style=&quot;color: #009900;&quot;&gt;// childs&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;addChild&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;arguments&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; ref &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;field&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
    ,
    listeners &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; dispatcher &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;localization&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;type&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;change&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;method&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;changeLocalization&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Nous noterons donc 2 dépendances sur cette &lt;strong&gt;définition d'objet&lt;/strong&gt; avec les propriétés&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;field&lt;/strong&gt;&amp;nbsp;: permet de créer une référence vers le champ de texte &quot;&lt;strong&gt;field&lt;/strong&gt;&quot; défini dans la fabrique &lt;strong&gt;IoC&lt;/strong&gt; avec la &lt;strong&gt;définition d'objet&lt;/strong&gt; du même nom.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;localization&lt;/strong&gt;&amp;nbsp;: permet de créer une référence vers la localisation de l'application et ainsi de pouvoir à tout moment changer la langue courante.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;La localisation de l'application peut être définie dans le conteneur &lt;strong&gt;IoC&lt;/strong&gt;  et référencée très simplement en utilisant une &lt;strong&gt;définition d'objet&lt;/strong&gt; utilisant une stratégie de type &lt;strong&gt;staticFactoryMethod&lt;/strong&gt;&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    id         &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;localization&amp;quot;&lt;/span&gt; ,
    &lt;span style=&quot;color: #004993;&quot;&gt;type&lt;/span&gt;       &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;andromeda.i18n.Localization&amp;quot;&lt;/span&gt; ,
    singleton  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ,
    lazyInit   &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ,
    staticFactoryMethod &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #004993;&quot;&gt;type&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;andromeda.i18n.Localization&amp;quot;&lt;/span&gt; ,
        &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;getInstance&amp;quot;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;A noter que nous utilisons un attribut &quot;listeners&quot; pour écouter la localisation de l'application et être notifié à tout moment du changement de langue courante avec la méthode changeLocalization définie dans la classe examples.Application.&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;listeners &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; dispatcher &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;localization&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;type&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;change&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;method&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;changeLocalization&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;/pre&gt;


&lt;h3&gt;Notes&lt;/h3&gt;


&lt;p&gt;Voici donc après quelques mois de retard cette nouvelle partie du chapitre sur les ressources externes de type &quot;&lt;strong&gt;i18n&lt;/strong&gt;&quot; dans le moteur de ressources du chargeur de context IoC de &lt;strong&gt;VEGAS&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;Pour cet article je ne vais pas dupliquer les liens vers les articles se trouvant sur mon blog mais je préfère vous rediriger vers &lt;strong&gt;Google Documents&lt;/strong&gt; et vers les pages de mon &lt;strong&gt;e-book&lt;/strong&gt; (toujours en pleine évolution) qui regroupe l'ensemble des chapitres concernant le design pattern d'injection de dépendance et de son utilisation avec &lt;strong&gt;VEGAS&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://docs.google.com/Doc?id=dfd9s8cg_15g3ct8rfb&quot;&gt;A - Design Pattern d'Inversion de Contrôle - Généralités&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://docs.google.com/Doc?id=dfd9s8cg_27c5s2pwkd&quot;&gt;B - Les définitions d'objets&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://docs.google.com/Doc?id=dfd9s8cg_26dzzj8vcv&quot;&gt;C - Configuration d'une fabrique IoC&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://docs.google.com/View?id=dfd9s8cg_29cdqrshrj&quot;&gt;D - Chargement de ressources externes&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A noter qu'il est préférable de consulter les articles sur &lt;strong&gt;google code&lt;/strong&gt; car ils sont sans arrêt mis à jour en cas de problème (faute d'orthographe, changement dans le code source des exemples ou dans l'API du framework).&lt;/p&gt;


&lt;p&gt;Pour toute question comme toujours sur &lt;strong&gt;VEGAS&lt;/strong&gt; je vous conseille de vous inscrire sur le &lt;strong&gt;Google Groups&lt;/strong&gt; du projet&amp;nbsp;: &lt;a href=&quot;http://groups.google.com/group/vegasos&quot;&gt;http://groups.google.com/group/vegasos&lt;/a&gt;&lt;/p&gt;


&lt;p&gt;En cas de soucis dans cette documentation ou dans le code source de VEGAS je vous conseille d'utiliser les &quot;issues&quot; des différents projets et différentes extensions du framework&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;VEGAS&amp;nbsp;: &lt;a href=&quot;http://code.google.com/p/vegas/issues/list&quot;&gt;http://code.google.com/p/vegas/issues/list&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;AndromedAS (IoC)&amp;nbsp;: &lt;a href=&quot;http://code.google.com/p/andromed-as/issues/list&quot;&gt;http://code.google.com/p/andromed-as/issues/list&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Maashaack&amp;nbsp;: &lt;a href=&quot;http://code.google.com/p/maashaack/issues/list&quot;&gt;http://code.google.com/p/maashaack/issues/list&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A suivre avec un prochain article sur les ressources de type &quot;&lt;strong&gt;shader&lt;/strong&gt;&quot; et l'utilisation des effets &lt;strong&gt;PixelBender&lt;/strong&gt; dans les ressources du moteur &lt;strong&gt;IoC&lt;/strong&gt; de VEGAS &lt;img src=&quot;/blog/themes/default/smilies/smile.png&quot; alt=&quot;:)&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;</description>
    
    
    
          <comments>http://www.ekameleon.net/blog/index.php?post/2009/08/27/D-Chargement-de-ressources-externes-Partie-5-localization#comment-form</comments>
      <wfw:comment>http://www.ekameleon.net/blog/index.php?post/2009/08/27/D-Chargement-de-ressources-externes-Partie-5-localization#comment-form</wfw:comment>
      <wfw:commentRss>http://www.ekameleon.net/blog/index.php?feed/rss2/comments/120</wfw:commentRss>
      </item>
    
  <item>
    <title>Problème d'utilisation du type * dans les propriétés virtuelles dans Flash CS3 et CS4 en mode &quot;avertissement&quot;</title>
    <link>http://www.ekameleon.net/blog/index.php?post/2009/07/31/Probleme-dutilisation-du-type-dans-les-proprietes-virtuelles-dans-Flash-CS3-et-CS4-en-mode-avertissement</link>
    <guid isPermaLink="false">urn:md5:42892c5eb795aa603cd4e97611699a16</guid>
    <pubDate>Fri, 31 Jul 2009 22:00:00 +0200</pubDate>
    <dc:creator>eKameleon</dc:creator>
        <category>AS3 - Flex - Air</category>
            
    <description>&lt;p&gt;Flash CS3 et Flash CS4 proposent par défaut d'améliorer le débogage &lt;strong&gt;AS3&lt;/strong&gt; avec un &quot;&lt;strong&gt;Mode avertissement&lt;/strong&gt;&quot;. Même si à la base ce mode doit aider le &lt;strong&gt;flasheur&lt;/strong&gt; dans son développement, j'avoue que personnellement je considère les &quot;&lt;strong&gt;Warning&lt;/strong&gt;&quot; notifiés dans le panneau de sortie de &lt;strong&gt;Flash&lt;/strong&gt; pas forcément très bien venus la plupart du temps.&lt;/p&gt;


&lt;p&gt;On pourra noter d'ailleurs un bon petit feedback sur le sujet sur le site de &lt;strong&gt;ByteArray.org&lt;/strong&gt;&amp;nbsp;: &lt;a href=&quot;http://www.bytearray.org/?p=931&quot;&gt;Warnings mode, the dangerous friend&lt;/a&gt;&lt;/p&gt;


&lt;p&gt;Je vais donc moi aussi vivement vous conseiller de désactiver dans vos paramètres de publication le &quot;&lt;strong&gt;Mode avertissement&lt;/strong&gt;&quot; de votre document.&lt;/p&gt;


&lt;p&gt;D'ailleurs il suffit de coder dans &lt;a href=&quot;http://fdt.powerflasher.com/&quot;&gt;FDT&lt;/a&gt; quotidiennement et de compiler normalement avec le compiler &lt;a href=&quot;http://labs.adobe.com/wiki/index.php/Flex_Compiler_Shell&quot;&gt;FCSH&lt;/a&gt; et de revenir de temps en temps dans Flash pour se rendre compte que ce retour est parfois bien 'étonnant' &lt;img src=&quot;/blog/themes/default/smilies/smile.png&quot; alt=&quot;:)&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;


&lt;p&gt;Voyons un exemple simple de classe pour isoler un warning qui pour moi ne peut vraiment pas être considéré comme une erreur&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.display&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;Sprite&lt;/span&gt; ;
&amp;nbsp;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;class&lt;/span&gt; Main extends &lt;span style=&quot;color: #004993;&quot;&gt;Sprite&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; Main&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                _func = &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
                &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                    &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;hello world&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
                &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;           
                function1&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
                function2&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;get&lt;/span&gt; function1&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Function&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;return&lt;/span&gt; _func ;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;get&lt;/span&gt; function2&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:*&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;return&lt;/span&gt; _func ;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; _func&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Function&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Il suffit d'ajouter la classe ci-dessus dans le panneau de propriété d'un nouveau document &lt;strong&gt;AS3&lt;/strong&gt; et de lancer la compilation.&lt;/p&gt;


&lt;p&gt;Résultat nous obtenons dans le panneau de sortie les deux invocations de la fonction (en gros nous attendions ce résultat) mais très étrangement une notification de type &quot;&lt;strong&gt;warning&lt;/strong&gt;&quot; dans le panneau &quot;&lt;strong&gt;Erreurs de compilations&lt;/strong&gt;&quot; de Flash&amp;nbsp;: &lt;strong&gt;&quot;Warning: 3553: Valeur de fonction utilisée alors qu'une valeur de type * est attendue.  Il semble que des parenthèses () sont absentes après cette référence à une fonction.&quot;&lt;/strong&gt;&lt;/p&gt;    &lt;p&gt;En gros dans la propriété virtuelle &quot;&lt;strong&gt;function2&lt;/strong&gt;&quot; Flash considère qu'il n'est pas possible de renvoyer un objet de type &lt;strong&gt;Function&lt;/strong&gt; dans une fonction qui doit renvoyer un objet de type &lt;strong&gt;*&lt;/strong&gt; ???  Alors que le type &lt;strong&gt;*&lt;/strong&gt; reste un type dynamique qui permet de faire sortir n'importe quel type d'objet&amp;nbsp;? Très étrange donc ce genre d'alerte&amp;nbsp;?&lt;/p&gt;


&lt;p&gt;Il est vrai que le code ci-dessus n'est pas vraiment très &quot;&lt;strong&gt;standard&lt;/strong&gt;&quot; mais imaginons que dans une classe nous ayons besoin de stocker en mémoire une fonction pour le réutiliser plus tard.. si si&amp;nbsp;! cela peut arriver&amp;nbsp;! Par exemple avec  une adaptation de la classe &lt;strong&gt;Tween&lt;/strong&gt; bien connue de tous et la nécessité d'utiliser une fonction de &quot;&lt;strong&gt;easing&lt;/strong&gt;&quot; pour changer l'effet appliqué sur l'interpolation.&lt;/p&gt;


&lt;p&gt;Imaginons donc un bout du code de cette classe &lt;strong&gt;Tween&lt;/strong&gt; avec le script ci-dessous&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.events&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;EventDispatcher&lt;/span&gt; ;
&amp;nbsp;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;class&lt;/span&gt; Tween extends &lt;span style=&quot;color: #004993;&quot;&gt;EventDispatcher&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; Tween&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                &lt;span style=&quot;color: #009900;&quot;&gt;// code&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;get&lt;/span&gt; easing&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:*&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;return&lt;/span&gt; _easing ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;set&lt;/span&gt; easing&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; easing&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:*&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; easing &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;is&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;Function&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                _easing = easing &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;Function&lt;/span&gt; ;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
                &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; easing &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;is&lt;/span&gt; Easing &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                _easing = &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;easing &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;as&lt;/span&gt; Easing&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.ease ;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;else&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                _easing = &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;t&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Number&lt;/span&gt;, &lt;span style=&quot;color: #004993;&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Number&lt;/span&gt;, &lt;span style=&quot;color: #004993;&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Number&lt;/span&gt;, &lt;span style=&quot;color: #004993;&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Number&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Number&lt;/span&gt;
                &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;c&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;*&lt;/span&gt; t &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;d&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;b&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// linear easing&lt;/span&gt;
                &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; _easing&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Function&lt;/span&gt; ;
&amp;nbsp;
        &lt;span style=&quot;color: #009900;&quot;&gt;// ... reste du code de la classe&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Avec &lt;strong&gt;Easing&lt;/strong&gt; une interface simple permettant d'implémenter des classes simples pour chaque type de transition&amp;nbsp;: &lt;strong&gt;Bounce&lt;/strong&gt;, &lt;strong&gt;Back&lt;/strong&gt;, etc. Cette interface doit juste définir une méthode &lt;strong&gt;ease&lt;/strong&gt;() personnalisable.&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    interface Easing
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; ease &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; t&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Number&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Number&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Number&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Number&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Number&lt;/span&gt; ;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Dans la classe &lt;strong&gt;Tween&lt;/strong&gt; définie plus haut, j'ai envie de définir une propriété virtuelle r/w &quot;&lt;strong&gt;easing&lt;/strong&gt;&quot; qui peut prendre des objets de type &lt;strong&gt;Easing&lt;/strong&gt; mais aussi des objets de type &lt;strong&gt;Function&lt;/strong&gt; simples... Je suis obligé de typer les 2 fonctions &lt;strong&gt;get&lt;/strong&gt; et &lt;strong&gt;set&lt;/strong&gt; de ma propriété virtuelle avec le type &lt;strong&gt;*&lt;/strong&gt; (impossible de typer différemment les 2 fonctions).&lt;/p&gt;


&lt;p&gt;Dans &lt;strong&gt;Flash&lt;/strong&gt; le problème du &quot;&lt;strong&gt;warning&lt;/strong&gt;&quot; indésirable apparait sur cette classe au niveau de la fonction &quot;&lt;strong&gt;get&lt;/strong&gt;&quot; de la propriété virtuelle &quot;&lt;strong&gt;easing&lt;/strong&gt;&quot;. Il est clair que le code ci-dessus même si il est &quot;discutable&quot; n'est pas mauvais en soit et que dans tous les cas l'application malgré ce &lt;strong&gt;warning&lt;/strong&gt; l'application fonctionne sans soucis.&lt;/p&gt;


&lt;p&gt;A noter que pour éviter ce &lt;strong&gt;warning&lt;/strong&gt; dans &lt;strong&gt;Flash&lt;/strong&gt; sur une fonction qui retourne un objet de type &lt;strong&gt;*&lt;/strong&gt;, il suffit de forcer le type de l'objet de retour de la fonction avec le type &quot;&lt;strong&gt;Object&lt;/strong&gt;&quot;&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;get&lt;/span&gt; easing&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:*&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;return&lt;/span&gt; _easing &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;Object&lt;/span&gt; ;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Plus de message d'alerte après ce petit &lt;strong&gt;hack&lt;/strong&gt;, mais cela reste tout de même à mon sens une solution tirée par les cheveux.&lt;/p&gt;


&lt;p&gt;Je code très peu dans l'environnement auteur de &lt;strong&gt;Flash&lt;/strong&gt; en privilégiant son utilisation uniquement pour la création des assets graphiques et des animations et je préfère largement ensuite charger mes swfs d'assets dynamiquement dans mon application principale codée dans &lt;strong&gt;FDT&lt;/strong&gt; et ensuite il suffit de prendre la main sur les éléments graphiques via leurs simple noms d'occurrences.&lt;/p&gt;


&lt;p&gt;Ce process de travaille laisse beaucoup plus de souplesse au graphiste, qui n'a plus d'excuse pour trouver l'&lt;strong&gt;ActionScript&lt;/strong&gt; &quot;compliqué&quot; vu que le seul code qui lui ai demandé c'est un &lt;strong&gt;stop()&lt;/strong&gt; de temps en temps sur une image clé, quelques étiquettes sur des images clés et surtout d'indiquer les noms d'occurrences sur les clips importants de l'application.&lt;/p&gt;


&lt;p&gt;Bon finalement plus de &quot;&lt;strong&gt;peur&lt;/strong&gt;&quot; que de mal .. mais franchement ils ont à mon sens simplifié à mort le code dans &lt;strong&gt;Flash CS3/4&lt;/strong&gt; en permettant au développeur débutant de coder sans se prendre trop la tête (pas besoin d'importer les classes natives, etc.) mais avec ce genre de &quot;&lt;strong&gt;warning&lt;/strong&gt;&quot; sans queue ni tête.. pas facile pour un débutant de comprendre les rouages de l'&lt;strong&gt;ActionScript&lt;/strong&gt; vous ne pensez pas&amp;nbsp;?&lt;/p&gt;</description>
    
    
    
          <comments>http://www.ekameleon.net/blog/index.php?post/2009/07/31/Probleme-dutilisation-du-type-dans-les-proprietes-virtuelles-dans-Flash-CS3-et-CS4-en-mode-avertissement#comment-form</comments>
      <wfw:comment>http://www.ekameleon.net/blog/index.php?post/2009/07/31/Probleme-dutilisation-du-type-dans-les-proprietes-virtuelles-dans-Flash-CS3-et-CS4-en-mode-avertissement#comment-form</wfw:comment>
      <wfw:commentRss>http://www.ekameleon.net/blog/index.php?feed/rss2/comments/119</wfw:commentRss>
      </item>
    
  <item>
    <title>AS3 - prototype et overriding</title>
    <link>http://www.ekameleon.net/blog/index.php?post/2009/06/05/AS3-prototype-et-overriding</link>
    <guid isPermaLink="false">urn:md5:f7c84bf19c6db9e914cf2b402af76029</guid>
    <pubDate>Fri, 05 Jun 2009 20:30:00 +0200</pubDate>
    <dc:creator>eKameleon</dc:creator>
        <category>AS3 - Flex - Air</category>
        <category>as3</category><category>ecmascript</category><category>inherit</category><category>override</category><category>prototype</category>    
    <description>&lt;p&gt;En &lt;strong&gt;ActionScript 3&lt;/strong&gt; beaucoup de développeurs ignorent ou oublient l'existence de l'objet &lt;strong&gt;prototype&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;L'objet &lt;strong&gt;prototype&lt;/strong&gt; reste un élément incontournable du langage et même si en &lt;strong&gt;AS3 Adobe&lt;/strong&gt; a fait évoluer le concept pour optimiser les capacités de nos classes via une implémentation basée sur les &quot;&lt;strong&gt;traits&lt;/strong&gt;&quot; il ne faut jamais oublier que l'&lt;strong&gt;ActionScript&lt;/strong&gt; est basé sur les normes &lt;strong&gt;ECMAScript&lt;/strong&gt; est reste avant tout un langage &quot;&lt;a href=&quot;http://en.wikipedia.org/wiki/Prototype-based_programming&quot;&gt;Prototype Based&lt;/a&gt;&quot;.&lt;/p&gt;


&lt;p&gt;Il est donc toujours possible d'utiliser à tout moment une objet &lt;strong&gt;prototype&lt;/strong&gt; pour déclarer des méthodes sur une classe et profiter du dynamisme de ce standard.&lt;/p&gt;


&lt;p&gt;En &lt;strong&gt;AS3&lt;/strong&gt; nous avons donc 2 manières pour créer des classes et implémenter leurs méthodes et propriétés avec des &lt;strong&gt;traits&lt;/strong&gt; ou/et des &lt;strong&gt;prototypes&lt;/strong&gt;.&lt;/p&gt;


&lt;h2&gt;Les traits&lt;/h2&gt;


&lt;p&gt;Toutes les propriétés définies dans les &lt;strong&gt;namespaces&lt;/strong&gt; &lt;em&gt;public&lt;/em&gt;, &lt;em&gt;private&lt;/em&gt;, &lt;em&gt;protected&lt;/em&gt;, &lt;em&gt;internal&lt;/em&gt; ou &lt;em&gt;custom&lt;/em&gt; dans une classe sont déclarées dans un &lt;strong&gt;trait&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;Les &lt;strong&gt;traits&lt;/strong&gt; sont des objets implémentés par &lt;strong&gt;Adobe&lt;/strong&gt; pour augmenter les performances des classes dans l'&lt;strong&gt;AVM2&lt;/strong&gt; (virtual machine) du &lt;strong&gt;FlashPlayer&lt;/strong&gt; et pour diminuer le temps utilisé pour appeler les propriétés d'un objet par rapport à l'utilisation classique basée sur une chaine de &lt;strong&gt;prototype&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;A la base les traits permettent de copier les méthodes d'une &lt;strong&gt;super-classe&lt;/strong&gt; vers sa classe enfant (de façon très optimisée) pour que l'appel de ces méthodes par la suite soit beaucoup plus rapide.&lt;/p&gt;


&lt;p&gt;Les traits ne sont pas directement accessibles au niveau du code AS3 et fonctionnent en tache de fond dans nos applications. Dans la documentation &lt;strong&gt;AS3&lt;/strong&gt; nous pouvons lire un bon article sur le sujet dans la documentation &lt;strong&gt;AS3&lt;/strong&gt; officielle &lt;a href=&quot;http://livedocs.adobe.com/flash/9.0/main/00000069.html#wp133609&quot;&gt;The traits object&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;Il faut tout de même remarquer la note importante dans cet article qui indique que cette implémentation n'est pas garantie et peut changer ou même disparaitre dans les versions futures de l'&lt;strong&gt;ActionScript&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;Nous pouvons tout de même rester tranquille à ce niveau là, l'&lt;strong&gt;AS3&lt;/strong&gt; est bien implémenté maintenant et il n'est pas prêt de disparaitre et dans tous les cas &lt;strong&gt;Adobe&lt;/strong&gt; s'efforce toujours de garder une forte compatibilité d'un &lt;strong&gt;FlashPlayer&lt;/strong&gt; à un autre.&lt;/p&gt;


&lt;p&gt;Les &lt;strong&gt;traits&lt;/strong&gt; sont donc très puissants mais en contre-partie limitent grandement certains comportements &lt;strong&gt;ECMAScript&lt;/strong&gt; liés au dynamisme du langage.&lt;/p&gt;


&lt;p&gt;En effet si l'on prend le temps de regarder de plus prêt l'implémentation des classes en &lt;strong&gt;AS3&lt;/strong&gt; certaines spécificités qui faisaient la force du langage &lt;strong&gt;ActionScript&lt;/strong&gt; sont bridées comme par exemple la manipulation du scope des méthodes déclarées dans une classe basée sur les traits ou le fait qu'il est impossible de cibler la fonction constructeur d'une classe et donc il est impossible d'appliquer un &lt;strong&gt;apply()&lt;/strong&gt; ou un &lt;strong&gt;call()&lt;/strong&gt; dessus, etc.&lt;/p&gt;


&lt;h2&gt;Les prototypes&lt;/h2&gt;


&lt;p&gt;L'&lt;strong&gt;ActionScript&lt;/strong&gt; depuis sa première version basée sur le standard &lt;strong&gt;ECMAScript&lt;/strong&gt; (à partir de Flash 5) se base sur la norme &lt;a href=&quot;http://www.ecma-international.org/publications/standards/Ecma-262.htm&quot;&gt;ECMAScript 262 edition 3&lt;/a&gt; et donc utilise des &lt;strong&gt;prototypes&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;Chaque classe &lt;strong&gt;ActionScript&lt;/strong&gt; possède un objet appelé &quot;&lt;strong&gt;prototype&lt;/strong&gt;&quot;, cette référence est un simple objet générique (donc dynamique) dans lequel il est possible de stoker des méthodes et des attributs qui seront communs à toutes les instances d'une même classe.&lt;/p&gt;    &lt;p&gt;En &lt;strong&gt;AS1&lt;/strong&gt; et &lt;strong&gt;AS2&lt;/strong&gt; (mais aussi en &lt;strong&gt;Javascript&lt;/strong&gt;) les classes ne sont pas définies comme les classes en &lt;strong&gt;AS3&lt;/strong&gt;, Il n'existe pas dans la norme &lt;strong&gt;ECMA 262&lt;/strong&gt; d'objets de type &quot;&lt;strong&gt;Class&lt;/strong&gt;&quot;. A la place la norme prévoit une solution de remplacement très simple en basant les classes sur des fonctions constructeurs, c'est à dire des objets de type &lt;strong&gt;Function&lt;/strong&gt;, exemple&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; MyClass&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Function&lt;/span&gt; = &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;
&amp;nbsp;
MyClass.&lt;span style=&quot;color: #004993;&quot;&gt;prototype&lt;/span&gt;.myMethod = &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;hello world&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;Dans l'exemple ci-dessus, nous avons déclaré une fonction constructeur &quot;&lt;strong&gt;MyClass&lt;/strong&gt;&quot;, et il sera possible d'utiliser à tout moment le mot clé &quot;&lt;strong&gt;new&lt;/strong&gt;&quot; pour instancier cette classe&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; instance&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:*&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; MyClass&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
instance.myMethod&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// hello world&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;L'idée d'utiliser une fonction comme classe est très logique finalement vu que dans 99% des cas nous déclarons nos classes avec une fonction constructeur qui aura le même nom que la classe. Alors pourquoi finalement ne pas fusionner la classe et sa fonction constructeur en un seul et même objet&amp;nbsp;?&lt;/p&gt;


&lt;p&gt;Dans des langages dynamiques utilisés pour créer des applications légères et rapides (adaptées au web) cette implémentation semble parfaitement adaptée.&lt;/p&gt;


&lt;p&gt;Il est clair que malgré tout cette implémentation dynamique possède ses bons côtés mais également ses limites. &lt;strong&gt;Adobe&lt;/strong&gt; a donc essayé en &lt;strong&gt;AS3&lt;/strong&gt; de garder cette fonctionnalité et d'en ajouter une plus performante en parallèle (utilisée par défaut en mode strict lors de la compilation).&lt;/p&gt;


&lt;p&gt;Vous remarquerez que les 2 exemples ci-dessus sont écris en &lt;strong&gt;AS3&lt;/strong&gt;, tout simplement pour vous montrer que le prototype en &lt;strong&gt;AS3&lt;/strong&gt; n'est pas mort et qu'il est donc toujours possible de déclarer des classes et des objets basés sur lui.&lt;/p&gt;


&lt;p&gt;J'utilise le type &lt;strong&gt;*&lt;/strong&gt; pour typer l'instance de la classe car la classe &lt;strong&gt;MyClass&lt;/strong&gt; ci-dessus n'est pas une classe basée sur les traits et une instance de type &lt;strong&gt;Class&lt;/strong&gt; et du coup n'est pas considérée en &lt;strong&gt;AS3&lt;/strong&gt; comme un type fort que l'on peut associer à une variable typée.&lt;/p&gt;


&lt;p&gt;Il faut donc utiliser une notation dynamique au maximum si l'on souhaite créer des instances d'une classe basée sur les fonctions constructeurs.&lt;/p&gt;


&lt;p&gt;A noter que dans toutes les classes natives &lt;strong&gt;AS3&lt;/strong&gt; (String, Number, Array, MovieClip, etc...) contenues dans le &lt;strong&gt;FlashPlayer&lt;/strong&gt;, l'objet prototype est présent et contient la plupart du temps des méthodes, il suffit de taper rapidement le code suivant pour s'en assurer&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;Array.prototype     : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;Array&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;prototype&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;Number.prototype    : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;Number&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;prototype&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;String.prototype    : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;prototype&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;MovieClip.prototype : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;MovieClip&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;prototype&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;Nous pouvons compiler ce code et nous obtiendrons à chaque fois une valeur et non un simple &lt;strong&gt;undefined&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;Attention toute fois au résultat de l'exemple ci-dessus. Il ne faut jamais oublier que la méthode &lt;strong&gt;toString&lt;/strong&gt;() de l'objet prototype renvoie dans les traces un String qui dépend de l'implémentation prévue à cet effet dans la classe.&lt;/p&gt;


&lt;p&gt;Par exemple la méthode &lt;strong&gt;toString&lt;/strong&gt;() définie dans le prototype de la classe &lt;strong&gt;Array&lt;/strong&gt; renvoie par défaut une chaine de caractère contenant les valeurs stockées dans le &lt;strong&gt;Array&lt;/strong&gt; séparé par des virgules, dans l'exemple précédent nous obtiendrons donc une chaine vide&amp;nbsp;!&lt;/p&gt;


&lt;p&gt;Pour aller un peu plus loin dans cette notion de classe native et de &lt;strong&gt;prototype&lt;/strong&gt;, il faut savoir par exemple que beaucoup de méthodes dans la classe &lt;strong&gt;Array&lt;/strong&gt; sont déclarées dans les &lt;strong&gt;traits&lt;/strong&gt; mais d'autres également dans le &lt;strong&gt;prototype&lt;/strong&gt; de la classe.&lt;/p&gt;


&lt;p&gt;Je vais revenir rapidement sur la méthode &lt;strong&gt;toString&lt;/strong&gt;() qui est présente dans tous les objets du langage&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; ar&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Array&lt;/span&gt; = &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;ar : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; ar &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// ar :&lt;/span&gt;
&amp;nbsp;
ar = &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;2&lt;/span&gt;, &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;3&lt;/span&gt;, &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;4&lt;/span&gt;, &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;5&lt;/span&gt;,&lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;6&lt;/span&gt;,&lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;7&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;ar : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; ar &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// 2,3,4,5,6,7&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Nous essayons de tracer le contenu d'un &lt;strong&gt;Array&lt;/strong&gt; vide et le résultat n'est pas très explicite.&lt;/p&gt;


&lt;p&gt;De même si nous remplissons le &lt;strong&gt;Array&lt;/strong&gt; avec des valeurs numériques mais également avec d'autres &lt;strong&gt;Array&lt;/strong&gt; contenant eux même des valeurs numériques le résultat n'est pas plus brillant avec une chaine simple de valeurs séparées par des virgules, difficile ici de déterminer quelles sont les valeurs du &lt;strong&gt;Array&lt;/strong&gt; principal et celles du &lt;strong&gt;Array&lt;/strong&gt; défini à la position 3&amp;nbsp;?&lt;/p&gt;


&lt;p&gt;Nous allons voir que pour améliorer le résultat du code précédent il suffira de se pencher sur le &lt;strong&gt;prototype&lt;/strong&gt; de la classe &lt;strong&gt;Array&lt;/strong&gt;, en reprendant le code précédent et en ajustant rapidement son contenu&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Array&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;prototype&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;toString&lt;/span&gt; = &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;[&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;join&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;,&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;]&amp;quot;&lt;/span&gt; ;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; ar&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Array&lt;/span&gt; = &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;ar : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; ar &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// ar : []&lt;/span&gt;
&amp;nbsp;
ar = &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;2&lt;/span&gt;, &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;3&lt;/span&gt;, &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;4&lt;/span&gt;, &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;5&lt;/span&gt;,&lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;6&lt;/span&gt;,&lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;7&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;ar : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; ar &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// [2,3,4,[5,6,7]]&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Le résultat de la méthode &lt;strong&gt;toString&lt;/strong&gt;() est maintenant beaucoup plus explicite et la manipulation s'applique automatiquement à toutes les instances de la classe.&lt;/p&gt;


&lt;p&gt;Finalement même si en &lt;strong&gt;AS3&lt;/strong&gt; pas mal de choses ont changées, il ne faut jamais perdre oublier la présence du prototype dans le langage. Dans nos classes personnalisées il sera donc possible de continuer à utiliser les &lt;strong&gt;prototypes&lt;/strong&gt; soit directement dans le corps des classes, soit en déclarant une fonction constructeur dans un package.&lt;/p&gt;


&lt;p&gt;Je vais rapidement vous montrer comment déclarer une classe basée sur une fonction constructeur en &lt;strong&gt;AS3&lt;/strong&gt;, il suffit simplement de déclarer dans un &lt;strong&gt;package&lt;/strong&gt; une constante de type &lt;strong&gt;Function&lt;/strong&gt; et le tour est joué&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; const User&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Function&lt;/span&gt; = &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; = &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; ;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;
&amp;nbsp;
    User.&lt;span style=&quot;color: #004993;&quot;&gt;prototype&lt;/span&gt;.speak = &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot; : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Vous pouvez noter l'utilisation indispensable du mot clé this pour cibler les propriétés de la classe.&lt;/p&gt;


&lt;p&gt;Pour utiliser cette fonction constructeur il suffit d'utiliser l'opérateur &lt;strong&gt;new&lt;/strong&gt;, en gros voici un code &lt;strong&gt;AS3&lt;/strong&gt; comme en &lt;strong&gt;AS1&lt;/strong&gt;.&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; i&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:*&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; User&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;name&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
i.speak&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;hello world&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;Il est clair que l'utilisation d'une classe dynamique définie avec une fonction constructeur peut paraitre à l'heure actuelle inutile dans le cadre d'un développement &lt;strong&gt;OOP&lt;/strong&gt; avancé en &lt;strong&gt;AS3&lt;/strong&gt;. Mais il ne faut jamais oublié que l'utilisation d'une classe basée uniquement sur les &lt;strong&gt;traits&lt;/strong&gt; bride certains comportements et certaines implémentations et vaut mieux bien connaitre les outils disponibles dans un langage pour pouvoir s'en servir le moment voulu que de vouloir absolument faire comme si ces outils n'existaient pas sous prétexte qu'ils ne correspondent pas à une utilisation classique du langage.&lt;/p&gt;


&lt;p&gt;Voyons maintenant comment utiliser les prototypes dans une classe &lt;strong&gt;AS3&lt;/strong&gt; classique&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; dynamic &lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;class&lt;/span&gt; User 
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; User&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;null&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; = &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; ;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;speak&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;I'm alive&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; ;
&amp;nbsp;
        &lt;span style=&quot;color: #004993;&quot;&gt;prototype&lt;/span&gt;.speak = &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot; say : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; sleep&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;this&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot; sleep : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;La classe ci-dessus contient 2 méthodes &lt;strong&gt;speak&lt;/strong&gt; et &lt;strong&gt;sleep&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;La méthode &quot;&lt;strong&gt;speak&lt;/strong&gt;&quot; par contre est déclarée dans le prototype de la classe. Il est donc possible dans le corps d'une classe de cibler à tout moment l'objet prototype et d'y ajouter (ou d'y modifier) une propriété.&lt;/p&gt;


&lt;p&gt;La méthode &quot;&lt;strong&gt;sleep&lt;/strong&gt;&quot; est classique, elle est déclarée dans le namespace &quot;&lt;strong&gt;public&lt;/strong&gt;&quot; de la classe.&lt;/p&gt;


&lt;p&gt;Nous observons dans cette implémentation certaines contraintes&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;La classe doit être dynamique pour accéder aux éléments contenus dans le &lt;strong&gt;prototype&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Dans une méthode définie dans le &lt;strong&gt;prototype&lt;/strong&gt;, il est indispensable d'utiliser le mot clé &quot;&lt;strong&gt;this&lt;/strong&gt;&quot; pour cibler les propriétés de la classe (défini ou non dans le prototype).&lt;/li&gt;
&lt;li&gt;Dans les autres méthodes basées sur les &lt;strong&gt;traits&lt;/strong&gt; de la classe il faut utiliser la notation entre crochet &lt;strong&gt;[&quot;propertyName&quot;]&lt;/strong&gt; pour appeler ou redéfinir une valeur définie dans le prototype.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Voyons maintenant comment réagi cette classe dans un petit bout de code permettant de la tester&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; user&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;User = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; User&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
user.speak&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;my test&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
user.sleep&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;Rien de bien compliqué finalement pour tous ceux qui ont déjà l'habitude de travailler avec les prototypes. La puissance de l'ActionScript 3 réside dans la possibilité de cohabiter habilement entre une implémentation &lt;strong&gt;OOP&lt;/strong&gt; sécurisée basée sur les &lt;strong&gt;traits&lt;/strong&gt; et une implémentation totalement dynamique basée sur les prototypes et suivant parfaitement les spécifications &lt;strong&gt;ECMAScript&lt;/strong&gt;. Une fois ces 2 éléments maitrisés (feu et glace) tout devient possible.&lt;/p&gt;


&lt;p&gt;Une fonctionnalité intéressante d'une méthode définie dans le prototype de la classe est la possibilité de surcharger directement la méthode au niveau d'une instance sans avoir à toucher à la classe&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; user&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;User = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; User&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
user.speak = &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; , face&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot; is &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; face &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot; and say '&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;'&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
user.speak&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;I love ActionScript !&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;happy&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;Il est impossible de réaliser cette manipulation avec une méthode &lt;strong&gt;public&lt;/strong&gt; de la classe définie dans les &lt;strong&gt;traits&lt;/strong&gt;. Si vous essayez de reproduire cet exemple avec une fonction classique le compilateur refusera d'aller plus loin et notifiera une erreur.&lt;/p&gt;


&lt;p&gt;Nous utilisons donc l'aspect dynamique de l'objet en &lt;strong&gt;ActionScript&lt;/strong&gt; en ajouter sur l'instance directement une méthode &quot;&lt;strong&gt;speak&lt;/strong&gt;&quot;, lorsque nous invoquons la méthode par la suite l'instance trouve la méthode directement et n'a pas besoin d'aller chercher dans le &lt;strong&gt;prototype&lt;/strong&gt; de sa classe.&lt;/p&gt;


&lt;p&gt;La méthode définie dans le &lt;strong&gt;prototype&lt;/strong&gt; est donc ignorée même si elle existe toujours en mémoire. D'ailleurs d'autres instances de la classe &lt;strong&gt;User&lt;/strong&gt; sur le même appel de méthode invoqueront la méthode définie dans le &lt;strong&gt;prototype&lt;/strong&gt; de la classe faute de trouver une méthode avec le même nom défini dynamiquement et localement.&lt;/p&gt;


&lt;p&gt;Ce comportement est un comportement totalement lié au standard &lt;strong&gt;ECMAScript&lt;/strong&gt; utilisé en &lt;strong&gt;Javascript&lt;/strong&gt;, &lt;strong&gt;AS1&lt;/strong&gt; et &lt;strong&gt;AS2&lt;/strong&gt;, il est normal de pouvoir le retrouver en &lt;strong&gt;AS3&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;A noter que pour l'exemple précédent si nous souhaitons dans le code retransformer l'instance pour qu'elle utilise à nouveau sa méthode définie dans le &lt;strong&gt;prototype&lt;/strong&gt; de sa classe il suffit de supprimer la méthode locale&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; user&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;User = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; User&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
user.speak = &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; , face&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot; is &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; face &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot; and say '&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;'&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
user.speak&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;I love ActionScript !&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;happy&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;delete&lt;/span&gt; user.speak ;
&amp;nbsp;
user.speak&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;I love Prototype !&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;Ce comportement apporte une souplesse importante dans le développement d'une application.&lt;/p&gt;


&lt;p&gt;Imaginons pour finir d'illustrer ce concept un jeux vidéo avec un personnage classique dans le monde proposé au joueur, ce personnage possède par défaut certaines méthodes simples &quot;manger&quot;, &quot;courir&quot;, &quot;marcher&quot;, etc. Si à un moment donné dans l'application le personnage trouve un bonus et que ce bonus lui permet de marcher plus vite pendant 15 minutes, il sera très facile avec ce comportement dynamique de modifier en local sur l'objet la méthode &quot;marcher&quot; et au bout de 15 minutes de revenir à une stratégie classique en utilisant à nouveau la méthode définie par défaut dans le prototype de la classe du personnage.&lt;/p&gt;


&lt;p&gt;Cette fonctionnalité en AS3 n'est pas possible directement sur des méthodes déclarées en public. Il est certain qu'il est possible d'utiliser les &quot;namespaces&quot; pour définir différentes stratégies mais leur utilisation est tout de même beaucoup plus complexe que l'utilisation basique des prototype.&lt;/p&gt;


&lt;p&gt;Héritage et surcharge d'une méthode définie dans le prototype.&lt;/p&gt;


&lt;p&gt;En &lt;strong&gt;AS2&lt;/strong&gt; l'héritage d'une classe par une autre est simplifié avec l'utilisation du mot clé &lt;strong&gt;extends&lt;/strong&gt;, il est toujours possible de modifier la chaine d'héritage en changeant la référence de l'objet __proto__ d'un prototype en particulier mais en général l'utilisation de base sera toujours préférée.&lt;/p&gt;


&lt;p&gt;En &lt;strong&gt;AS3&lt;/strong&gt; les classes peuvent toujours hériter d'une autre classe avec le mot clé extends mais l'évolution de certains des membres de la classe sont soumis à de nouvelles contraintes.&lt;/p&gt;


&lt;p&gt;Une des contrainte de l'héritage en &lt;strong&gt;AS3&lt;/strong&gt; réside dans l'utilisation obligatoire du mot clé &quot;override&quot; qui donne droit à la nouvelle classe de surcharger (écraser ou étendre) une méthode déjà existante dans son héritage direct ou indirect, sous réserve de ne pas modifier la signature de la méthode (overloading impossible)&lt;/p&gt;


&lt;p&gt;Exemple&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;class&lt;/span&gt; Student extends User
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; Student&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;null&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;super&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; override &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; sleep&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;this&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot; sleep good : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;toString&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;Student&amp;quot;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Dans cet exemple la classe &lt;strong&gt;Student&lt;/strong&gt; hérite de la classe &lt;strong&gt;User&lt;/strong&gt; et la méthode &lt;strong&gt;sleep&lt;/strong&gt; est surchargée. Dans une méthode classique &lt;strong&gt;AS3&lt;/strong&gt; il est impossible d'opérer une surcharge autrement, l'oubli du mot clé &lt;strong&gt;override&lt;/strong&gt; est sanctionné automatiquement par le compilateur.&lt;/p&gt;


&lt;p&gt;Maintenant nous allons observer quelque chose d'un peu particulier dans la classe définie ci-dessus. Vous savez surement qu'il est possible dans n'importe quelle nouvelle classe de définir une méthode &lt;strong&gt;toString&lt;/strong&gt;() personnalisée.&lt;/p&gt;


&lt;p&gt;Dans notre exemple si nous n'avions pas déclarée de méthode &lt;strong&gt;toString&lt;/strong&gt;() nous savons que cette méthode existe déjà malgré tout par défaut dans la classe vu qu'il est tout à fait possible de l'invoquer sur n'importe quel objet (&lt;em&gt;natif&lt;/em&gt; ou &lt;em&gt;custom&lt;/em&gt;) défini dans l'application.&lt;/p&gt;


&lt;p&gt;Ici nous supposons donc que la méthode &lt;strong&gt;toString&lt;/strong&gt;() existe déjà hors je n'ai pas eu à utiliser le mot clé &quot;&lt;strong&gt;override&lt;/strong&gt;&quot; pour écraser la méthode définie par défaut dans la classe &lt;strong&gt;Object&lt;/strong&gt; (vu que non définie dans la classe &lt;strong&gt;User&lt;/strong&gt;).&lt;/p&gt;


&lt;p&gt;Nous avons vu précédement que pour écraser une méthode définie dans les traits il faut absolument utiliser le mot clé &quot;override&quot;, ici ce n'est pas le cas. De plus dans l'exemple précédent j'ai défini une méthode &lt;strong&gt;toString&lt;/strong&gt;() avec une signature très classique mais j'aurai pu imaginer ajouter un paramètre optionel dans la fonction sans que le compilateur ne me dise quoi que ce soit durant la compilation.&lt;/p&gt;


&lt;p&gt;Ce comportement nous indique donc que la méthode &lt;strong&gt;toString&lt;/strong&gt;() qui existe dans tous les objets n'est donc pas définie dans les traits mais ailleurs. Finalement nous pouvons considérer que cette méthode est définie dans le prototype de la classe &lt;strong&gt;Object&lt;/strong&gt; par défaut. Ce qui laisse une grande liberté pour ensuite la redéfinir dans une classe custom.&lt;/p&gt;


&lt;p&gt;Bien entendu si nous continuons notre héritage avec une nouvelle classe &lt;strong&gt;Teacher&lt;/strong&gt; par exemple qui hérite de la classe &lt;strong&gt;Student&lt;/strong&gt; et que nous essayons d'écraser la méthode &lt;strong&gt;toString&lt;/strong&gt;() définie dans &lt;strong&gt;Student&lt;/strong&gt; dans les traits il faudra alors penser à utiliser une méthode avec le mot clé &quot;&lt;strong&gt;override&lt;/strong&gt;&quot; pour aller plus loin, exemple&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;class&lt;/span&gt; Teacher extends Student
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; Teacher&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;null&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;super&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; override &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;toString&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;Teacher&amp;quot;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Ce coup ci, pas possible de modifier la signature de la méthode &lt;strong&gt;toString&lt;/strong&gt;() définie dans &lt;strong&gt;Student&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;Nous voyons ici une particularité du langage &lt;strong&gt;AS3&lt;/strong&gt;, avec sa double identité basée sur les &lt;strong&gt;traits&lt;/strong&gt; et les &lt;strong&gt;prototypes&lt;/strong&gt;. Les méthodes définies dans les traits seront toujours dominantes sur les méthodes définies dans le prototype de la classe. Mais déclarer une méthode dans le prototype peut être fort utile si nous souhaitons par exemple dans l'héritage par la suite modifier la signature d'une méthode (changer le type ou le nombre des arguments ou le type de retour de la fonction).&lt;/p&gt;


&lt;p&gt;Reprenons maintenant l'exemple précédent en le complétant pour réaliser une surcharge d'une méthode custom définie dans le prototype de la super-classe en transformant cette méthode en méthode plus classique.&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;class&lt;/span&gt; Student extends User
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; Student&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;null&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;super&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; speak&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; , face&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot; is &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; face &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot; and say '&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;message&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;'&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; override &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; sleep&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;this&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot; sleep good : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Je n'ai pas cherché dans l'exemple précédent à écraser la méthode au niveau du prototype de la classe directement et je déclare simplement une nouvelle méthode public &quot;&lt;strong&gt;speak&lt;/strong&gt;&quot; qui sera définie dans le &lt;strong&gt;trait&lt;/strong&gt; de la classe.&lt;/p&gt;


&lt;p&gt;Dans ce cas de figure la méthode &quot;&lt;strong&gt;speak&lt;/strong&gt;&quot; dans le prototype est ignorée et toute instance de la classe Student utilisera maintenant la nouvelle méthode définie dans la classe. Comme nous l'avons vu un peu plus haut les méthodes classiques d'une classe &lt;strong&gt;AS3&lt;/strong&gt; sont toujours dominantes sur une méthode définie dans le prototype de la classe.&lt;/p&gt;


&lt;p&gt;Nous n'avons pas eu à utiliser le mot clé &lt;strong&gt;override&lt;/strong&gt;. L'implémentation de la méthode est directe et peut avoir une signature totalement différente de la méthode définie dans le prototype (nom, type et nombre des arguments, type de retour de la fonction).&lt;/p&gt;


&lt;p&gt;Bien entendu nous perdons dans la classe &lt;strong&gt;Student&lt;/strong&gt; les caractéristiques dynamiques de la classe User et même si nous ajoutons le mot clé &lt;strong&gt;dynamic&lt;/strong&gt; pour déclarer la classe il ne sera plus possible d'écraser au niveau de l'instance directement la méthode &lt;strong&gt;speak&lt;/strong&gt;. Les méthodes définies dans les traits sont plus rapides mais suppriment toute notion de dynamisme sur les instances.&lt;/p&gt;


&lt;p&gt;Personnellement j'utilise souvent le &lt;strong&gt;prototype&lt;/strong&gt; dans mes application selon les besoins rencontrés, par exemple pour reproduire le comportement des méthodes &lt;strong&gt;callbacks&lt;/strong&gt; sur mes clips et boutons comme en &lt;strong&gt;AS1/AS2&lt;/strong&gt; avec des fonctions simples définies rapidement au niveau de l'instance.&lt;/p&gt;


&lt;p&gt;Je vais finir cet article avec un exemple d'implémentation d'un bouton basé sur un &lt;strong&gt;Sprite&lt;/strong&gt; qui fonctionnera très simplement avec des méthodes &lt;strong&gt;callbacks&lt;/strong&gt; définies directement sur l'instance.&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.display&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;Sprite&lt;/span&gt;;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.events&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;MouseEvent&lt;/span&gt;;
&amp;nbsp;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; dynamic &lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;class&lt;/span&gt; MyButton extends &lt;span style=&quot;color: #004993;&quot;&gt;Sprite&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; MyButton&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;width&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Number&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;150&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;height&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Number&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;20&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #004993;&quot;&gt;graphics&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;beginFill&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;0xFF0000&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
            &lt;span style=&quot;color: #004993;&quot;&gt;graphics&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;drawRect&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #004993;&quot;&gt;width&lt;/span&gt;, &lt;span style=&quot;color: #004993;&quot;&gt;height&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
            &lt;span style=&quot;color: #004993;&quot;&gt;buttonMode&lt;/span&gt;    = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ;
            &lt;span style=&quot;color: #004993;&quot;&gt;mouseEnabled&lt;/span&gt;  = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ;
            &lt;span style=&quot;color: #004993;&quot;&gt;useHandCursor&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ;
            &lt;span style=&quot;color: #004993;&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;MouseEvent&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;MOUSE_DOWN&lt;/span&gt;  , _mouseDown &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #004993;&quot;&gt;prototype&lt;/span&gt;.press = &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #009900;&quot;&gt;// nothing, overrides now this method.&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; _mouseDown&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; e&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;MouseEvent&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;null&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;press&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Voyons maintenant comment utiliser cette classe &lt;strong&gt;MyButton&lt;/strong&gt;&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt; 
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.display&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;Sprite&lt;/span&gt;;
&amp;nbsp;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;class&lt;/span&gt; Main extends &lt;span style=&quot;color: #004993;&quot;&gt;Sprite&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; Main&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; button&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;MyButton = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; MyButton&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;120&lt;/span&gt;,&lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;18&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
            button.press = &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;this&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot; press&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;
&amp;nbsp;
            button.&lt;span style=&quot;color: #004993;&quot;&gt;x&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;400&lt;/span&gt; ;
            button.&lt;span style=&quot;color: #004993;&quot;&gt;y&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;130&lt;/span&gt; ;
&amp;nbsp;
            &lt;span style=&quot;color: #004993;&quot;&gt;addChild&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; button &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Voilà pour cet article très &quot;militant&quot; &lt;img src=&quot;/blog/themes/default/smilies/wink.png&quot; alt=&quot;;)&quot; class=&quot;smiley&quot; /&gt; En voyant de plus en plus de développeur minimiser les possibilités des prototypes, j'avais envie de mettre en avant une implémentation particulière en AS3 basée sur cet objet.&lt;/p&gt;


&lt;p&gt;Pour finir je voulais vous indiquer un petit lien vers un nouveau site que j'ouvre en parallèle de mon site officiel et blog&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://sites.google.com/site/ekameleon/Home/articles/actionscript/prototype-et-overriding-en-as3&quot;&gt;http://sites.google.com/site/ekameleon/Home/articles/actionscript/prototype-et-overriding-en-as3&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;J'écris maintenant tous mes articles sur &lt;strong&gt;Google Documents&lt;/strong&gt; avant de les porter sur mon blog. &lt;strong&gt;Google Documents&lt;/strong&gt; répond vraiment à mes besoins pour rédiger mes articles et e-books et je trouve génial tout ce qu'il est possible de faire. Dernière fonctionnalité en date, la possibilité d'injecter dans un &lt;strong&gt;Google Sites&lt;/strong&gt; mes documents.&lt;/p&gt;


&lt;p&gt;Je viens tout juste de me lancer dans mon Google Sites et j'espère pouvoir l'alimenter régulièrement en reprenant mes anciens articles mais aussi des tas de nouveaux dans les prochains mois.&lt;/p&gt;


&lt;p&gt;Comme toujours pour vos questions vous pouvez utiliser les commentaires de cet article ou pourquoi pas pousser la discussion sur mon &lt;strong&gt;Google Groups&lt;/strong&gt; &lt;img src=&quot;/blog/themes/default/smilies/wink.png&quot; alt=&quot;;)&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;</description>
    
    
    
          <comments>http://www.ekameleon.net/blog/index.php?post/2009/06/05/AS3-prototype-et-overriding#comment-form</comments>
      <wfw:comment>http://www.ekameleon.net/blog/index.php?post/2009/06/05/AS3-prototype-et-overriding#comment-form</wfw:comment>
      <wfw:commentRss>http://www.ekameleon.net/blog/index.php?feed/rss2/comments/118</wfw:commentRss>
      </item>
    
  <item>
    <title>Enumération type-safe AS3 (mise à jour)</title>
    <link>http://www.ekameleon.net/blog/index.php?post/2009/05/22/Enumeration-type-safe-AS3-mise-a-jour</link>
    <guid isPermaLink="false">urn:md5:e5527d853711ddce22e0d207374c0af1</guid>
    <pubDate>Fri, 22 May 2009 22:17:00 +0200</pubDate>
    <dc:creator>eKameleon</dc:creator>
        <category>AS3 - Flex - Air</category>
            
    <description>&lt;p&gt;Voici une petite mise à jour de mon vieux article sur les &lt;a href=&quot;http://www.ekameleon.net/blog/index.php?post/2006/09/23/49-as2-as3-enumerations-type-safe&quot;&gt;énumérations type-safe&lt;/a&gt; (qui date tout de même de &lt;strong&gt;septembre 2006&lt;/strong&gt; !!) avec un petit nettoyage avec du code tout en &lt;strong&gt;AS3&lt;/strong&gt; et quelques explications supplémentaires sur la fin de l'article.&lt;/p&gt;


&lt;p&gt;Tous mes articles sont maintenant disponibles en double sur mon blog mais aussi sur des documents publiques sur &lt;strong&gt;Google Document&lt;/strong&gt;&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://docs.google.com/View?id=dfd9s8cg_76cmv6cdcr&quot;&gt;http://docs.google.com/View?id=dfd9s8cg_76cmv6cdcr&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Google Documents&lt;/strong&gt; me permet de mettre à jour facilement mes articles et au final de préparer quelques surprises pour les prochains mois &lt;img src=&quot;/blog/themes/default/smilies/wink.png&quot; alt=&quot;;)&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;


&lt;h3&gt;Généralités.&lt;/h3&gt;


&lt;p&gt;Les énumérations sont utilisées pour réduire les redondances de leur code et garantir le maximum de sécurité.&lt;/p&gt;


&lt;p&gt;En &lt;strong&gt;ActionScript&lt;/strong&gt; il n'existe pas de vraie implémentation précise à ce sujet. Il existe donc plusieurs recettes de cuisines pour les utiliser et je vais essayer de vous montre ma façon d'utiliser les énumérations.&lt;/p&gt;


&lt;h4&gt;Exemple simple d'énumération en utilisant des types primitifs&amp;nbsp;:&lt;/h4&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt;  
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;class&lt;/span&gt; ApplicationColor
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; 
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; static &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; getColor&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;color&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;uint&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;uint&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;switch&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;color&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;case&lt;/span&gt; 0xD97F00 &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;// abricot&lt;/span&gt;
                &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;case&lt;/span&gt; 0xFFFFFF &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;// blanc&lt;/span&gt;
                &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;case&lt;/span&gt; 0xD70079 &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;// bonbon&lt;/span&gt;
                &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;case&lt;/span&gt; 0xAE293B &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;// cerise&lt;/span&gt;
                &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;case&lt;/span&gt; 0xFF6633 &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;// corail &lt;/span&gt;
                &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;color&lt;/span&gt; ;
                &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
                &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;default&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
                &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;return&lt;/span&gt; 0x000000 ; &lt;span style=&quot;color: #009900;&quot;&gt;// black&lt;/span&gt;
                &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Dans la méthode &lt;strong&gt;getColor()&lt;/strong&gt; ci-dessus nous pouvons constater tout d'abord que la lecture des couleurs n'est pas forcément des plus simples (à moins d'avoir un panneau mélangeur câblé en permanence dans votre esprit), il est assez difficile de définir précisément les couleurs représentées dans la condition &lt;strong&gt;switch..case&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;De plus si l'on doit réutiliser ces couleurs plus loin dans le code, il va falloir reprendre à chaque fois toutes les primitives. Si au cours de votre développement une couleur change il va falloir mettre en place un &lt;strong&gt;refactoring&lt;/strong&gt; plus ou moins long pour remettre à jour l'ensemble de l'application. En gros il va devenir très rapidement assez compliqué de maintenir le code avec cette sorte d'implémentation.&lt;/p&gt;


&lt;p&gt;A noter que j'ai tout de même mi en place quelques petits commentaires pour rendre un peu plus facile la lecture du code mais la lisibilité s'arrête là, il va devenir très lourd de commenter à chaque fois le code.&lt;/p&gt;


&lt;h4&gt;2 - Exemple un peu plus évolué avec des constantes&lt;/h4&gt;    &lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;class&lt;/span&gt; ApplicationColor
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; static const ABRICOT &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;uint&lt;/span&gt; = 0xD97F00 ;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; static const BLANC   &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;uint&lt;/span&gt; = 0xFFFFFF ;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; static const BONBON  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;uint&lt;/span&gt; = 0xD70079 ;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; static const CERISE  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;uint&lt;/span&gt; = 0xAE293B ;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; static const CORAIL  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;uint&lt;/span&gt; = 0xFF6633 ;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; static const NOIR    &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;uint&lt;/span&gt; = 0x000000 ;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; static &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; getColor&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;color&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;uint&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;uint&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
              &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;switch&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;color&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
              &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                  &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;case&lt;/span&gt; ABRICOT &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
                  &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;case&lt;/span&gt; BLANC   &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
                  &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;case&lt;/span&gt; BONBON  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
                  &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;case&lt;/span&gt; CERISE  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
                  &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;case&lt;/span&gt; CORAIL  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
                  &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                      &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;color&lt;/span&gt; ;
                  &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
                  &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;default&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
                  &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                      &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;return&lt;/span&gt; NOIR ;
                  &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
              &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;    
          &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Le code au dessus est déjà bien plus clair. Il n'est plus nécessaire de commenter celui ci car le nom des énumérations est bien assez explicite.&lt;/p&gt;


&lt;p&gt;De plus il est assez simple de modifier une couleur sans avoir à retoucher par la suite l'intégralité du code, il suffit d'utiliser ces constantes dans tout le code de l'application et si il faut modifier une couleur il suffit de redéfinir la valeur d'une des constantes. Cette solution est bien plus élégante que la précédente et reste simple.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Remarque :&lt;/strong&gt; A noter que la plupart des éditeurs de code un peu évolués (&lt;strong&gt;FDT&lt;/strong&gt;, &lt;strong&gt;FlashBuilder&lt;/strong&gt;) permettent l'auto complétion et ainsi permettent de retrouver rapidement le contenu une énumération de constantes.&lt;/p&gt;


&lt;h4&gt;3 - &quot;Typesafe&quot; Enumeration.&lt;/h4&gt;


&lt;p&gt;Nous allons maintenant pousser l'exemple précédent en intégrant des énumérations typées avec une classe spécifique pour nos couleurs.&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;class&lt;/span&gt; ApplicationColor
     &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; ApplicationColor&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;uint&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt; = &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt; ;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;uint&lt;/span&gt; ;
&amp;nbsp;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;valueOf&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;uint&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt; ;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; static const ABRICOT &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;ApplicationColor = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; ApplicationColor&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0xD97F00 &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; static const BLANC   &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;ApplicationColor = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; ApplicationColor&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0xFFFFFF &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; static const BONBON  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;ApplicationColor = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; ApplicationColor&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0xD70079 &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; static const CERISE  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;ApplicationColor = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; ApplicationColor&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0xAE293B &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; static const CORAIL  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;ApplicationColor = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; ApplicationColor&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0xFF6633 &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; static const NOIR    &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;ApplicationColor = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; ApplicationColor&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0x000000 &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;L'exemple au dessus est un peu plus complexe car il nécessite de définir dans la classe le constructeur et une propriété pour stocker la valeur de l'énumération. Cet exemple reste tout de même assez simple à mettre en place et permet cette fois ci une meilleure sécurité des objets utilisés dans l'application.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Remarque :&lt;/strong&gt; En &lt;strong&gt;AS2&lt;/strong&gt; la classe &lt;strong&gt;ApplicationColor&lt;/strong&gt; aurait pu hériter de la classe &lt;strong&gt;Number&lt;/strong&gt;, en &lt;strong&gt;AS3&lt;/strong&gt; la classe &lt;strong&gt;Number&lt;/strong&gt; est déclarée en &quot;&lt;strong&gt;final&lt;/strong&gt;&quot; et il est donc impossible de l'étendre. Malgré tout, il est possible d'en revenir à peut prêt au même en utilisant la méthode &lt;strong&gt;valueOf&lt;/strong&gt;() (présente dans tous les objets en &lt;strong&gt;ActionScript&lt;/strong&gt;), cette méthode renvoie la valeur primitive d'un objet et dans notre exemple, elle renvoie la valeur numérique (&lt;strong&gt;uint&lt;/strong&gt;) de l'objet.&lt;/p&gt;


&lt;p&gt;Cette implémentation illustre le design pattern&amp;nbsp;: &quot;&lt;strong&gt;Type-safe Enum&lt;/strong&gt;&quot;.&lt;/p&gt;


&lt;p&gt;De plus en utilisant une classe pour typer les énumérations il est possible d'ajouter sur les constantes des fonctionnalités avancées via quelques méthodes plus facilement que sur un type primitif.
Voyons de plus prêt une version finalisée de notre classe &lt;strong&gt;ApplicationColor&lt;/strong&gt; avec un exemple un peu plus complet&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;class&lt;/span&gt; ApplicationColor
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; ApplicationColor&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;uint&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            _name  = &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt;  ;
            _value = &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; _name&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; ;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; _value&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;uint&lt;/span&gt; ;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;valueOf&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;uint&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;return&lt;/span&gt; _value ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;toString&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;return&lt;/span&gt; _name ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; static const ABRICOT &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;ApplicationColor = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; ApplicationColor&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0xD97F00 , &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;abricot&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; static const BLANC   &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;ApplicationColor = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; ApplicationColor&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0xFFFFFF , &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;blanc&amp;quot;&lt;/span&gt;   &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; static const BONBON  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;ApplicationColor = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; ApplicationColor&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0xD70079 , &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;bonbon&amp;quot;&lt;/span&gt;  &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; static const CERISE  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;ApplicationColor = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; ApplicationColor&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0xAE293B , &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;cerise&amp;quot;&lt;/span&gt;  &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; static const CORAIL  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;ApplicationColor = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; ApplicationColor&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0xFF6633 , &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;corail&amp;quot;&lt;/span&gt;  &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; static const NOIR    &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;ApplicationColor = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; ApplicationColor&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0x000000 , &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;noir&amp;quot;&lt;/span&gt;    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Nous avons ajouté dans notre classe une propriété &lt;strong&gt;name&lt;/strong&gt; qui permet de donner un nom spécifique à l'objet.&lt;/p&gt;


&lt;h4&gt;Points positifs de ce pattern.&lt;/h4&gt;


&lt;p&gt;Le constructeur est &lt;strong&gt;public&lt;/strong&gt; et il est possible d'étendre la classe et de créer de nouvelles énumérations en dehors de la classe.&lt;/p&gt;


&lt;p&gt;L'utilisation du mot clé &lt;strong&gt;const&lt;/strong&gt; permet de fixer dans l'application certaines constantes typées.&lt;/p&gt;


&lt;p&gt;J'écrase ( &lt;strong&gt;override&lt;/strong&gt; ) la méthode &lt;strong&gt;toString&lt;/strong&gt;() de la classe pour renvoyer le nom de l'instance et la méthode &lt;strong&gt;valueOf&lt;/strong&gt;() renvoi la valeur numérique de l'instance ce qui permet de combiner à la fois des manipulations classiques avec les opérateurs sur ces énumérations mais également de renvoyer dans un panneau de sortie des messages plus explicites (pour ma part je préfère lire dans mon panneau de sortie le mot &quot;&lt;strong&gt;abricot&lt;/strong&gt;&quot; que la valeur &lt;strong&gt;14253824&lt;/strong&gt; qui lui correspond en &lt;strong&gt;base 10&lt;/strong&gt;).&lt;/p&gt;


&lt;h4&gt;Points négatifs de ce pattern&amp;nbsp;:&lt;/h4&gt;


&lt;p&gt;Le point qui peut sembler négatif est à mon avis que cette technique alourdie un peu le poids de vos applications et prend un peu plus de temps pour être mise en place qu'une simple variable primitive.&lt;/p&gt;


&lt;p&gt;Il est certain que lorsque l'on commence à utiliser ce genre de technique nous pouvons perdre un peu en &quot;&lt;strong&gt;vitesse&lt;/strong&gt;&quot;, mais attention quand je parle de temps et de vitesse il faut rester très relatif sur ces 2 dernières remarques... Un bon développeur utilisera cette technique le moment voulu et il est parfois indispensable de pouvoir utiliser l'une ou l'autre des techniques selon les besoins.&lt;/p&gt;


&lt;p&gt;Ces techniques s'utilisent dans des cadres précis et impliquent une bonne réflexion sur l'architecture de son code.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Remarques :&lt;/strong&gt;&lt;/p&gt;


&lt;p&gt;L'utilisation des constantes écrites comme ci-dessus uniquement avec des lettres en majuscules restent une nomenclature très utilisée dans la communauté des développeurs &lt;strong&gt;ActionScript&lt;/strong&gt;, &lt;strong&gt;ECMAScript&lt;/strong&gt; ou même &lt;strong&gt;JAVA&lt;/strong&gt; etc.&lt;/p&gt;


&lt;p&gt;En &lt;strong&gt;AS3&lt;/strong&gt;, il n'est pas possible d'utiliser de constructeur privé (il existe beaucoup de discussion à ce sujet d'ailleurs avec la notion de pattern Singleton par exemple) mais il est possible d'utiliser des exceptions pour sécuriser le constructeur de la classe. Dans tous les cas je me suis rendu compte que l'utilisation d'un constructeur privé est pas une si bonne chose que cela finalement, surtout lorsque l'on souhaite tester efficacement une classe avec un minimum d'unit tests.&lt;/p&gt;


&lt;h4&gt;4 - Petite manipulation sur la valeur primitive ou la représentation sous forme de chaine de caractères d'une énumération type-safe utilisant les méthodes valueOf() et toString().&lt;/h4&gt;


&lt;p&gt;Nous avons vu plus haut dans l'exemple de la classe &lt;strong&gt;ApplicationColor&lt;/strong&gt; qu'il est possible de jouer sur les méthods &lt;strong&gt;toString&lt;/strong&gt;() et &lt;strong&gt;valueOf&lt;/strong&gt;() d'une classe ou d'un objet pour lui donner des fonctionnalités plus fines.&lt;/p&gt;


&lt;p&gt;Voyons comment utiliser ces 2 méthodes&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;color        : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; ApplicationColor.ABRICOT &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// abricot&lt;/span&gt;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;color        : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; ApplicationColor.ABRICOT.&lt;span style=&quot;color: #004993;&quot;&gt;toString&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// abricot&lt;/span&gt;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;color number : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; ApplicationColor.ABRICOT.&lt;span style=&quot;color: #004993;&quot;&gt;valueOf&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;  &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// 14253824&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Pour obtenir la valeur numérique de la classe il est nécessaire d'invoquer la méthode &lt;strong&gt;valueOf&lt;/strong&gt;(). Alors que la méthode &lt;strong&gt;toString&lt;/strong&gt;() sera utilisée pour récupérer la représentation en chaine de caractère de l'objet.&lt;/p&gt;


&lt;p&gt;J'utilisais énormément la méthode &lt;strong&gt;valueOf&lt;/strong&gt;() pour m'assurer de récupérer la valeur primitive d'un objet comme dans le code ci-dessus dans mes classes et au final je me suis rendu compte il y a peu de temps (alors que j'aurai pu utiliser cette technique depuis un petit moment maintenant) qu'il est beaucoup plus simple et pratique d'utiliser la capacité de transformation des fonctions constructeurs (&lt;strong&gt;type casting&lt;/strong&gt; avec fonction constructeur)&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; ApplicationColor.ABRICOT &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// abricot&lt;/span&gt;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;uint&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; ApplicationColor.ABRICOT &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// 14253824&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;ApplicationColor.ABRICOT&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;1&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// abricot1&lt;/span&gt;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; ApplicationColor.ABRICOT &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;1&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// 14253825&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Selon si nous voulons jouer sur la valeur primitive &quot;&lt;strong&gt;uint&lt;/strong&gt;&quot; ou &quot;&lt;strong&gt;string&lt;/strong&gt;&quot; de l'objet nous pouvons utiliser les fonctions &lt;strong&gt;String&lt;/strong&gt;() ou &lt;strong&gt;uint&lt;/strong&gt;() pour encapsuler la valeur de la constante et extraire ainsi la bonne valeur. Je trouve cette technique beaucoup plus élégante que l'utilisation directe des méthodes &lt;strong&gt;toString&lt;/strong&gt;() ou &lt;strong&gt;valueOf&lt;/strong&gt;().&lt;/p&gt;


&lt;h4&gt;5 - Evaluation et comparaison entres valeurs d'une énumération type-safe.&lt;/h4&gt;


&lt;p&gt;Il peut arriver parfois qu'il soit nécessaire de comparer les valeurs de certaines énumérations dans une application, exemple si la valeur est renvoyée par un serveur via du &lt;strong&gt;class-mapping&lt;/strong&gt; (dans ce cas d'ailleurs il sera indispensable que la classe de l'énumération soit &quot;&lt;strong&gt;public&lt;/strong&gt;&quot; et puisse s'instancier sans soucis lors du passage de données entre le serveur et le client).&lt;/p&gt;


&lt;p&gt;Maintenant si nous souhaitons comparer 2 objets de même type mais définis dans une &lt;strong&gt;énumération type-safe&lt;/strong&gt; en particulier, il ne faudra pas forcément tester qu'ils représentent une même référence en mémoire mais surtout qu'ils soient identiques en comparant certaines valeurs importantes.&lt;/p&gt;


&lt;p&gt;Du coup l'opérateur &lt;strong&gt;==&lt;/strong&gt; ne sera pas forcément la meilleure solution dans ce cas de figure et il sera beaucoup plus intéressant d'implémenter une méthode &quot;&lt;strong&gt;equals(o:*):Boolean&lt;/strong&gt;&quot; via une petite interface &lt;a href=&quot;http://code.google.com/p/maashaack/source/browse/trunk/AS3/src/system/Equatable.as&quot;&gt;Equatable&lt;/a&gt; par exemple dans la classe &lt;strong&gt;ApplicationColor&lt;/strong&gt;&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; system.Equatable;
&amp;nbsp;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;class&lt;/span&gt; ApplicationColor implements Equatable
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; ApplicationColor&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;uint&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            _name  = &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt;  ;
            _value = &lt;span style=&quot;color: #004993;&quot;&gt;value&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; static const ABRICOT &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;ApplicationColor = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; ApplicationColor&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0xD97F00 , &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;abricot&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; static const BLANC   &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;ApplicationColor = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; ApplicationColor&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0xFFFFFF , &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;blanc&amp;quot;&lt;/span&gt;   &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; static const BONBON  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;ApplicationColor = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; ApplicationColor&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0xD70079 , &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;bonbon&amp;quot;&lt;/span&gt;  &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; static const CERISE  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;ApplicationColor = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; ApplicationColor&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0xAE293B , &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;cerise&amp;quot;&lt;/span&gt;  &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; static const CORAIL  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;ApplicationColor = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; ApplicationColor&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0xFF6633 , &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;corail&amp;quot;&lt;/span&gt;  &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; static const NOIR    &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;ApplicationColor = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; ApplicationColor&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0x000000 , &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;noir&amp;quot;&lt;/span&gt;    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;equals&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; o&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:*&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Boolean&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; o &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;is&lt;/span&gt; ApplicationColor &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;o &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;as&lt;/span&gt; ApplicationColor&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;valueOf&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; == _value &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;o &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;as&lt;/span&gt; ApplicationColor&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;toString&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; == _name ;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;else&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;false&lt;/span&gt; ;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;valueOf&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;uint&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;return&lt;/span&gt; _value ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;toString&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;return&lt;/span&gt; _name ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; _name&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; ;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; _value&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;uint&lt;/span&gt; ;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Pour comparer une valeur définie dans l'énumération et un objet (quel qu'il soit) il suffira d'utiliser la méthode &lt;strong&gt;equals()&lt;/strong&gt;&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;color&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;ApplicationColor = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; ApplicationColor&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0xFFFFFF , &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;blanc&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; ApplicationColor.BLANC.&lt;span style=&quot;color: #004993;&quot;&gt;equals&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;color&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// true&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Plus de problème maintenant pour comparer une valeur provenant d'un script serveur ou autre et une valeur typée énumérée dans la classe &lt;strong&gt;ApplicationColor&lt;/strong&gt; définie ci-dessus.&lt;/p&gt;</description>
    
    
    
          <comments>http://www.ekameleon.net/blog/index.php?post/2009/05/22/Enumeration-type-safe-AS3-mise-a-jour#comment-form</comments>
      <wfw:comment>http://www.ekameleon.net/blog/index.php?post/2009/05/22/Enumeration-type-safe-AS3-mise-a-jour#comment-form</wfw:comment>
      <wfw:commentRss>http://www.ekameleon.net/blog/index.php?feed/rss2/comments/117</wfw:commentRss>
      </item>
    
  <item>
    <title>La classe asgard.display.Background</title>
    <link>http://www.ekameleon.net/blog/index.php?post/2009/04/30/La-classe-asgarddisplayBackground</link>
    <guid isPermaLink="false">urn:md5:1a6fa417b66e5ae9b79b1feb13d0fbd4</guid>
    <pubDate>Thu, 30 Apr 2009 20:00:00 +0200</pubDate>
    <dc:creator>eKameleon</dc:creator>
        <category>VEGAS</category>
        <category>as3</category><category>asgard</category><category>design pattern</category><category>Graphics</category><category>opensource</category><category>pegas</category><category>Sprite</category><category>vegas</category>    
    <description>&lt;h3&gt;Description&lt;/h3&gt;


&lt;p&gt;La classe &lt;a href=&quot;http://www.ekameleon.net/vegas/docs/asgard/display/Background.html&quot;&gt;Background&lt;/a&gt; est une classe simple mais très efficace que j'utilise dans pratiquement tous mes projets &lt;strong&gt;AS3&lt;/strong&gt;. Cette classe hérite de la classe &lt;strong&gt;flash.display.Sprite&lt;/strong&gt; et permet de générer des zones graphiques rectangulaires. Ces zones peuvent aussi bien remplir l'intégralité de la zone visible du FlashPlayer ou plus simplement servir de fond pour divers éléments graphiques d'une application (menus, listes, lecteur vidéo, etc.)&lt;/p&gt;


&lt;p&gt;Cette classe utilise les &lt;strong&gt;API dynamiques de dessins&lt;/strong&gt; pour générer très simplement un rectangle coloré (uni ou dégradé) ou texturé en utilisant les outils de dessins disponibles dans &lt;a href=&quot;http://code.google.com/p/pegas/&quot;&gt;PEGAS&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;&amp;nbsp;: Je ne vais pas rentrer trop dans le détail ici sur le moteur de dessin de &lt;a href=&quot;http://code.google.com/p/pegas/&quot;&gt;PEGAS&lt;/a&gt; car cette implémentation nécessite une série de tutoriels précis et complets. Je ne vais donc pas trop parler dans les exemples qui suivent des classes spécifiques de PEGAS mais n'hésitez pas en cas de problème à me poser des questions sur le sujet en attendant que je trouve le temps d'écrire les articles manquants sur le sujet.&lt;/p&gt;


&lt;h3&gt;Les bases&lt;/h3&gt;


&lt;p&gt;Pour commencer voyons tout simplement comment créer via quelques lignes de codes une zone rectangulaire avec la classe Background&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; asgard.display.Background ;
&amp;nbsp;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; pegas.&lt;span style=&quot;color: #004993;&quot;&gt;draw&lt;/span&gt;.FillStyle ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; area&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Background = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; Background&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
area.&lt;span style=&quot;color: #004993;&quot;&gt;x&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;25&lt;/span&gt; ;
area.&lt;span style=&quot;color: #004993;&quot;&gt;y&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;25&lt;/span&gt; ;
&amp;nbsp;
area.fill = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; FillStyle&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0xD97BD0 , &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;0.8&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
area.w    = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;400&lt;/span&gt; ;
area.h    = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;300&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;addChild&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; area &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;Le code ci-dessus permet de générer une zone rectangulaire de &lt;strong&gt;400&lt;/strong&gt; pixels de large (&lt;strong&gt;w&lt;/strong&gt;) par &lt;strong&gt;300&lt;/strong&gt; pixels de hauteur (&lt;strong&gt;h&lt;/strong&gt;) avec une couleur de remplissage&lt;strong&gt; 0xD97BD0&lt;/strong&gt; et une transparence de &lt;strong&gt;80%&lt;/strong&gt; (&lt;strong&gt;alpha&lt;/strong&gt;).&lt;/p&gt;


&lt;p&gt;Dans la classe &lt;a href=&quot;http://www.ekameleon.net/vegas/docs/asgard/display/Background.html&quot;&gt;Background&lt;/a&gt; nous utilisons les propriétés virtuelles &quot;&lt;strong&gt;w&lt;/strong&gt;&quot; et &quot;&lt;strong&gt;h&lt;/strong&gt;&quot; pour définir la largeur et la hauteur absolues que nous voulons attribuer à notre zone rectangulaire. Je parle ici de taille &quot;absolue&quot; car finalement même si nous attribuons les valeurs &lt;strong&gt;400&lt;/strong&gt; et &lt;strong&gt;300&lt;/strong&gt;, le rectangle n'aura peut être pas au final cette taille si l'on regarde les propriétés classiques &quot;&lt;strong&gt;width&lt;/strong&gt;&quot; et &quot;&lt;strong&gt;height&lt;/strong&gt;&quot; du display, surtout si nous appliquons à notre zone rectangulaire un contour.&lt;/p&gt;


&lt;p&gt;Je reprends l'exemple précédent en ajoutant un contour avec la propriété &quot;&lt;strong&gt;line&lt;/strong&gt;&quot; de la classe Background&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; asgard.display.Background ;
&amp;nbsp;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; pegas.&lt;span style=&quot;color: #004993;&quot;&gt;draw&lt;/span&gt;.FillStyle ;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; pegas.&lt;span style=&quot;color: #004993;&quot;&gt;draw&lt;/span&gt;.LineStyle ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; area&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Background = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; Background&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
area.fill = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; FillStyle&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0xD97BD0 , &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;0.8&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
area.line = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; LineStyle&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;2&lt;/span&gt;, 0xD97BD0, &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;0.6&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
area.w    = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;400&lt;/span&gt; ;
area.h    = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;300&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;addChild&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; area &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;Dans l'exemple ci-dessus j'applique sur la zone rectangulaire un contour avec une épaisseur de &lt;strong&gt;2 pixels&lt;/strong&gt; avec la propriété &quot;&lt;strong&gt;line&lt;/strong&gt;&quot; qui prend pour valeur un objet de type &lt;strong&gt;LineStyle&lt;/strong&gt;. Avec un petit test très simple nous pouvons isoler la différence entre les propriétés &lt;strong&gt;w/h&lt;/strong&gt; et &lt;strong&gt;width/height&lt;/strong&gt;&amp;nbsp;:&lt;/p&gt;    &lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; area.w &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot; : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; area.&lt;span style=&quot;color: #004993;&quot;&gt;width&lt;/span&gt;  &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// 400 : 402&lt;/span&gt;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; area.h &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot; : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; area.&lt;span style=&quot;color: #004993;&quot;&gt;height&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// 300 : 302&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;&lt;strong&gt;Remarque :&lt;/strong&gt; Les propriétés &quot;&lt;strong&gt;line&lt;/strong&gt;&quot; et &quot;&lt;strong&gt;fill&lt;/strong&gt;&quot; de la classe &lt;strong&gt;Background&lt;/strong&gt; permettent de définir respectivement les styles du contour et du remplissage de la zone rectangulaire.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;La propriété &lt;strong&gt;line&lt;/strong&gt; prend pour valeur tout objet de type &lt;a href=&quot;http://www.ekameleon.net/vegas/docs/pegas/draw/ILineStyle.html&quot;&gt;pegas.draw.ILineStyle&lt;/a&gt; (LineStyle, LineGradientStyle)&lt;/li&gt;
&lt;li&gt;La propriété &lt;strong&gt;fill&lt;/strong&gt; prend pour valeur tout objet de type &lt;a href=&quot;http://www.ekameleon.net/vegas/docs/pegas/draw/IFillStyle.html&quot;&gt;pegas.draw.FillStyle&lt;/a&gt; (FillStyle, FillGradientStyle, FillBitmapStyle)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Je vous invite à consulter la documentation de &lt;strong&gt;VEGAS&lt;/strong&gt; et à tester ces classes en regardant tranquillement les exemples du package &lt;strong&gt;pegas.draw&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;Il est possible de limiter la taille minimale et maximale des propriétés w et h de la classe &lt;strong&gt;Background&lt;/strong&gt; avec les propriétés virtuelles&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;maxHeight&lt;/strong&gt;&amp;nbsp;: permet de définir la taille maximale de la propriété h&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;maxWidth&lt;/strong&gt;&amp;nbsp;: permet de définir la taille maximale de la propriété w&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;minHeight&lt;/strong&gt;&amp;nbsp;: permet de définir la taille minimale de la propriété h&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;minWidth&lt;/strong&gt;&amp;nbsp;: permet de définir la taille minimale de la propriété w&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ces propriétés sont de type &lt;strong&gt;Number&lt;/strong&gt;, si l'une de ces propriétés est définie avec la valeur &lt;strong&gt;NaN&lt;/strong&gt; alors aucune limite n'est appliquée sur la forme.&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; asgard.display.Background ;
&amp;nbsp;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; pegas.&lt;span style=&quot;color: #004993;&quot;&gt;draw&lt;/span&gt;.FillStyle ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; area&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Background = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; Background&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
area.fill = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; FillStyle&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0xD97BD0 , &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;0.8&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
area.maxWidth  = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;200&lt;/span&gt; ;
area.maxHeight = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;200&lt;/span&gt; ;
&amp;nbsp;
area.w = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;400&lt;/span&gt; ;
area.h = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;300&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;addChild&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; area &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; area.w &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot; : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; area.h &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// 200 : 200&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Chaque appel des propriétés &lt;strong&gt;w&lt;/strong&gt; ou &lt;strong&gt;h&lt;/strong&gt; invoque en interne la méthode &lt;strong&gt;update()&lt;/strong&gt; de la classe &lt;strong&gt;Background&lt;/strong&gt;. La méthode &lt;strong&gt;update()&lt;/strong&gt; sert de moteur principal et permet de rafraichir à tout moment l'aspect graphique du display. Pour optimiser le redimensionnement d'une instance de type &lt;strong&gt;Background&lt;/strong&gt; vous pourrez utiliser également la méthode &lt;strong&gt;setSize(w,h)&lt;/strong&gt;&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; asgard.display.Background ;
&amp;nbsp;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; pegas.&lt;span style=&quot;color: #004993;&quot;&gt;draw&lt;/span&gt;.FillStyle ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; area&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Background = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; Background&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
area.fill = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; FillStyle&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0xD97BD0 , &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;0.8&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
area.setSize&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;400&lt;/span&gt; , &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;300&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;addChild&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; area &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;La méthode&lt;strong&gt; setSize(w,h)&lt;/strong&gt; invoque qu'une seul fois la méthode &lt;strong&gt;&quot;update()&quot;&lt;/strong&gt; contre 2 appels si nous utilisons dans le code au même moment les 2 propriétés &lt;strong&gt;w&lt;/strong&gt; et &lt;strong&gt;h&lt;/strong&gt;. Il faudra donc faire attention selon les besoins d'utiliser les propriétés virtuelles ou la méthode &lt;strong&gt;setSize()&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;A noter que tout changement de taille sur un &lt;strong&gt;Background&lt;/strong&gt; diffuse un événement de type &lt;strong&gt;Event.RESIZE&lt;/strong&gt;.&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; asgard.display.Background ;
&amp;nbsp;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; pegas.&lt;span style=&quot;color: #004993;&quot;&gt;draw&lt;/span&gt;.FillStyle ;
&amp;nbsp;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.events&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;Event&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;resize&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Function&lt;/span&gt; = &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; e&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Event&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;resize w:&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; area.w &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot; h:&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; area.h &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; 
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; area&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Background = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; Background&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;addChild&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; area &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
area.fill = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; FillStyle&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0xD97BD0 , &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;0.8&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
area.&lt;span style=&quot;color: #004993;&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;Event&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;RESIZE&lt;/span&gt; , &lt;span style=&quot;color: #004993;&quot;&gt;resize&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
area.setSize&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;400&lt;/span&gt; , &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;300&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;h3&gt;Les options de la classe Background&lt;/h3&gt;


&lt;h2&gt;Arrondir les angles&lt;/h2&gt;


&lt;p&gt;Première option sympatique dans la classe &lt;strong&gt;Background&lt;/strong&gt; avec les propriétés numériques&amp;nbsp;: &lt;strong&gt;bottomLeftRadius&lt;/strong&gt;, &lt;strong&gt;bottomRightRadius&lt;/strong&gt;, &lt;strong&gt;topLeftRadius&lt;/strong&gt; et &lt;strong&gt;topRightRadius&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;Ces 4 propriétés permettent de définir pour chaque coin de la zone rectangulaire la taille du rayon que l'on souhaite appliquer (par défaut 0 et donc pas d'arrondi).&lt;/p&gt;


&lt;p&gt;Attention malgré tout car ces propriétés ne sont pas virtuelles et pour tout changement visuel sur la zone rectangulaire il faudra invoquer manuellement la méthode &lt;strong&gt;update()&lt;/strong&gt; de l'instance&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; asgard.display.Background ;
&amp;nbsp;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; pegas.&lt;span style=&quot;color: #004993;&quot;&gt;draw&lt;/span&gt;.FillStyle ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; area&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Background = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; Background&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;addChild&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; area &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
area.fill = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; FillStyle&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0xD97BD0 , &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;0.8&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
area.setSize&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;400&lt;/span&gt; , &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;300&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
area.topLeftRadius     = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;12&lt;/span&gt; ;
area.bottomRightRadius = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;12&lt;/span&gt; ;
&amp;nbsp;
area.update&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;&lt;strong&gt;Remarque :&lt;/strong&gt; Toute propriété ou méthode qui invoque indirectement la méthode&lt;strong&gt; update()&lt;/strong&gt; suffit pour mettre à jour la vue, par exemple l'utilisation de la méthode &lt;strong&gt;setSize()&lt;/strong&gt; juste après les propriétés définies ci-dessus suffira pour rafraichir la vue&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; asgard.display.Background ;
&amp;nbsp;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; pegas.&lt;span style=&quot;color: #004993;&quot;&gt;draw&lt;/span&gt;.FillStyle ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; area&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Background = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; Background&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;addChild&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; area &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
area.fill = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; FillStyle&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0xD97BD0 , &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;0.8&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
area.topLeftRadius     = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;12&lt;/span&gt; ;
area.bottomRightRadius = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;12&lt;/span&gt; ;
&amp;nbsp;
area.setSize&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;400&lt;/span&gt; , &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;300&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// update&lt;/span&gt;&lt;/pre&gt;


&lt;h2&gt;Choisir l'alignement de la zone rectangulaire&lt;/h2&gt;


&lt;p&gt;La propriété virtuelle numérique &quot;&lt;strong&gt;align&lt;/strong&gt;&quot; permet de modifier l'alignement de la zone rectangulaire. Pour définir simplement la propriété &quot;&lt;strong&gt;align&lt;/strong&gt;&quot; il suffit d'utiliser l'énumération &lt;a href=&quot;http://www.ekameleon.net/vegas/docs/pegas/draw/Align.html&quot;&gt;pegas.draw.Align&lt;/a&gt; avec les constantes&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Align.CENTER&lt;/li&gt;
&lt;li&gt;Align.LEFT, Align.RIGHT&lt;/li&gt;
&lt;li&gt;Align.BOTTOM, Align.BOTTOM_LEFT, Align.BOTTOM_RIGHT&lt;/li&gt;
&lt;li&gt;Align.TOP, Align.TOP_LEFT, Align.TOP_RIGHT&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Exemple :&lt;/strong&gt;&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; asgard.display.Background ;
&amp;nbsp;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; pegas.&lt;span style=&quot;color: #004993;&quot;&gt;draw&lt;/span&gt;.Align ;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; pegas.&lt;span style=&quot;color: #004993;&quot;&gt;draw&lt;/span&gt;.FillStyle ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; area&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Background = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; Background&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;addChild&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; area &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
area.&lt;span style=&quot;color: #004993;&quot;&gt;x&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;100&lt;/span&gt; ;
area.&lt;span style=&quot;color: #004993;&quot;&gt;y&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;100&lt;/span&gt; ;
&amp;nbsp;
area.&lt;span style=&quot;color: #004993;&quot;&gt;align&lt;/span&gt; = Align.&lt;span style=&quot;color: #004993;&quot;&gt;CENTER&lt;/span&gt; ;
&amp;nbsp;
area.fill = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; FillStyle&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0xD97BD0 , &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;0.8&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
area.setSize&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;400&lt;/span&gt; , &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;300&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;Je vous conseille d'essayer les diverses constantes de la classe &lt;strong&gt;Align&lt;/strong&gt; pour voir les différents comportements de dessin de la zone rectangulaire.&lt;/p&gt;


&lt;h2&gt;Mode plein écran et direction&lt;/h2&gt;


&lt;p&gt;Par défaut les propriétés &lt;strong&gt;w&lt;/strong&gt; et &lt;strong&gt;h&lt;/strong&gt; de la classe &lt;strong&gt;Background&lt;/strong&gt; renvoies les valeurs numériques définies par l'utilisateur dans le code.&lt;/p&gt;


&lt;p&gt;Il est toute fois possible de changer le comportement des propriétés &lt;strong&gt;w&lt;/strong&gt; et &lt;strong&gt;h&lt;/strong&gt; en utilisant les propriétés &quot;&lt;strong&gt;isFull&lt;/strong&gt;&quot;, &quot;&lt;strong&gt;direction&lt;/strong&gt;&quot; et &quot;&lt;strong&gt;autoSize&lt;/strong&gt;&quot; de la classe &lt;strong&gt;Background&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;La propriété &lt;strong&gt;isFull&lt;/strong&gt; est une propriété virtuelle booléenne qui change la stratégie en lecture des propriétés &lt;strong&gt;w&lt;/strong&gt; et &lt;strong&gt;h&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;Quand la propriété &lt;strong&gt;isFull&lt;/strong&gt; vaut &quot;&lt;strong&gt;true&lt;/strong&gt;&quot; alors les propriétés &lt;strong&gt;w&lt;/strong&gt; et &lt;strong&gt;h&lt;/strong&gt; ne renvoies non plus les valeurs définies par l'utilisateur mais la largeur et la hauteur définies par les propriétés &lt;strong&gt;stage.stageWidth&lt;/strong&gt; et &lt;strong&gt;stage.stageHeight&lt;/strong&gt; (à condition que le background soit attaché dans la display list de l'application).&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; asgard.display.Background ;
&amp;nbsp;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; pegas.&lt;span style=&quot;color: #004993;&quot;&gt;draw&lt;/span&gt;.FillStyle ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;stage&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;align&lt;/span&gt;     = &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;tl&amp;quot;&lt;/span&gt; ;
&lt;span style=&quot;color: #004993;&quot;&gt;stage&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;scaleMode&lt;/span&gt; = &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;noScale&amp;quot;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; area&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Background = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; Background&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;addChild&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; area &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
area.fill = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; FillStyle&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0xD97BD0 , &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;0.8&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
area.isFull  = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; area.w == &lt;span style=&quot;color: #004993;&quot;&gt;stage&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;stageWidth&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// true&lt;/span&gt;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; area.h == &lt;span style=&quot;color: #004993;&quot;&gt;stage&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;stageHeight&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// true&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Dans l'exemple ci-dessus la scène est définir avec un alignement en haut à gauche et une propriété &lt;strong&gt;scaleMode&lt;/strong&gt; avec la valeur &quot;&lt;strong&gt;noScale&lt;/strong&gt;&quot;. Il est important de modifier la nature par défaut de la scène pour profiter au mieux des fonctionnalités avancées de la classe &lt;strong&gt;Background&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;Ainsi, le code précédent redimensionne automatiquement la zone rectangulaire avec la taille courante de la scène principale dans le &lt;strong&gt;FlashPlayer&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;Petit problème maintenant car si nous changeons la taille du &lt;strong&gt;FlashPlayer&lt;/strong&gt;, la zone rectangulaire gardera sa taille définir préalablement au moment de l'activation du mode &quot;&lt;strong&gt;isFull&lt;/strong&gt;&quot;. Si nous souhaitons garder à tout moment un fond avec une largeur et hauteur identique à celle de l'animation il faudra combiner le code ci-dessus avec la propriété virtuelle &quot;&lt;strong&gt;autoSize&lt;/strong&gt;&quot;&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; asgard.display.Background ;
&amp;nbsp;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; pegas.&lt;span style=&quot;color: #004993;&quot;&gt;draw&lt;/span&gt;.FillStyle ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;stage&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;align&lt;/span&gt;     = &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;tl&amp;quot;&lt;/span&gt; ;
&lt;span style=&quot;color: #004993;&quot;&gt;stage&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;scaleMode&lt;/span&gt; = &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;noScale&amp;quot;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; area&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Background = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; Background&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;addChild&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; area &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
area.fill     = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; FillStyle&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0xD97BD0 , &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;0.8&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
area.isFull   = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ;
area.&lt;span style=&quot;color: #004993;&quot;&gt;autoSize&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;Le code ci-dessus permet très simplement de créer un fond qui prendra la taille de toute votre animation. Très pratique pour créer des fond d'écrans mais aussi des &quot;&lt;strong&gt;shadow box&lt;/strong&gt;&quot; (zone rectangulaire qui couvre toute l'application permettant d'afficher des informations ou des messages d'alertes) ou &quot;&lt;strong&gt;protector&lt;/strong&gt;&quot; (zone couvrant toute la scène et permettant de protéger l'application de tout click de souris)&lt;/p&gt;


&lt;p&gt;A noter qu'il est possible d'aller encore plus loin en créant une classe &quot;&lt;strong&gt;custom&lt;/strong&gt;&quot; qui héritera de la classe &lt;strong&gt;Background&lt;/strong&gt; car dans ce cas il sera possible de définir des comportements avancés pendant le redimensionnement de la zone rectangulaire, exemple&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt; example.display
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; asgard.display.Background;
&amp;nbsp;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.display&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;Bitmap&lt;/span&gt;;    
&amp;nbsp;
    &lt;span style=&quot;color: #3f5fbf;&quot;&gt;/**
     * The wallpaper of the application.
     */&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;class&lt;/span&gt; Wallpaper extends Background
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #3f5fbf;&quot;&gt;/**
         * Creates a new Wallpaper instance.
         */&lt;/span&gt;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; Wallpaper&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            isFull   = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ;
            &lt;span style=&quot;color: #004993;&quot;&gt;autoSize&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #3f5fbf;&quot;&gt;/**
         * The picture of the wallpaper.
         */&lt;/span&gt;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; picture&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Bitmap&lt;/span&gt; ;
&amp;nbsp;
        &lt;span style=&quot;color: #3f5fbf;&quot;&gt;/**
         * Invoked after the draw() method in the update() method.
         */&lt;/span&gt;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; override &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; viewChanged&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; picture &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;!&lt;/span&gt;= &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;null&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                picture.&lt;span style=&quot;color: #004993;&quot;&gt;x&lt;/span&gt; = &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; w &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;-&lt;/span&gt; picture.&lt;span style=&quot;color: #004993;&quot;&gt;width&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;2&lt;/span&gt; ;
                picture.&lt;span style=&quot;color: #004993;&quot;&gt;y&lt;/span&gt; = &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; h &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;-&lt;/span&gt; picture.&lt;span style=&quot;color: #004993;&quot;&gt;height&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;2&lt;/span&gt; ;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;        
&amp;nbsp;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;La classe &lt;strong&gt;Wallpaper&lt;/strong&gt; définie ci-dessus hérite de la classe &lt;strong&gt;Background&lt;/strong&gt;. Je vous ai déjà parlé de la méthode &lt;strong&gt;update()&lt;/strong&gt; de la classe &lt;strong&gt;Background&lt;/strong&gt;, il faut savoir également que cette méthode invoque en interne une méthode &quot;&lt;strong&gt;viewChanged&lt;/strong&gt;&quot; qui peut être écrasée (&lt;strong&gt;override&lt;/strong&gt;) par l'utilisateur dans une classe custom et il est donc possible de gérer en fonction des besoins le positionnement d'autres sous objets par exemple dans cette méthode.&lt;/p&gt;


&lt;p&gt;Je fini l'exemple ci-dessus avec un petit bout de code simple&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; example.display.Wallpaper ;
&amp;nbsp;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.display&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;Bitmap&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; pegas.&lt;span style=&quot;color: #004993;&quot;&gt;draw&lt;/span&gt;.FillStyle ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;stage&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;align&lt;/span&gt;     = &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;tl&amp;quot;&lt;/span&gt; ;
&lt;span style=&quot;color: #004993;&quot;&gt;stage&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;scaleMode&lt;/span&gt; = &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;noScale&amp;quot;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; wallpaper&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Wallpaper = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; Wallpaper&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
wallpaper.picture = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;Bitmap&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; MyPicture&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;0&lt;/span&gt;,&lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #009900;&quot;&gt;// MyPicture a BitmapData in the library of the swf&lt;/span&gt;
wallpaper.fill    = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; FillStyle&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; 0x000000 &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
wallpaper.&lt;span style=&quot;color: #004993;&quot;&gt;addChild&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; picture &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&lt;span style=&quot;color: #004993;&quot;&gt;addChild&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; wallpaper &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;Le &lt;strong&gt;Bitmap&lt;/strong&gt; &quot;&lt;strong&gt;picture&lt;/strong&gt;&quot; est passé par référence dans l'instance &quot;&lt;strong&gt;wallpaper&lt;/strong&gt;&quot;. Visuellement l'image est toujours centrée dans le font de l'écran (voir contenu de la méthode viewChanged de la classe Wallpaper définie plus haut).&lt;/p&gt;


&lt;p&gt;Les possibilités de la classe &lt;strong&gt;Background&lt;/strong&gt; sont vastes et peuvent évoluées selon les besoins.&lt;/p&gt;


&lt;p&gt;A noter qu'il est possible pour finir d'utiliser la propriété virtuelle &quot;&lt;strong&gt;direction&lt;/strong&gt;&quot; avec les valeurs &lt;strong&gt;Direction.HORIZONTAL&lt;/strong&gt; ou &lt;strong&gt;Direction.VERTICAL&lt;/strong&gt; (voir la classe &lt;a href=&quot;http://www.ekameleon.net/vegas/docs/pegas/draw/Direction.html&quot;&gt;pegas.draw.Direction&lt;/a&gt;).&lt;/p&gt;


&lt;p&gt;La propriété &quot;&lt;strong&gt;direction&lt;/strong&gt;&quot; permet de modifier encore un peu la stratégie des propriétés &lt;strong&gt;w&lt;/strong&gt; et &lt;strong&gt;h&lt;/strong&gt; si la propriété &quot;&lt;strong&gt;isFull&lt;/strong&gt;&quot; est active (&lt;strong&gt;true&lt;/strong&gt;)&amp;nbsp;:&lt;/p&gt;


&lt;p&gt;Si la propriété &quot;&lt;strong&gt;direction&lt;/strong&gt;&quot; a pour valeur &quot;&lt;strong&gt;null&lt;/strong&gt;&quot; et &lt;strong&gt;isFull = true&lt;/strong&gt;, les propriétés &lt;strong&gt;w&lt;/strong&gt; et &lt;strong&gt;h&lt;/strong&gt; prennent la taille de la scène (comportement décrit plus haut).&lt;/p&gt;


&lt;p&gt;Si la propriété &quot;&lt;strong&gt;direction&lt;/strong&gt;&quot; a pour valeur la chaine de caractère &quot;&lt;strong&gt;horizontal&lt;/strong&gt;&quot; (ou &lt;strong&gt;Direction.HORIZONTAL&lt;/strong&gt;)&amp;nbsp;: seule la propriété &lt;strong&gt;w&lt;/strong&gt; prend la largeur de la scène, la propriété &lt;strong&gt;h&lt;/strong&gt; garde sa taille définie dans le code. Il est donc possible de créer facilement des &lt;strong&gt;bandeaux horizontaux&lt;/strong&gt; dans une application avec cette propriété en mode &quot;&lt;strong&gt;horizontal&lt;/strong&gt;&quot;.&lt;/p&gt;


&lt;p&gt;Si la propriété &quot;&lt;strong&gt;direction&lt;/strong&gt;&quot; a pour valeur la chaine de caractère &quot;&lt;strong&gt;vertical&lt;/strong&gt;&quot; (ou &lt;strong&gt;Direction.VERTICAL&lt;/strong&gt;)&amp;nbsp;: seule la propriété &lt;strong&gt;h&lt;/strong&gt; prend la hauteur de la scène, la propriété &lt;strong&gt;w&lt;/strong&gt; garde sa taille définie dans le code. Il est donc possible de créer facilement des &lt;strong&gt;bandeaux verticaux&lt;/strong&gt; dans une application avec cette propriété en mode &quot;&lt;strong&gt;vertical&lt;/strong&gt;&quot;.&lt;/p&gt;


&lt;p&gt;Pour finir ce tutoriel je vais ajouter un dernier exemple beaucoup plus complet que vous pourrez trouver sur le SVN de &lt;strong&gt;ASGard&lt;/strong&gt; avec la classe &lt;a href=&quot;http://code.google.com/p/as-gard/source/browse/trunk/AS3/trunk/examples/asgard/display/examples/TestBackground.as&quot;&gt;TestBackground&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;Voici le code de la classe pour ceux qui auront pas le courage de cliquer sur le lien ci-dessus&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;package&lt;/span&gt; examples 
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; asgard.display.Background;
&amp;nbsp;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; pegas.&lt;span style=&quot;color: #004993;&quot;&gt;draw&lt;/span&gt;.Direction;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; pegas.&lt;span style=&quot;color: #004993;&quot;&gt;draw&lt;/span&gt;.FillGradientStyle;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; pegas.&lt;span style=&quot;color: #004993;&quot;&gt;draw&lt;/span&gt;.FillStyle;
&amp;nbsp;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.display&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;GradientType&lt;/span&gt;;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.display&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;Sprite&lt;/span&gt;;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.display&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;StageAlign&lt;/span&gt;;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.display&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;StageScaleMode&lt;/span&gt;;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.events&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;KeyboardEvent&lt;/span&gt;;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.ui&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;Keyboard&lt;/span&gt;;    
&amp;nbsp;
    &lt;span style=&quot;color: #3f5fbf;&quot;&gt;/**
     * Example with the asgard.display.Background class.
     */&lt;/span&gt;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #9900cc; font-weight: bold;&quot;&gt;class&lt;/span&gt; TestBackground extends &lt;span style=&quot;color: #004993;&quot;&gt;Sprite&lt;/span&gt; 
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; TestBackground&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
            &lt;span style=&quot;color: #004993;&quot;&gt;stage&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;align&lt;/span&gt;     = &lt;span style=&quot;color: #004993;&quot;&gt;StageAlign&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;TOP_LEFT&lt;/span&gt; ;
            &lt;span style=&quot;color: #004993;&quot;&gt;stage&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;scaleMode&lt;/span&gt; = &lt;span style=&quot;color: #004993;&quot;&gt;StageScaleMode&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;NO_SCALE&lt;/span&gt; ;
&amp;nbsp;
            &lt;span style=&quot;color: #004993;&quot;&gt;stage&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;KeyboardEvent&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;KEY_DOWN&lt;/span&gt;, &lt;span style=&quot;color: #004993;&quot;&gt;keyDown&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
            &lt;span style=&quot;color: #004993;&quot;&gt;background&lt;/span&gt;         = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; Background&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
            &lt;span style=&quot;color: #004993;&quot;&gt;background&lt;/span&gt;.fill    = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; FillStyle&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;0xD97BD0, &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
            &lt;span style=&quot;color: #004993;&quot;&gt;background&lt;/span&gt;.w       = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;400&lt;/span&gt; ;
            &lt;span style=&quot;color: #004993;&quot;&gt;background&lt;/span&gt;.h       = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;300&lt;/span&gt; ;
&amp;nbsp;
            &lt;span style=&quot;color: #004993;&quot;&gt;addChild&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;background&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
            &lt;span style=&quot;color: #009900;&quot;&gt;// little tests&lt;/span&gt;
            &lt;span style=&quot;color: #009900;&quot;&gt;// background.minWidth = 600 ;&lt;/span&gt;
            &lt;span style=&quot;color: #009900;&quot;&gt;// background.maxWidth = 250 ;&lt;/span&gt;
            &lt;span style=&quot;color: #009900;&quot;&gt;// background.line = new LineStyle(2, 0xFFFFFF, 1) ;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;protected&lt;/span&gt; &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;background&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Background ;        
&amp;nbsp;
        &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;protected&lt;/span&gt; &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;keyDown&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; e&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;KeyboardEvent&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;code&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;uint&lt;/span&gt; = e.&lt;span style=&quot;color: #004993;&quot;&gt;keyCode&lt;/span&gt; ;
            &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;switch&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;code&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;case&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;Keyboard&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;SPACE&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
                &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;background&lt;/span&gt;.isFull &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
                    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                        &lt;span style=&quot;color: #004993;&quot;&gt;background&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;autoSize&lt;/span&gt;  = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;false&lt;/span&gt; ;
                        &lt;span style=&quot;color: #004993;&quot;&gt;background&lt;/span&gt;.direction = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;null&lt;/span&gt; ;
                        &lt;span style=&quot;color: #004993;&quot;&gt;background&lt;/span&gt;.isFull    = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;false&lt;/span&gt; ;
                        &lt;span style=&quot;color: #004993;&quot;&gt;background&lt;/span&gt;.fill      = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; FillStyle&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;0xD97BD0&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
                    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
                    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;else&lt;/span&gt;
                    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                        &lt;span style=&quot;color: #004993;&quot;&gt;background&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;autoSize&lt;/span&gt;         = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ;
                        &lt;span style=&quot;color: #004993;&quot;&gt;background&lt;/span&gt;.isFull           = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ;
                        &lt;span style=&quot;color: #004993;&quot;&gt;background&lt;/span&gt;.direction        = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;null&lt;/span&gt; ;
                        &lt;span style=&quot;color: #004993;&quot;&gt;background&lt;/span&gt;.gradientRotation = &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;90&lt;/span&gt; ;
                        &lt;span style=&quot;color: #004993;&quot;&gt;background&lt;/span&gt;.useGradientBox   = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ;
                        &lt;span style=&quot;color: #004993;&quot;&gt;background&lt;/span&gt;.fill             = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; FillGradientStyle
                        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;
                            &lt;span style=&quot;color: #004993;&quot;&gt;GradientType&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;LINEAR&lt;/span&gt; , &lt;span style=&quot;color: #009900;&quot;&gt;// type &lt;/span&gt;
                            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;0x071E2C,0x81C2ED&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt; , &lt;span style=&quot;color: #009900;&quot;&gt;// colors&lt;/span&gt;
                            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;               , &lt;span style=&quot;color: #009900;&quot;&gt;// alphas&lt;/span&gt;
                            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;0&lt;/span&gt;,0xFF&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;              &lt;span style=&quot;color: #009900;&quot;&gt;// ratios&lt;/span&gt;
                        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
                    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
                    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;break&lt;/span&gt; ;
                &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
                &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;case&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;Keyboard&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;UP&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
                &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                    &lt;span style=&quot;color: #004993;&quot;&gt;background&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;autoSize&lt;/span&gt;  = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ;
                    &lt;span style=&quot;color: #004993;&quot;&gt;background&lt;/span&gt;.fill      = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; FillStyle&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;0x000000&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
                    &lt;span style=&quot;color: #004993;&quot;&gt;background&lt;/span&gt;.isFull    = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ;
                    &lt;span style=&quot;color: #004993;&quot;&gt;background&lt;/span&gt;.direction = Direction.&lt;span style=&quot;color: #004993;&quot;&gt;HORIZONTAL&lt;/span&gt; ;
                    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;break&lt;/span&gt; ;
                &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
                &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;case&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;Keyboard&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;DOWN&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
                &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                    &lt;span style=&quot;color: #004993;&quot;&gt;background&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;autoSize&lt;/span&gt;  = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ;
                    &lt;span style=&quot;color: #004993;&quot;&gt;background&lt;/span&gt;.fill      = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; FillStyle&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;0xFFFFFF&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
                    &lt;span style=&quot;color: #004993;&quot;&gt;background&lt;/span&gt;.isFull    = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;true&lt;/span&gt; ;
                    &lt;span style=&quot;color: #004993;&quot;&gt;background&lt;/span&gt;.direction = Direction.&lt;span style=&quot;color: #004993;&quot;&gt;VERTICAL&lt;/span&gt; ;         
                    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;break&lt;/span&gt; ;
                &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;J'espère que ce tutoriel vous a permis de découvrir au mieux la classe &lt;a href=&quot;http://code.google.com/p/as-gard/source/browse/trunk/AS3/trunk/src/asgard/display/Background.as&quot;&gt;asgard.display.Background&lt;/a&gt; est très pratique et à la fois très simple d'utilisation.&lt;/p&gt;


&lt;p&gt;Je vous invite donc à vous amuser avec le plus possible &lt;img src=&quot;/blog/themes/default/smilies/wink.png&quot; alt=&quot;;)&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;


&lt;p&gt;A noter qu'avec un peu d'&lt;strong&gt;IoC&lt;/strong&gt; pour définir rapidement vos zones graphiques dans votre application cela devient encore plus sympa d'utiliser cette classe des petits exemples dans &lt;a href=&quot;http://code.google.com/p/astr/&quot;&gt;AST&lt;/a&gt;'r sont à votre disposition pour les plus curieux&amp;nbsp;!&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Remarque :&lt;/strong&gt;&lt;/p&gt;


&lt;p&gt;Vous pouvez consulter ce document sur &lt;strong&gt;Google Document&lt;/strong&gt; à tout moment sans passer par mon blog à l'adresse publique suivante&amp;nbsp;: &lt;a href=&quot;http://docs.google.com/Doc?id=dfd9s8cg_70fc5t36f3&quot;&gt;http://docs.google.com/Doc?id=dfd9s8cg_70fc5t36f3&lt;/a&gt;&lt;/p&gt;</description>
    
    
    
          <comments>http://www.ekameleon.net/blog/index.php?post/2009/04/30/La-classe-asgarddisplayBackground#comment-form</comments>
      <wfw:comment>http://www.ekameleon.net/blog/index.php?post/2009/04/30/La-classe-asgarddisplayBackground#comment-form</wfw:comment>
      <wfw:commentRss>http://www.ekameleon.net/blog/index.php?feed/rss2/comments/116</wfw:commentRss>
      </item>
    
  <item>
    <title>Contrôler la timeline de vos animations.</title>
    <link>http://www.ekameleon.net/blog/index.php?post/2009/03/29/Controler-la-timeline-de-vos-animations</link>
    <guid isPermaLink="false">urn:md5:3c663430798aa082ec0928fdee6903b1</guid>
    <pubDate>Sun, 29 Mar 2009 22:37:00 +0200</pubDate>
    <dc:creator>eKameleon</dc:creator>
        <category>AS3 - Flex - Air</category>
        <category>as3</category><category>framework</category><category>MovieClip</category><category>opensource</category><category>timeline</category><category>vegas</category>    
    <description>&lt;h2&gt;1 - Généralité&lt;/h2&gt;


&lt;p&gt;Pour contrôler la &lt;strong&gt;timeline&lt;/strong&gt; d'une animation &lt;strong&gt;Flash&lt;/strong&gt; ou d'un &lt;strong&gt;MovieClip&lt;/strong&gt; nous avons l'habitude depuis les toutes premières versions de l'&lt;strong&gt;ActionScript&lt;/strong&gt; d'utiliser les méthodes &lt;strong&gt;play&lt;/strong&gt;(), &lt;strong&gt;stop&lt;/strong&gt;(), &lt;strong&gt;gotoAndStop&lt;/strong&gt;(), etc. de la classe &lt;strong&gt;MovieClip&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;En &lt;strong&gt;AS3&lt;/strong&gt; de nouvelles propriétés et méthodes sont apparues pour rendre encore plus souple notre maitrise de la &lt;strong&gt;timeline&lt;/strong&gt; et de nos animations. Nous pouvons noter l'apparition de la classe &lt;strong&gt;flash.display.FrameLabel&lt;/strong&gt; qui permet d'obtenir à n'importe quel moment via un objet typé toutes les informations d'une imagé clé portant une étiquette d'image spécifique. Ou encore la possibilité d'utiliser une méthode non documenté &lt;strong&gt;addFrameScript&lt;/strong&gt;() qui permet d'injecter dans les images clés d'un &lt;strong&gt;MovieClip&lt;/strong&gt; des fonctions selon les besoin au runtime.&lt;/p&gt;


&lt;p&gt;Malgré ces outils de base, j'ai eu très vite besoin d'aller un peu plus loin et de standardiser dans l'extension &lt;a href=&quot;http://code.google.com/p/as-gard/&quot;&gt;ASGard&lt;/a&gt; de &lt;strong&gt;VEGAS&lt;/strong&gt; avec 3 classes bien pratiques pour manipuler le scénario d'un &lt;strong&gt;MovieClip&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Ces classes sont :&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://code.google.com/p/as-gard/source/browse/trunk/AS3/trunk/src/asgard/display/TimelineInspector.as&quot;&gt;asgard.display.TimelineInspector&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://code.google.com/p/as-gard/source/browse/trunk/AS3/trunk/src/asgard/display/TimelineIterator.as&quot;&gt;asgard.display.TimelineIterator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://code.google.com/p/as-gard/source/browse/trunk/AS3/trunk/src/asgard/display/TimelineScript.as&quot;&gt;asgard.display.TimelineScript&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pour utiliser ces classes je vous invite à récupérer les sources de &lt;strong&gt;VEGAS&lt;/strong&gt; (pour ceux qui ne l'ont pas encore récupéré les sources &lt;strong&gt;AS3&lt;/strong&gt; ;))&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;http://code.google.com/p/vegas/wiki/InstallVEGASwithSVN?tm=4&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pour toute question sur &lt;a href=&quot;http://code.google.com/p/vegas/&quot;&gt;VEGAS&lt;/a&gt; et ses extensions vous pouvez vous inscrire sur le &lt;a href=&quot;http://groups.google.com/group/vegasos&quot;&gt;Google Groups du projet&amp;nbsp;: VEGASOS&lt;/a&gt; .&lt;/p&gt;    &lt;h2&gt;2 - La classe asgard.display.TimelineInspector&lt;/h2&gt;


&lt;p&gt;Cette classe diffuse des événements de type &lt;a href=&quot;http://code.google.com/p/as-gard/source/browse/trunk/AS3/trunk/src/asgard/events/FrameLabelEvent.as&quot;&gt;asgard.events.FrameLabelEvent&lt;/a&gt; avec le type défini dans la constante &lt;strong&gt;FrameLabelEvent.FRAME_LABEL&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;Elle prend la main par composition sur un &lt;strong&gt;MovieClip&lt;/strong&gt; et injecte via la méthode &lt;strong&gt;addFrameScript&lt;/strong&gt; des fonctionnalités dans le &lt;strong&gt;MovieClip&lt;/strong&gt; pour diffuser des événements pendant la lecture du clip lorsque la tête de lecture rencontre un clip contenant une image clé portant une étiquette d'image.&lt;/p&gt;


&lt;p&gt;Cette classe permet en gros comme pour des vidéos d'injecter au &lt;strong&gt;runtime&lt;/strong&gt; des &quot;&lt;strong&gt;cue points&lt;/strong&gt;&quot; et permet de très rapidement prendre la main avec des fonctionnalités avancées &lt;strong&gt;ActionScript&lt;/strong&gt; sur une animation simple générée par un graphiste ou animateur qui n'a pas trop l'habitude de manipuler l'&lt;strong&gt;ActionScript&lt;/strong&gt; (si si cela existe encore malheureusement). Il faudra juste qu'il mette des étiquettes sur les images clés importantes de son animation.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Exemple d'utilisation :&lt;/strong&gt;&lt;/p&gt;

&lt;pre class=&quot;actionscript&quot;&gt;package examples
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0066CC;&quot;&gt;import&lt;/span&gt; asgard.&lt;span style=&quot;color: #006600;&quot;&gt;display&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;TimelineInspector&lt;/span&gt;;
    &lt;span style=&quot;color: #0066CC;&quot;&gt;import&lt;/span&gt; asgard.&lt;span style=&quot;color: #006600;&quot;&gt;events&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;FrameLabelEvent&lt;/span&gt;;
&amp;nbsp;
    &lt;span style=&quot;color: #0066CC;&quot;&gt;import&lt;/span&gt; flash.&lt;span style=&quot;color: #006600;&quot;&gt;display&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;FrameLabel&lt;/span&gt;;
    &lt;span style=&quot;color: #0066CC;&quot;&gt;import&lt;/span&gt; flash.&lt;span style=&quot;color: #006600;&quot;&gt;display&lt;/span&gt;.&lt;span style=&quot;color: #0066CC;&quot;&gt;MovieClip&lt;/span&gt;;
    &lt;span style=&quot;color: #0066CC;&quot;&gt;import&lt;/span&gt; flash.&lt;span style=&quot;color: #006600;&quot;&gt;display&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;Sprite&lt;/span&gt;;
    &lt;span style=&quot;color: #0066CC;&quot;&gt;import&lt;/span&gt; flash.&lt;span style=&quot;color: #006600;&quot;&gt;display&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;StageAlign&lt;/span&gt;;
    &lt;span style=&quot;color: #0066CC;&quot;&gt;import&lt;/span&gt; flash.&lt;span style=&quot;color: #006600;&quot;&gt;display&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;StageScaleMode&lt;/span&gt;;
    &lt;span style=&quot;color: #0066CC;&quot;&gt;import&lt;/span&gt; flash.&lt;span style=&quot;color: #006600;&quot;&gt;events&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;MouseEvent&lt;/span&gt;;
    &lt;span style=&quot;color: #0066CC;&quot;&gt;import&lt;/span&gt; flash.&lt;span style=&quot;color: #006600;&quot;&gt;utils&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;setTimeout&lt;/span&gt;;    
&amp;nbsp;
    &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**
     * Example with the asgard.display.TestTimelineInspector class.
     */&lt;/span&gt;
    &lt;span style=&quot;color: #0066CC;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;dynamic&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; TestTimelineInspector &lt;span style=&quot;color: #0066CC;&quot;&gt;extends&lt;/span&gt; Sprite
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0066CC;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; TestTimelineInspector&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
            &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// stage&lt;/span&gt;
&amp;nbsp;
            &lt;span style=&quot;color: #0066CC;&quot;&gt;stage&lt;/span&gt;.&lt;span style=&quot;color: #0066CC;&quot;&gt;align&lt;/span&gt;      = StageAlign.&lt;span style=&quot;color: #006600;&quot;&gt;TOP_LEFT&lt;/span&gt; ;
            &lt;span style=&quot;color: #0066CC;&quot;&gt;stage&lt;/span&gt;.&lt;span style=&quot;color: #0066CC;&quot;&gt;scaleMode&lt;/span&gt;  = StageScaleMode.&lt;span style=&quot;color: #006600;&quot;&gt;NO_SCALE&lt;/span&gt; ;
&amp;nbsp;
            &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// target&lt;/span&gt;
&amp;nbsp;
            &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// &amp;quot;mc&amp;quot; a MovieClip in the stage of the application&lt;/span&gt;
            mc = getChildByName&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;mc&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; as &lt;span style=&quot;color: #0066CC;&quot;&gt;MovieClip&lt;/span&gt; ;
&amp;nbsp;
            mc.&lt;span style=&quot;color: #0066CC;&quot;&gt;useHandCursor&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;true&lt;/span&gt; ;
            mc.&lt;span style=&quot;color: #006600;&quot;&gt;buttonMode&lt;/span&gt;    = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;true&lt;/span&gt; ;
&amp;nbsp;
            mc.&lt;span style=&quot;color: #006600;&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; MouseEvent.&lt;span style=&quot;color: #006600;&quot;&gt;CLICK&lt;/span&gt; , click &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
            &lt;span style=&quot;color: #0066CC;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Click the movieclip to start the example.&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
            &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// timeline inspector&lt;/span&gt;
&amp;nbsp;
            &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;var&lt;/span&gt; inspector:TimelineInspector = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; TimelineInspector&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; mc , &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;true&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
            inspector.&lt;span style=&quot;color: #006600;&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; FrameLabelEvent.&lt;span style=&quot;color: #006600;&quot;&gt;FRAME_LABEL&lt;/span&gt;, frameLabel &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0066CC;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;var&lt;/span&gt; mc:&lt;span style=&quot;color: #0066CC;&quot;&gt;MovieClip&lt;/span&gt; ;
&amp;nbsp;
        &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**
          * Run the test.
          */&lt;/span&gt;
        &lt;span style=&quot;color: #0066CC;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; click&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;e&lt;/span&gt;:MouseEvent &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #0066CC;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
            mc.&lt;span style=&quot;color: #0066CC;&quot;&gt;play&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**
         * Invoked when a new frame label notify a FrameLabelEvent.
         */&lt;/span&gt;
        &lt;span style=&quot;color: #0066CC;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; frameLabel&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;e&lt;/span&gt;:FrameLabelEvent &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #0066CC;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;var&lt;/span&gt; frame:FrameLabel = &lt;span style=&quot;color: #0066CC;&quot;&gt;e&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;frameLabel&lt;/span&gt; ;
            &lt;span style=&quot;color: #0066CC;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;frameLabel :: &amp;quot;&lt;/span&gt; + frame.&lt;span style=&quot;color: #006600;&quot;&gt;frame&lt;/span&gt; + &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot; : &amp;quot;&lt;/span&gt; + frame.&lt;span style=&quot;color: #0066CC;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
            &lt;span style=&quot;color: #b1b100;&quot;&gt;switch&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; frame.&lt;span style=&quot;color: #0066CC;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
            &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
                &lt;span style=&quot;color: #b1b100;&quot;&gt;case&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;finish&amp;quot;&lt;/span&gt; :
                &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
                    mc.&lt;span style=&quot;color: #0066CC;&quot;&gt;stop&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
                    &lt;span style=&quot;color: #b1b100;&quot;&gt;break&lt;/span&gt; ;
                &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
                &lt;span style=&quot;color: #b1b100;&quot;&gt;case&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;middle&amp;quot;&lt;/span&gt; :
                &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
                    mc.&lt;span style=&quot;color: #0066CC;&quot;&gt;stop&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
                    setTimeout&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;mc.&lt;span style=&quot;color: #0066CC;&quot;&gt;play&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;5000&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// pause 5 seconds&lt;/span&gt;
                    &lt;span style=&quot;color: #b1b100;&quot;&gt;break&lt;/span&gt; ;
                &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
            &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Le code précédent est très simple, il suffit donc de prendre la main sur un MovieClip en tapant simplement&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;var&lt;/span&gt; inspector:TimelineInspector = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; TimelineInspector&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; mc , &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;true&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;A noter que le second paramètre du constructeur de la classe &lt;a href=&quot;http://code.google.com/p/as-gard/source/browse/trunk/AS3/trunk/src/asgard/display/TimelineInspector.as&quot;&gt;TimelineInspector&lt;/a&gt; permet de lancer automatiquement la fonction stop() du MovieClip ciblé pour arrêter tout de suite sa lecture (par exemple si le graphiste n'a pas mi de code sur la première image clé de l'animation pour stopper celle ci).&lt;/p&gt;


&lt;p&gt;Il suffit donc ensuite d'écouter l'événement de type &lt;strong&gt;FrameLabelEvent.FRAME_LABEL&lt;/strong&gt; pour recevoir les notifications pendant la lecture de l'animation. Dans l'exemple ci-dessus il faut cliquer sur le &lt;strong&gt;MovieClip&lt;/strong&gt; pour lancer son animation.&lt;/p&gt;


&lt;p&gt;A noter que vous pouvez retrouver cet exemple et ceux des autres classes de cet article dans le &lt;strong&gt;SVN&lt;/strong&gt; de ASGard dans le répertoire &lt;a href=&quot;http://as-gard.googlecode.com/svn/trunk/AS3/trunk/examples/asgard/display/&quot;&gt;AS3/trunk/examples&lt;/a&gt; (ou de &lt;strong&gt;VEGAS&lt;/strong&gt; en external dans le répertoire &lt;strong&gt;AS3/trunk/bin/tests&lt;/strong&gt;).&lt;/p&gt;


&lt;h2&gt;3 - La classe asgard.display.TimelineIterator&lt;/h2&gt;


&lt;p&gt;Permet en se basant sur le &lt;strong&gt;design pattern Iterator&lt;/strong&gt; implémenté via une interface dans le package &lt;strong&gt;system.data&lt;/strong&gt; de parcourir facilement dans les 2 sens l'animation d'un &lt;strong&gt;MovieClip&lt;/strong&gt;. Comme si un MovieClip était une &lt;strong&gt;collection&lt;/strong&gt; d'image clé.&lt;/p&gt;


&lt;p&gt;La classe &lt;a href=&quot;http://code.google.com/p/as-gard/source/browse/trunk/AS3/trunk/src/asgard/display/TimelineIterator.as&quot;&gt;TimelineIterator&lt;/a&gt; prend la main par composition sur un &lt;strong&gt;MovieClip&lt;/strong&gt; et permet via les méthodes hasNext(), hasPrevious(), next() et previous() de naviguer facilement d'une image clé vers une autre.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Exemple :&lt;/strong&gt;&lt;/p&gt;

&lt;pre class=&quot;actionscript&quot;&gt;package examples
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0066CC;&quot;&gt;import&lt;/span&gt; asgard.&lt;span style=&quot;color: #006600;&quot;&gt;display&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;TimelineIterator&lt;/span&gt;;
&amp;nbsp;
    &lt;span style=&quot;color: #0066CC;&quot;&gt;import&lt;/span&gt; flash.&lt;span style=&quot;color: #006600;&quot;&gt;display&lt;/span&gt;.&lt;span style=&quot;color: #0066CC;&quot;&gt;MovieClip&lt;/span&gt;;
    &lt;span style=&quot;color: #0066CC;&quot;&gt;import&lt;/span&gt; flash.&lt;span style=&quot;color: #006600;&quot;&gt;display&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;Sprite&lt;/span&gt;;
    &lt;span style=&quot;color: #0066CC;&quot;&gt;import&lt;/span&gt; flash.&lt;span style=&quot;color: #006600;&quot;&gt;display&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;StageAlign&lt;/span&gt;;
    &lt;span style=&quot;color: #0066CC;&quot;&gt;import&lt;/span&gt; flash.&lt;span style=&quot;color: #006600;&quot;&gt;display&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;StageScaleMode&lt;/span&gt;;
    &lt;span style=&quot;color: #0066CC;&quot;&gt;import&lt;/span&gt; flash.&lt;span style=&quot;color: #006600;&quot;&gt;events&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;KeyboardEvent&lt;/span&gt;;
    &lt;span style=&quot;color: #0066CC;&quot;&gt;import&lt;/span&gt; flash.&lt;span style=&quot;color: #006600;&quot;&gt;ui&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;Keyboard&lt;/span&gt;;    
&amp;nbsp;
    &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**
      * Example with the asgard.display.TimelineIterator class.
      */&lt;/span&gt;
    &lt;span style=&quot;color: #0066CC;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;dynamic&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; TestTimelineIterator &lt;span style=&quot;color: #0066CC;&quot;&gt;extends&lt;/span&gt; Sprite
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #0066CC;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; TestTimelineIterator&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0066CC;&quot;&gt;stage&lt;/span&gt;.&lt;span style=&quot;color: #0066CC;&quot;&gt;align&lt;/span&gt;      = StageAlign.&lt;span style=&quot;color: #006600;&quot;&gt;TOP_LEFT&lt;/span&gt; ;
            &lt;span style=&quot;color: #0066CC;&quot;&gt;stage&lt;/span&gt;.&lt;span style=&quot;color: #0066CC;&quot;&gt;scaleMode&lt;/span&gt;  = StageScaleMode.&lt;span style=&quot;color: #006600;&quot;&gt;NO_SCALE&lt;/span&gt; ;
&amp;nbsp;
            &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;var&lt;/span&gt; mc:&lt;span style=&quot;color: #0066CC;&quot;&gt;MovieClip&lt;/span&gt; = getChildByName&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;mc&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; as &lt;span style=&quot;color: #0066CC;&quot;&gt;MovieClip&lt;/span&gt; ;
&amp;nbsp;
            it = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; TimelineIterator&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; mc , &lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
            &lt;span style=&quot;color: #0066CC;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;timeline current frame : &amp;quot;&lt;/span&gt; + it.&lt;span style=&quot;color: #006600;&quot;&gt;currentFrame&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
            &lt;span style=&quot;color: #0066CC;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;timeline total frames  : &amp;quot;&lt;/span&gt; + it.&lt;span style=&quot;color: #006600;&quot;&gt;totalFrames&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
            &lt;span style=&quot;color: #0066CC;&quot;&gt;stage&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; KeyboardEvent.&lt;span style=&quot;color: #006600;&quot;&gt;KEY_DOWN&lt;/span&gt; , keyDown &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0066CC;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;var&lt;/span&gt; it:TimelineIterator ;
&amp;nbsp;
        &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**
         * Invoked when key is down.
         */&lt;/span&gt;
        &lt;span style=&quot;color: #0066CC;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; keyDown&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;e&lt;/span&gt;:KeyboardEvent &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #0066CC;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;var&lt;/span&gt; code:uint = &lt;span style=&quot;color: #0066CC;&quot;&gt;e&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;keyCode&lt;/span&gt; ;
            &lt;span style=&quot;color: #b1b100;&quot;&gt;switch&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;code&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
            &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
                &lt;span style=&quot;color: #b1b100;&quot;&gt;case&lt;/span&gt; Keyboard.&lt;span style=&quot;color: #0066CC;&quot;&gt;LEFT&lt;/span&gt; :
                &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
                    &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; it.&lt;span style=&quot;color: #006600;&quot;&gt;hasPrevious&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
                    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
                        it.&lt;span style=&quot;color: #006600;&quot;&gt;previous&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
                    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
                    &lt;span style=&quot;color: #b1b100;&quot;&gt;else&lt;/span&gt;
                    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
                        it.&lt;span style=&quot;color: #006600;&quot;&gt;last&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
                    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
                    &lt;span style=&quot;color: #b1b100;&quot;&gt;break&lt;/span&gt; ;
                &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
                &lt;span style=&quot;color: #b1b100;&quot;&gt;case&lt;/span&gt; Keyboard.&lt;span style=&quot;color: #0066CC;&quot;&gt;RIGHT&lt;/span&gt; :
                &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
                    &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; it.&lt;span style=&quot;color: #006600;&quot;&gt;hasNext&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
                    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
                        it.&lt;span style=&quot;color: #006600;&quot;&gt;next&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
                    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
                    &lt;span style=&quot;color: #b1b100;&quot;&gt;else&lt;/span&gt;
                    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
                        it.&lt;span style=&quot;color: #006600;&quot;&gt;reset&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
                    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
                    &lt;span style=&quot;color: #b1b100;&quot;&gt;break&lt;/span&gt; ;
                &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
            &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
            &lt;span style=&quot;color: #0066CC;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;timeline : &amp;quot;&lt;/span&gt; + it.&lt;span style=&quot;color: #006600;&quot;&gt;currentFrame&lt;/span&gt; + &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot; | &amp;quot;&lt;/span&gt; + it.&lt;span style=&quot;color: #006600;&quot;&gt;totalFrames&lt;/span&gt; + &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot; | frame label : &amp;quot;&lt;/span&gt; + it.&lt;span style=&quot;color: #006600;&quot;&gt;currentLabel&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Pour contrôler le &lt;strong&gt;MovieClip&lt;/strong&gt; il suffit de créer une instance de type &lt;a href=&quot;http://code.google.com/p/as-gard/source/browse/trunk/AS3/trunk/src/asgard/display/TimelineIterator.as&quot;&gt;TimelineIterator&lt;/a&gt; avec un constructeur défini avec les arguments suivants&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; TimelineIterator&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;target&lt;/span&gt;:&lt;span style=&quot;color: #0066CC;&quot;&gt;MovieClip&lt;/span&gt; , framePosition:&lt;span style=&quot;color: #0066CC;&quot;&gt;Number&lt;/span&gt;=&lt;span style=&quot;color: #0066CC;&quot;&gt;NaN&lt;/span&gt;, stepSize:uint=&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Le premier argument &quot;&lt;strong&gt;target&lt;/strong&gt;&quot; permet de cibler le &lt;strong&gt;MovieClip&lt;/strong&gt;&lt;/p&gt;


&lt;p&gt;Le second argument &quot;&lt;strong&gt;framePosition&lt;/strong&gt;&quot; optionel permet de définir l'image clé sur laquelle on souhaite débuter l'itération. A noter que le &lt;strong&gt;TimelineIterator&lt;/strong&gt; se sert de la méthode &lt;strong&gt;gotoAndStop&lt;/strong&gt;() pour se déplacer dans l'animation d'un clip et en définissant un numéro d'image clé dans le constructeur de la classe permet donc de positionner tout de suite l'animation à l'image clé voulu et d'arrêter l'animation.&lt;/p&gt;


&lt;p&gt;Le troisième et dernier argument &quot;&lt;strong&gt;stepSize&lt;/strong&gt;&quot; optionel permet de changer la valeur des &quot;sauts&quot; entre une itération et une autre. Par défaut le saut est simplement d'une seule image clé mais dans certains cas il est possible d'augmenter cette valeur.&lt;/p&gt;


&lt;p&gt;Je vous invite à regarder de plus prêt la classe &lt;strong&gt;TimelineIterator&lt;/strong&gt; pour en découvrir toutes les propriétés et méthodes. Cette classe implémente l'interface &lt;strong&gt;system.data.OrderedIterator&lt;/strong&gt;.&lt;/p&gt;


&lt;h2&gt;4 - La classe asgard.display.TimelineScript&lt;/h2&gt;


&lt;p&gt;Permet d'injecter dans une image clé d'un &lt;strong&gt;MovieClip&lt;/strong&gt; une fonction en ciblant son numéro ou son nom d'étiquette.&lt;/p&gt;


&lt;p&gt;Cette classe ressemble beaucoup à la classe &lt;a href=&quot;http://code.google.com/p/as-gard/source/browse/trunk/AS3/trunk/src/asgard/display/TimelineInspector.as&quot;&gt;TimelineInspector&lt;/a&gt; mais permet de maitriser toutes les images clés d'un &lt;strong&gt;MovieClip&lt;/strong&gt;. La classe &lt;a href=&quot;http://code.google.com/p/as-gard/source/browse/trunk/AS3/trunk/src/asgard/display/TimelineInspector.as&quot;&gt;TimelineInspector&lt;/a&gt; diffuse uniquement des événements pendant la lecture des images clés possédant une étiquette.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Exemple :&lt;/strong&gt;&lt;/p&gt;

&lt;pre class=&quot;actionscript&quot;&gt;package examples
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0066CC;&quot;&gt;import&lt;/span&gt; asgard.&lt;span style=&quot;color: #006600;&quot;&gt;display&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;TimelineScript&lt;/span&gt;;
&amp;nbsp;
    &lt;span style=&quot;color: #0066CC;&quot;&gt;import&lt;/span&gt; flash.&lt;span style=&quot;color: #006600;&quot;&gt;display&lt;/span&gt;.&lt;span style=&quot;color: #0066CC;&quot;&gt;MovieClip&lt;/span&gt;;
    &lt;span style=&quot;color: #0066CC;&quot;&gt;import&lt;/span&gt; flash.&lt;span style=&quot;color: #006600;&quot;&gt;display&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;Sprite&lt;/span&gt;;
    &lt;span style=&quot;color: #0066CC;&quot;&gt;import&lt;/span&gt; flash.&lt;span style=&quot;color: #006600;&quot;&gt;display&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;StageAlign&lt;/span&gt;;
    &lt;span style=&quot;color: #0066CC;&quot;&gt;import&lt;/span&gt; flash.&lt;span style=&quot;color: #006600;&quot;&gt;display&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;StageScaleMode&lt;/span&gt;;
    &lt;span style=&quot;color: #0066CC;&quot;&gt;import&lt;/span&gt; flash.&lt;span style=&quot;color: #006600;&quot;&gt;events&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;MouseEvent&lt;/span&gt;;
    &lt;span style=&quot;color: #0066CC;&quot;&gt;import&lt;/span&gt; flash.&lt;span style=&quot;color: #006600;&quot;&gt;utils&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;setTimeout&lt;/span&gt;;    
&amp;nbsp;
    &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**
     * Example with the asgard.display.TimelineScript class.
     */&lt;/span&gt;
    &lt;span style=&quot;color: #0066CC;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;dynamic&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; TestTimelineScript &lt;span style=&quot;color: #0066CC;&quot;&gt;extends&lt;/span&gt; Sprite
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0066CC;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; TestTimelineScript&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
            &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// stage&lt;/span&gt;
&amp;nbsp;
            &lt;span style=&quot;color: #0066CC;&quot;&gt;stage&lt;/span&gt;.&lt;span style=&quot;color: #0066CC;&quot;&gt;align&lt;/span&gt;      = StageAlign.&lt;span style=&quot;color: #006600;&quot;&gt;TOP_LEFT&lt;/span&gt; ;
            &lt;span style=&quot;color: #0066CC;&quot;&gt;stage&lt;/span&gt;.&lt;span style=&quot;color: #0066CC;&quot;&gt;scaleMode&lt;/span&gt;  = StageScaleMode.&lt;span style=&quot;color: #006600;&quot;&gt;NO_SCALE&lt;/span&gt; ;
&amp;nbsp;
            &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// target&lt;/span&gt;
&amp;nbsp;
            mc               = getChildByName&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;mc&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; as &lt;span style=&quot;color: #0066CC;&quot;&gt;MovieClip&lt;/span&gt; ;
            mc.&lt;span style=&quot;color: #0066CC;&quot;&gt;useHandCursor&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;true&lt;/span&gt; ;
            mc.&lt;span style=&quot;color: #006600;&quot;&gt;buttonMode&lt;/span&gt;    = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;true&lt;/span&gt; ;
&amp;nbsp;
            mc.&lt;span style=&quot;color: #006600;&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; MouseEvent.&lt;span style=&quot;color: #006600;&quot;&gt;CLICK&lt;/span&gt; , click &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
            &lt;span style=&quot;color: #0066CC;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Click the movieclip to start the example.&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
            &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// timeline script&lt;/span&gt;
&amp;nbsp;
            &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;var&lt;/span&gt; ts:TimelineScript = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; TimelineScript&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; mc , &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;true&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
            ts.&lt;span style=&quot;color: #006600;&quot;&gt;put&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;begin&amp;quot;&lt;/span&gt;   , &lt;span style=&quot;color: #0066CC;&quot;&gt;start&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
            ts.&lt;span style=&quot;color: #006600;&quot;&gt;put&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;middle&amp;quot;&lt;/span&gt;  , &lt;span style=&quot;color: #0066CC;&quot;&gt;pause&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
            ts.&lt;span style=&quot;color: #006600;&quot;&gt;put&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;finish&amp;quot;&lt;/span&gt;  , finish &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0066CC;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;var&lt;/span&gt; mc:&lt;span style=&quot;color: #0066CC;&quot;&gt;MovieClip&lt;/span&gt; ;
&amp;nbsp;
        &lt;span style=&quot;color: #0066CC;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; click&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;e&lt;/span&gt;:MouseEvent &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #0066CC;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
            mc.&lt;span style=&quot;color: #0066CC;&quot;&gt;play&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0066CC;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;start&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #0066CC;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0066CC;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;start&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0066CC;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;pause&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #0066CC;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0066CC;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;pause&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
            mc.&lt;span style=&quot;color: #0066CC;&quot;&gt;stop&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
            setTimeout&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; mc.&lt;span style=&quot;color: #0066CC;&quot;&gt;play&lt;/span&gt; , &lt;span style=&quot;color: #cc66cc;&quot;&gt;4000&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// pause 4 s&lt;/span&gt;
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0066CC;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; finish&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;span style=&quot;color: #0066CC;&quot;&gt;void&lt;/span&gt;
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #0066CC;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;finish&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
            mc.&lt;span style=&quot;color: #0066CC;&quot;&gt;stop&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Comme la classe TimelineInspector la déclaration d'une instance de type TimelineScript est facile, il suffit de cibler un MovieClip en tapant simplement&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;var&lt;/span&gt; script:TimelineScript = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; TimelineScript&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; mc , &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;true&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;Le second argument optionel permet de lancer automatiquement la fonction stop() du clip sélectionné pour le mettre en pause. Ce paramètre est très pratique quand le graphiste n'a pas pris le temps de mettre de &lt;strong&gt;stop()&lt;/strong&gt; sur la première image clé d'un clip posé sur la scène principale par exemple. Il sera alors très simple de prendre la main sur un ou plusieurs clips et ainsi d'orchestrer leurs contenus correctement.&lt;/p&gt;


&lt;p&gt;A noter que les classes &lt;strong&gt;TimelineScript&lt;/strong&gt; et &lt;strong&gt;TimelineInspector&lt;/strong&gt; utilisent en internent la méthode &lt;strong&gt;addFrameScript&lt;/strong&gt; et qu'il est préférable de ne mettre aucun script dans les images clés du clip ciblé et bien entendu d'éviter d'utiliser la méthode &lt;strong&gt;addFrameScript&lt;/strong&gt; sur le clip, ce qui pourrait écraser les fonctionnalités injectées dans les &quot;&lt;strong&gt;helper&lt;/strong&gt;&quot; définis dans l'application.&lt;/p&gt;


&lt;p&gt;J'espère que ces 3 petites classes vous aideront dans vos applications et n'hésitez pas à me faire savoir quelles fonctionnalités vous aimeriez voir apparaitre par la suite dans ces classes ou dans le package &lt;strong&gt;asgard.display&lt;/strong&gt;.&lt;/p&gt;</description>
    
    
    
          <comments>http://www.ekameleon.net/blog/index.php?post/2009/03/29/Controler-la-timeline-de-vos-animations#comment-form</comments>
      <wfw:comment>http://www.ekameleon.net/blog/index.php?post/2009/03/29/Controler-la-timeline-de-vos-animations#comment-form</wfw:comment>
      <wfw:commentRss>http://www.ekameleon.net/blog/index.php?feed/rss2/comments/115</wfw:commentRss>
      </item>
    
  <item>
    <title>Font case sensitive in MAC OSX</title>
    <link>http://www.ekameleon.net/blog/index.php?post/2009/02/07/Font-case-sensitive-in-MAC-OSX</link>
    <guid isPermaLink="false">urn:md5:7148ed7c2622ec28fd2a9f76acb2b0b1</guid>
    <pubDate>Sat, 07 Feb 2009 23:20:00 +0100</pubDate>
    <dc:creator>eKameleon</dc:creator>
        <category>Flash</category>
            
    <description>&lt;p&gt;Petite remarque à propos des polices de caractères sur MACOS X dans Flash.&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://www.ekameleon.net/blog/public/images/divers/mac_flash_fonts.jpg&quot; alt=&quot;MAC fonts case sensitive&quot; style=&quot;float:left; margin: 0 1em 1em 0;&quot; /&gt; J'ai la chance depuis une petite semaine de travailler sous MAC OSX avec un tout nouveau MacBook Pro, c'est mon premier MAC donc je suis un peu comme un gosse qui découvre un nouveau joujou... Il m'a fallu tout se temps pour me mettre sur &lt;strong&gt;MAC&lt;/strong&gt; et franchement là je peux dire qu'il n'y a rien à regretter. Quelques habitudes sur de longues années sur &lt;strong&gt;Windows&lt;/strong&gt; sont encore à perdre mais le bilan reste à l'heure actuelle vraiment largement positif (bien plus que je ne l'espérais).&lt;/p&gt;


&lt;p&gt;Reste que le passage d'un &lt;strong&gt;Windows XP&lt;/strong&gt; vers un &lt;strong&gt;MAC OSX&lt;/strong&gt; est une grosse claque au niveau ergonomie, souplesse de l'&lt;strong&gt;OS&lt;/strong&gt; et des applications, et des possibilités (terminal en ligne de commande intégré, SVN, ANT, etc.. déjà installé, etc..).. Maintenant des choses sont vraiment différentes et il est clair qu'à l'heure actuelle pour intégrer convenablement une application Flash (que cela soit pour le FlashPlayer mais aussi pour AIR) il faut absolument avoir un système permettant de tester son code, et le rendu d'un projet sous plusieurs OS sous peine de réaliser après tout ce temps que l'on traine derrière soit des dommages collatéraux assez énormes&amp;nbsp;!&lt;/p&gt;


&lt;p&gt;Bon donc pour en revenir au sujet de ce ticket, je me suis rendu compte (super rapidement) que le nom des polices de caractères utilisées dans Flash (ou Flex, c'est pareil..) définies dans les feuilles de style ou dans les objets de type &lt;strong&gt;flash.text.TextFormat&lt;/strong&gt; doivent absolument respecter la sensibilité de la casse des caractères.&lt;/p&gt;


&lt;p&gt;Exemple simple de code dans Flash pour illustrer le petit problème rencontré&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;var&lt;/span&gt; field:&lt;span style=&quot;color: #0066CC;&quot;&gt;TextField&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;TextField&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
field.&lt;span style=&quot;color: #006600;&quot;&gt;defaultTextFormat&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;TextFormat&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;arial&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;14&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
field.&lt;span style=&quot;color: #006600;&quot;&gt;x&lt;/span&gt;    = &lt;span style=&quot;color: #cc66cc;&quot;&gt;10&lt;/span&gt; ;
field.&lt;span style=&quot;color: #006600;&quot;&gt;y&lt;/span&gt;    = &lt;span style=&quot;color: #cc66cc;&quot;&gt;10&lt;/span&gt; ;
field.&lt;span style=&quot;color: #0066CC;&quot;&gt;text&lt;/span&gt; = &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;hello world&amp;quot;&lt;/span&gt; ;
&amp;nbsp;
addChild&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; field &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;Si l'on compile l'exemple précédent et que nous utilisons un FlashPlayer sous Windows, pas de soucis la police est bien prise en compte. Alors que si l'on utilise un swf généré avec le code ci-dessus par exemple dans le FlashPlayer 10 MAC OSX, la police n'est pas prise en compte et c'est la police système par défaut (Times je crois) qui est utilisée.&lt;/p&gt;    &lt;p&gt;Donc pour corriger le tire il faut regarder par exemple dans Flash le panneau de propriété des champs de texte et bien noter le nom exacte (à la majuscule et minuscule près de la font utilisée&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;var&lt;/span&gt; field:&lt;span style=&quot;color: #0066CC;&quot;&gt;TextField&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;TextField&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
field.&lt;span style=&quot;color: #006600;&quot;&gt;defaultTextFormat&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;TextFormat&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Arial&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;14&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
field.&lt;span style=&quot;color: #006600;&quot;&gt;x&lt;/span&gt;    = &lt;span style=&quot;color: #cc66cc;&quot;&gt;10&lt;/span&gt; ;
field.&lt;span style=&quot;color: #006600;&quot;&gt;y&lt;/span&gt;    = &lt;span style=&quot;color: #cc66cc;&quot;&gt;10&lt;/span&gt; ;
field.&lt;span style=&quot;color: #0066CC;&quot;&gt;text&lt;/span&gt; = &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;hello world&amp;quot;&lt;/span&gt; ;
&amp;nbsp;
addChild&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; field &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;&lt;strong&gt;Remarque :&lt;/strong&gt; j'ai trouvé sur Google un lien vers le JIRA de Adobe qui concerne ce &quot;bug&quot; (je ne sais pas si c'est un bug sur MAC ou plutöt sur Windows du coup... à mon sens c'est bien que les fonts soit case sensitive &lt;img src=&quot;/blog/themes/default/smilies/smile.png&quot; alt=&quot;:)&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://bugs.adobe.com/jira/secure/attachment/16927/16927_SDK-14324_Mac.jpg&quot; hreflang=&quot;en&quot;&gt;Font names are case sensitive on Macintosh&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Maintenant le swf peut être consulté correctement aussi bien sur &lt;strong&gt;OSX&lt;/strong&gt; que sur &lt;strong&gt;Windows&lt;/strong&gt;. Me reste à installer ce week-end une virtual machine pour tester cela sur Linux &lt;img src=&quot;/blog/themes/default/smilies/wink.png&quot; alt=&quot;;)&quot; class=&quot;smiley&quot; /&gt; Cette virtual machine se servira à coup sûr pour installer Flash Media Interactive Server et devenir totalement indépendant de mon ancien PC qui tire vraiment la tronche mais il m'a fait subir ces derniers mois des crise de colère tellement intense qu'il est vraiment temps que je passe à autre chose. Notre séparation est vraiment indispensable et je ne pense vraiment pas que Windows 7 me refera venir vers Windows de si tôt &lt;img src=&quot;/blog/themes/default/smilies/smile.png&quot; alt=&quot;:)&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;


&lt;p&gt;Je reste persuadé que les ingénieurs et développeurs de Windows chez Microsoft devraient discuter un peu avec les développeurs qui travaillent sur la XBOX 360 .. lol Mais bon je veux pas non plus cracher sur mes années DOS et Windows... j'ai passé des bons moment sur cet OS (si si ...) mais pour le travail et nos besoins actuels (profession qui nécessite de plus en plus de technicité) les MAC deviennent le produit indispensable pour bosser. Un peu comme à l'époque quand je rêvais d'avoir une Sillycon Graphics.. à l'heure actuelle les MAC proposent un environnement de travail de rêve pour tout développeur qui se respecte... Travailler avec 9 écrans virtuels (space) sur 2 écran en simultané (donc 18 écrans) .. Cela change une vie lol&lt;/p&gt;


&lt;p&gt;Bref... j'ai pas envie de rentrer ici dans le débat bien connu qui tourne autour de la guerre MAC/PC mais je voulais juste vous donner un peu mon impression face à ce système d'exploitation et ce matériel qui reste cher mais au combien bien pensé&amp;nbsp;!&lt;/p&gt;</description>
    
    
    
          <comments>http://www.ekameleon.net/blog/index.php?post/2009/02/07/Font-case-sensitive-in-MAC-OSX#comment-form</comments>
      <wfw:comment>http://www.ekameleon.net/blog/index.php?post/2009/02/07/Font-case-sensitive-in-MAC-OSX#comment-form</wfw:comment>
      <wfw:commentRss>http://www.ekameleon.net/blog/index.php?feed/rss2/comments/114</wfw:commentRss>
      </item>
    
  <item>
    <title>D - Chargement de ressources externes ( Partie 4 - config )</title>
    <link>http://www.ekameleon.net/blog/index.php?post/2009/01/01/D-Chargement-de-ressources-externes-Partie-4-config</link>
    <guid isPermaLink="false">urn:md5:7ac29bdcb539c96d043e7e85b2c329b1</guid>
    <pubDate>Thu, 01 Jan 2009 12:12:00 +0100</pubDate>
    <dc:creator>eKameleon</dc:creator>
        <category>VEGAS</category>
        <category>andromedas</category><category>config</category><category>design_pattern</category><category>framework</category><category>IoC</category><category>vegas</category>    
    <description>&lt;h3&gt;Très bonne année 2009 et surtout bonne santé !!&lt;/h3&gt;


&lt;p&gt;Je commence donc cette année avec l'avant dernier article du chapitre D sur les ressources externes des fichiers de configuration d'une fabrique IoC &lt;img src=&quot;/blog/themes/default/smilies/smile.png&quot; alt=&quot;:)&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;


&lt;p&gt;J'aurai pu faire un simple petit article classique mais je préfère faire d'une pierre deux coups &lt;img src=&quot;/blog/themes/default/smilies/wink.png&quot; alt=&quot;;)&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;


&lt;p&gt;J'espère que cette année &lt;strong&gt;2009&lt;/strong&gt; me laissera le temps de continuer mon travail sur la v&lt;strong&gt;ersion 2&lt;/strong&gt; de &lt;strong&gt;VEGAS&lt;/strong&gt; avec la fusion dans &lt;strong&gt;Maashaack&lt;/strong&gt; de la plupart des packages &lt;strong&gt;system.events&lt;/strong&gt;, &lt;strong&gt;system.process&lt;/strong&gt; et &lt;strong&gt;system.ioc&lt;/strong&gt;&amp;nbsp;!&lt;/p&gt;


&lt;p&gt;Sinon la bonne résolution pour &lt;strong&gt;2009&lt;/strong&gt; c'est de débuter le projet de &lt;strong&gt;GUI AIR&lt;/strong&gt; pour créer des RIA facilement basé sur &lt;strong&gt;eden&lt;/strong&gt; et &lt;strong&gt;IoC&lt;/strong&gt; + un petit projet qui me tiens à coeur avec &lt;strong&gt;Zwetan&lt;/strong&gt; ... un projet de flibustier et qui sent bon le bateau en pleine mer ou dans l'espace ??... enfin je me comprends lol&lt;/p&gt;


&lt;p&gt;Je tiens à remercier tous ceux qui m'ont aidés pendant 2008 et qui ont encore le courage de le faire cette nouvelle année pour faire avancer le projet &lt;img src=&quot;/blog/themes/default/smilies/wink.png&quot; alt=&quot;;)&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;PS&amp;nbsp;: Pour ma part j'attends en 2009 des news importantes sur le futur de l'ActionScript avec AS4 !&lt;/strong&gt;&lt;/p&gt;


&lt;p&gt;Je peux maintenant vous laisser le temps pour lire ce nouvel article sur les ressources de type &quot;config&quot;. Bonne lecture à tous &lt;img src=&quot;/blog/themes/default/smilies/smile.png&quot; alt=&quot;:)&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;    &lt;h3&gt;7 - Les ressources de type &quot;config&quot; (configuration)&lt;/h3&gt;


&lt;h4&gt;7-1 . La classe andromeda.config.Config&lt;/h4&gt;


&lt;p&gt;Nous avons vu un peu plus haut dans le &lt;strong&gt;chapitre C-1.1&lt;/strong&gt; qu'il est possible de définir dans la configuration d'une fabrique &lt;strong&gt;IoC&lt;/strong&gt; un objet &quot;&lt;strong&gt;config&lt;/strong&gt;&quot; de configuration simple qui permet ensuite de récupérer les valeurs de certaines variables dans les différentes &lt;strong&gt;définitions d'objet&lt;/strong&gt; d'un conteneur &lt;strong&gt;IoC&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;Dans le cadre d'un chargement d'une configuration externe (context &lt;strong&gt;IoC&lt;/strong&gt;) l'objet de configuration de la fabrique cible un singleton dynamique de type &lt;strong&gt;andromeda.config.Config&lt;/strong&gt; qui servira à la fois d'objet de configuration dans les définitions d'objet du conteneur &lt;strong&gt;IoC&lt;/strong&gt; mais aussi de configuration globale dans l'application en ciblant à tout moment cet objet avec l'instruction suivante&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; andromeda.config.Config ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; config&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Config = Config.getInstance&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;La classe &lt;a href=&quot;http://www.ekameleon.net/vegas/docs/andromeda/config/Config.html&quot;&gt;andromeda.config.Config&lt;/a&gt; est dynamique et il est donc possible de définir sur une de ses instances tous les attributs nécessaires pour configurer l'application.&lt;/p&gt;


&lt;p&gt;Voici un exemple simple d'utilisation de cette classe et de son singleton&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.text&lt;/span&gt;.&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;*&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; andromeda.config.Config ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;init&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Object&lt;/span&gt; = 
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    header &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt;    &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;CONFIG TEST&amp;quot;&lt;/span&gt; , 
        &lt;span style=&quot;color: #004993;&quot;&gt;version&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;1.0.0.0&amp;quot;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    ,
    views &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        field &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #004993;&quot;&gt;autoSize&lt;/span&gt;          &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;left&amp;quot;&lt;/span&gt; ,
            &lt;span style=&quot;color: #004993;&quot;&gt;defaultTextFormat&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;TextFormat&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;Arial&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;14&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ,
            &lt;span style=&quot;color: #004993;&quot;&gt;text&lt;/span&gt;              &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;hello world&amp;quot;&lt;/span&gt; ,
            &lt;span style=&quot;color: #004993;&quot;&gt;textColor&lt;/span&gt;         &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; 0x3C4DDD ,
            &lt;span style=&quot;color: #004993;&quot;&gt;x&lt;/span&gt;                 &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;10&lt;/span&gt; ,
            &lt;span style=&quot;color: #004993;&quot;&gt;y&lt;/span&gt;                 &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight:bold;&quot;&gt;10&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; conf&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Config = Config.getInstance&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #009900;&quot;&gt;// Initialize the dynamic configuration with a dynamic object.&lt;/span&gt;
&amp;nbsp;
conf.&lt;span style=&quot;color: #004993;&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;init&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #009900;&quot;&gt;// target valuers with the dot notation or the get() method.&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;conf.header.name           : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; conf.header.&lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;conf.get('header.version') : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; conf.&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;'header.version'&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #009900;&quot;&gt;// initialize an object in the application with the init() method&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; field&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;TextField&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;TextField&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&lt;span style=&quot;color: #004993;&quot;&gt;addChild&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; field &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
conf.&lt;span style=&quot;color: #004993;&quot;&gt;init&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; field , &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;views.field&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;Nous noterons dans l'exemple précédent l'utilisation des méthodes&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;get()&lt;/strong&gt;&amp;nbsp;: Cette méthode utilise en interne un objet de type &lt;a href=&quot;http://www.ekameleon.net/vegas/docs/system/evaluators/PropertyEvaluator.html&quot;&gt;system.evaluators.PropertyEvaluator&lt;/a&gt; pour évaluer le paramètre envoyé et pour récupérer dans la config la valeur désirée. Si l'identifiant est null ou qu'il ne correspond à aucune propriété définie dans la config alors la méthode renvoie &quot;&lt;strong&gt;null&lt;/strong&gt;&quot;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;init()&lt;/strong&gt;&amp;nbsp;: Cette méthode permet d'initialiser un objet en lui attribuant membre à membre les propriétés définies dans la config ou dans une propriété en particulier définie dans la config. Comme pour la méthode &lt;strong&gt;get(id:String)&lt;/strong&gt;, il est possible de passer dans le second paramètre de la fonction un identifiant (&lt;strong&gt;String&lt;/strong&gt;) qui sera évalué et qui permet de localiser précisément un sous objet défini dans la config.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;map()&lt;/strong&gt;&amp;nbsp;: Cette méthode permet d'initialiser la config avec un objet générique dynamique simple.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;7-2 . L'interface andromeda.config.IConfigLoader&lt;/h4&gt;


&lt;p&gt;La classe andromeda.config.Config et son singleton sont donc très pratique surtout si on les combine avec une classe qui implémente l'interface &lt;a href=&quot;http://www.ekameleon.net/vegas/docs/andromeda/config/IConfigLoader.html&quot;&gt;andromeda.config.IConfigLoader&lt;/a&gt; . Cette interface permet de définir des chargeurs de configurations externes (au format &lt;strong&gt;eden&lt;/strong&gt;, &lt;strong&gt;JSON&lt;/strong&gt;, etc..)&lt;/p&gt;


&lt;p&gt;Nous pouvons retrouver dans le package &lt;strong&gt;andromeda.config.*&lt;/strong&gt; les 2 classes qui implémentent pour le moment cette interface&amp;nbsp;: &lt;a href=&quot;http://www.ekameleon.net/vegas/docs/andromeda/config/EdenConfigLoader.html&quot;&gt;EdenConfigLoader&lt;/a&gt; et &lt;a href=&quot;http://www.ekameleon.net/vegas/docs/andromeda/config/JSONConfigLoader.html&quot;&gt;JSONConfigLoader&lt;/a&gt;. Il est ensuite tout à fait possible d'implémenter d'autres types de chargeur de configuration basé sur le format &lt;strong&gt;XML&lt;/strong&gt; ou autres en se basant sur l'implémentation de ces 2 classes.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Exemple d'utilisation :&lt;/strong&gt;&lt;/p&gt;


&lt;p&gt;Création d'un fichier texte &lt;strong&gt;UTF8&lt;/strong&gt; externe &quot;&lt;strong&gt;config.eden&lt;/strong&gt;&quot; qui contient la chaine de caractère suivante&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;header = 
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #004993;&quot;&gt;name&lt;/span&gt;      &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;CONFIG EDEN TEST&amp;quot;&lt;/span&gt; , 
    &lt;span style=&quot;color: #004993;&quot;&gt;namespace&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;andromeda.config&amp;quot;&lt;/span&gt; ,
    &lt;span style=&quot;color: #004993;&quot;&gt;version&lt;/span&gt;   &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;1.0.0.0&amp;quot;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; ; 
&amp;nbsp;
security = 
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt; 
    &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;http://code.google.com/p/vegas/&amp;quot;&lt;/span&gt; ,
    &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;http://www.ekameleon.net/&amp;quot;&lt;/span&gt; , 
    &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;http://groups.google.com/group/vegasos&amp;quot;&lt;/span&gt; 
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt; ; 
&amp;nbsp;
default_lang = &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;fr&amp;quot;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;Utilisation simple de la classe &lt;strong&gt;EdenConfigLoader&lt;/strong&gt; dans un script &lt;strong&gt;AS3&lt;/strong&gt; classique&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; andromeda.config.Config ;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; andromeda.config.EdenConfigLoader;
&amp;nbsp;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; andromeda.events.ActionEvent ;
&amp;nbsp;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;flash.events&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;Event&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; debug&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Function&lt;/span&gt; = &lt;span style=&quot;color: #339966; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; e&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;Event&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;void&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
    &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; e &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
    &lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;Config = Config.getInstance&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
    &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; prop&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
       &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;# &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; prop &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot; : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;prop&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
       &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;prop&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;Object&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
       &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
           &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; key&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #004993;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;prop&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; 
           &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
               &lt;span style=&quot;color: #004993;&quot;&gt;trace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;  - &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; key &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot; : &amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;prop&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;key&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
           &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
       &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
   &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;loader&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;EdenConfigLoader = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; EdenConfigLoader&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;loader&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; ActionEvent.FINISH , debug&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;loader&lt;/span&gt;.run&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;h4&gt;7-3 . Contenu de l'objet générique qui permet de définir la ressource de type &quot;config&quot;.&lt;/h4&gt;


&lt;p&gt;Les ressources de type &quot;&lt;strong&gt;config&lt;/strong&gt;&quot; permettent donc de charger un ou plusieurs fichier de configuration (par défaut au format &lt;strong&gt;eden&lt;/strong&gt;) qui contiennent des variables qui seront utilisées par la suite dans les &lt;strong&gt;définitions d'objet&lt;/strong&gt; de la fabrique mais aussi directement dans l'application en ciblant le singleton &lt;strong&gt;Config.getInstance()&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;Regardons la signature minimale de l'objet générique qu'il est possible de définir dans l'attribut &quot;imports&quot; pour charger une ressource de type &quot;&lt;strong&gt;config&lt;/strong&gt;&quot;&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; 
    resource : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;config&amp;quot;&lt;/span&gt;  , 
    &lt;span style=&quot;color: #0066CC;&quot;&gt;type&lt;/span&gt;     : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;config&amp;quot;&lt;/span&gt;  , 
    verbose  : &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;true&lt;/span&gt; 
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Dans cet objet générique il est possible de d'utiliser les attributs suivant&amp;nbsp;:&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Attributs obligatoires :&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;resource&lt;/strong&gt;&amp;nbsp;: indique le nom (sans l'extension) du fichier que l'on souhaite charger (obligatoire)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;type&lt;/strong&gt;&amp;nbsp;: indispensable pour indiquer au chargeur que la ressource est de type &quot;config&quot;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Attributs optionnels :&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;loader&lt;/strong&gt;&amp;nbsp;: Représente directement une référence vers une classe de type IConfigLoader ou une chaine de caractère qui représente le nom complet d'une classe de type IConfigLoader.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;path&lt;/strong&gt;&amp;nbsp;: indique le chemin du fichier à charger (exemple&amp;nbsp;: path:&quot;config/&quot; ).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;suffix&lt;/strong&gt;&amp;nbsp;: Représente le nom de l'extension utilisée pour charger le fichier de configuration, par défaut cette extension a pour valeur la chaine de caractère&amp;nbsp;: &quot;.eden&quot;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;verbose&lt;/strong&gt;&amp;nbsp;: un booléean qui active le mode debug de la ressource en cas de problème.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A noter que l'attribut &quot;loader&quot; permet de remplacer la classe EdenConfigLoader utilisée par défaut par la ressource pour chager le fichier de configuration externe. Il sera donc possible en cas de besoin d'utiliser un autre type de chargeur de configuration (&lt;strong&gt;JSON&lt;/strong&gt;, &lt;strong&gt;XML&lt;/strong&gt;, etc...)&lt;/p&gt;


&lt;h4&gt;7-4 . Exemple d'utilisation d'une ressource de type &quot;config&quot;&lt;/h4&gt;


&lt;p&gt;Il faut tout d'abord créer un fichier texte UTF8 de configuration &quot;&lt;strong&gt;config.eden&lt;/strong&gt;&quot; que l'on place dans un répertoire &lt;strong&gt;config/&lt;/strong&gt; qui contient les variables suivantes&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript&quot;&gt;display =
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
   filters : 
   &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt; 
        &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; flash.&lt;span style=&quot;color: #006600;&quot;&gt;filters&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;DropShadowFilter&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;4&lt;/span&gt;,&lt;span style=&quot;color: #cc66cc;&quot;&gt;75&lt;/span&gt;,0x000000,&lt;span style=&quot;color: #cc66cc;&quot;&gt;0.8&lt;/span&gt;,&lt;span style=&quot;color: #cc66cc;&quot;&gt;12&lt;/span&gt;,&lt;span style=&quot;color: #cc66cc;&quot;&gt;12&lt;/span&gt;,&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #cc66cc;&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; 
   &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; 
&amp;nbsp;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;;
&amp;nbsp;
field =
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0066CC;&quot;&gt;autoSize&lt;/span&gt;          : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;left&amp;quot;&lt;/span&gt; ,
    defaultTextFormat : &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; flash.&lt;span style=&quot;color: #0066CC;&quot;&gt;text&lt;/span&gt;.&lt;span style=&quot;color: #0066CC;&quot;&gt;TextFormat&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Arial&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;14&lt;/span&gt;, 0xEEED2B&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ,
    &lt;span style=&quot;color: #0066CC;&quot;&gt;text&lt;/span&gt;              : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;hello world&amp;quot;&lt;/span&gt; ,
    x                 : &lt;span style=&quot;color: #cc66cc;&quot;&gt;25&lt;/span&gt; ,
    y                 : &lt;span style=&quot;color: #cc66cc;&quot;&gt;25&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;;&lt;/pre&gt;


&lt;p&gt;Ensuite il suffit de créer un fichier de configuration &quot;&lt;a href=&quot;http://code.google.com/p/as-gard/source/browse/trunk/AS3/trunk/examples/asgard/net/deploy/context/application_config_resource.eden&quot;&gt;context/application_config_resource.eden&lt;/a&gt;&quot; au format eden avec les définitions d'objet et la ressource de type &quot;&lt;strong&gt;config&lt;/strong&gt;&quot; indispensable pour charger le fichier ci-dessus et créer le contenu de l'application&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript&quot;&gt;imports =
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; resource : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;config&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #0066CC;&quot;&gt;type&lt;/span&gt; : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;config&amp;quot;&lt;/span&gt; , path : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;config/&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; ;
&amp;nbsp;
objects =
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
        id   : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;field&amp;quot;&lt;/span&gt; ,
        &lt;span style=&quot;color: #0066CC;&quot;&gt;type&lt;/span&gt; : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;flash.text.TextField&amp;quot;&lt;/span&gt; ,
        properties :
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;
            &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;name&lt;/span&gt; : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;autoSize&amp;quot;&lt;/span&gt;          , config : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;field.autoSize&amp;quot;&lt;/span&gt;          &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; ,
            &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;name&lt;/span&gt; : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;defaultTextFormat&amp;quot;&lt;/span&gt; , config : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;field.defaultTextFormat&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; ,
            &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;name&lt;/span&gt; : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;filters&amp;quot;&lt;/span&gt;           , config : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;display.filters&amp;quot;&lt;/span&gt;         &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; ,
            &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;name&lt;/span&gt; : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;text&amp;quot;&lt;/span&gt;              , config : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;field.text&amp;quot;&lt;/span&gt;              &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; ,
            &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;name&lt;/span&gt; : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;x&amp;quot;&lt;/span&gt;                 , config : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;field.x&amp;quot;&lt;/span&gt;                 &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; ,
            &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;name&lt;/span&gt; : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;y&amp;quot;&lt;/span&gt;                 , config : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;field.y&amp;quot;&lt;/span&gt;                 &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; 
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
    ,
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
        id               : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;application&amp;quot;&lt;/span&gt; ,
        &lt;span style=&quot;color: #0066CC;&quot;&gt;type&lt;/span&gt;             : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;flash.display.MovieClip&amp;quot;&lt;/span&gt; ,
        factoryReference : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;#root&amp;quot;&lt;/span&gt; ,
        singleton        : &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;true&lt;/span&gt; ,
        properties       :
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;
            &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;name&lt;/span&gt; : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;addChild&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #0066CC;&quot;&gt;arguments&lt;/span&gt; : &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; ref : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;field&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; 
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Pour finir il suffit de taper le code &lt;strong&gt;AS3&lt;/strong&gt; suivant&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript3&quot;&gt;&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; asgard.net.ECMAObjectLoader ;
&lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;import&lt;/span&gt; system.eden ;
&amp;nbsp;
&lt;span style=&quot;color: #009900;&quot;&gt;// Authorizes the TextFormat class in the white list of eden&lt;/span&gt;
&amp;nbsp;
eden.addAuthorized&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;flash.filters.*&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
eden.addAuthorized&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;flash.text.TextFormat&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #009900;&quot;&gt;// Initialize and launch the IoC factory loader.&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #6699cc; font-weight: bold;&quot;&gt;var&lt;/span&gt; &lt;span style=&quot;color: #004993;&quot;&gt;loader&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;:&lt;/span&gt;ECMAObjectLoader = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;new&lt;/span&gt; ECMAObjectLoader&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;application_config_resource.eden&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #990000;&quot;&gt;&amp;quot;context/&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;loader&lt;/span&gt;.&lt;span style=&quot;color: #004993;&quot;&gt;root&lt;/span&gt; = &lt;span style=&quot;color: #0033ff; font-weight: bold;&quot;&gt;this&lt;/span&gt; ;
&amp;nbsp;
&lt;span style=&quot;color: #004993;&quot;&gt;loader&lt;/span&gt;.run&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;&lt;strong&gt;Remarque :&lt;/strong&gt; Il est possible de charger plusieurs fichiers de configurations externe dans un même objet générique &quot;imports&quot;&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript&quot;&gt;imports =
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; resource : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;config2&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #0066CC;&quot;&gt;type&lt;/span&gt; : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;config&amp;quot;&lt;/span&gt; , path : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;config/&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; ,
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; resource : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;config1&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #0066CC;&quot;&gt;type&lt;/span&gt; : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;config&amp;quot;&lt;/span&gt; , path : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;config/&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; ;&lt;/pre&gt;


&lt;p&gt;Cette technique permet de diviser le contenu d'une configuration un peu trop grosse mais aussi de gérer plus finement le remplissage de la configuration selon les besoins. A noter qu'une propriété définie avec le même nom dans plusieurs fichiers de configuration externes sera écrasé et prendra la valeur du dernier fichier chargé.&lt;/p&gt;


&lt;p&gt;Le moteur de chargement des ressources externes est basé sur un système de &lt;strong&gt;stack LIFO (Last in First Out)&lt;/strong&gt; qui impose dans l'exemple ci-dessus que les fichiers &quot;&lt;strong&gt;config/config1.eden&lt;/strong&gt;&quot; et &quot;&lt;strong&gt;config/config2.eden&lt;/strong&gt;&quot; soient chargés dans le sens inverse de l'ordre naturel de remplissage de la liste &quot;&lt;strong&gt;imports&lt;/strong&gt;&quot; de type Array.  Il faudra donc faire attention à bien déclarer dans le bon ordre les différentes ressources de type &quot;config&quot;.&lt;/p&gt;


&lt;h2&gt;Liens&lt;/h2&gt;


&lt;p&gt;Pour ceux qui découvrent dans cet article le design pattern d'Inversion de contrôle avec &lt;strong&gt;VEGAS&lt;/strong&gt; et qui n'ont pas eu encore le temps de consulter les articles précédents, voici une liste rapide des derniers articles à lire avant d'entamer celui-ci&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.ekameleon.net/blog/index.php?post/2008/07/21/A-Design-Pattern-dinversion-de-controle-Generalites&quot;&gt;A - Design Pattern d'inversion de contrôle - Généralités&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.ekameleon.net/blog/index.php?post/2008/08/01/B-Les-definitions-dobjets-1-5&quot;&gt;B - Les définitions d'objets (Partie - 1/5)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.ekameleon.net/blog/index.php?post/2008/08/02/B-Les-definitions-dobjets-2-5&quot;&gt;B - Les définitions d'objets (Partie - 2/5)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.ekameleon.net/blog/index.php?post/2008/08/08/B-Les-definitions-dobjets-3-5&quot;&gt;B - Les définitions d'objets (Partie - 3/5)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.ekameleon.net/blog/index.php?post/2008/08/08/B-Les-definitions-dobjets-4-5&quot;&gt;B - Les définitions d'objets (Partie - 4/5)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.ekameleon.net/blog/index.php?post/2008/08/14/B-Les-definitions-dobjets-5-5&quot;&gt;B - Les définitions d'objets (Partie - 5/5)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.ekameleon.net/blog/index.php?post/2008/09/12/C-Configuration-dune-fabrique-IoC&quot;&gt;C - Configuration d'une fabrique IoC&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.ekameleon.net/blog/index.php?post/2008/11/30/D-Chargement-de-ressources-externes-Partie-1&quot;&gt;D - Chargement de ressources externes ( Partie 1 )&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.ekameleon.net/blog/index.php?post/2008/12/07/D-Chargement-de-ressources-externes-Partie-2&quot;&gt;D - Chargement de ressources externes ( Partie 2 )&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Article Précédent&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.ekameleon.net/blog/index.php?post/2008/12/13/D-Chargement-de-ressources-externes-Partie-3&quot;&gt;D - Chargement de ressources externes ( Partie 3 )&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Article Suivant&lt;/strong&gt;&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Les ressources de type &quot;i18n&quot; (très bientôt)&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;</description>
    
    
    
          <comments>http://www.ekameleon.net/blog/index.php?post/2009/01/01/D-Chargement-de-ressources-externes-Partie-4-config#comment-form</comments>
      <wfw:comment>http://www.ekameleon.net/blog/index.php?post/2009/01/01/D-Chargement-de-ressources-externes-Partie-4-config#comment-form</wfw:comment>
      <wfw:commentRss>http://www.ekameleon.net/blog/index.php?feed/rss2/comments/113</wfw:commentRss>
      </item>
    
  <item>
    <title>D - Chargement de ressources externes ( Partie 3 )</title>
    <link>http://www.ekameleon.net/blog/index.php?post/2008/12/13/D-Chargement-de-ressources-externes-Partie-3</link>
    <guid isPermaLink="false">urn:md5:40aaf5f4ab65b1747b6c83d56dc4ef6e</guid>
    <pubDate>Sat, 13 Dec 2008 11:43:00 +0100</pubDate>
    <dc:creator>eKameleon</dc:creator>
        <category>VEGAS</category>
        <category>andromedas</category><category>as3</category><category>css</category><category>design_pattern</category><category>ecmascript</category><category>eden</category><category>flash</category><category>fonts</category><category>io</category><category>IoC</category><category>style</category><category>vegas</category><category>xml</category>    
    <description>&lt;h3&gt;Petite introduction&lt;/h3&gt;


&lt;p&gt;Avec la 3ème partie de ce chapitre nous allons étudier l'utilisation des ressources de type &quot;font&quot;, &quot;style&quot; et &quot;xml&quot; dans les fichiers de configuration d'une fabrique IoC basée sur VEGAS et son extension AndromedAS. Ces 3 types de ressources vont vous simplifier la vie pour mettre en place vos applications.&lt;/p&gt;


&lt;p&gt;Bonne lecture à tous &lt;img src=&quot;/blog/themes/default/smilies/smile.png&quot; alt=&quot;:)&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;


&lt;h3&gt;4 - Les ressources de type &quot;style&quot;&lt;/h3&gt;


&lt;p&gt;Cette ressource permet de charger un ou plusieurs fichiers texte contenant une feuille de style au format &lt;strong&gt;CSS&lt;/strong&gt; qui permettra de définir le style des champs de texte dynamiques d'une application. Cette ressource permet en même temps de créer dans la fabrique &lt;strong&gt;IoC&lt;/strong&gt; une définition d'objet qui servira de référence singleton pour utiliser par la suite cette feuille de style (&lt;strong&gt;flash.text.StyleSheet&lt;/strong&gt;).&lt;/p&gt;


&lt;p&gt;Commençons par définir dans un fichier texte &quot;&lt;strong&gt;style/style.css&quot;&lt;/strong&gt; une classe de style que nous pourrons charger et utiliser ensuite dans les champs de textes dynamique de notre application.&lt;/p&gt;

&lt;pre class=&quot;actionscript&quot;&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;my&lt;/span&gt;-style 
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; 
    font-family: Verdana;
    font-&lt;span style=&quot;color: #0066CC;&quot;&gt;size&lt;/span&gt;: 11px;
    font-weight: &lt;span style=&quot;color: #0066CC;&quot;&gt;bold&lt;/span&gt;;
    &lt;span style=&quot;color: #0066CC;&quot;&gt;color&lt;/span&gt;: &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;#FEF292; &lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Pour charger une ressource de type &quot;&lt;strong&gt;style&lt;/strong&gt;&quot; il suffit de définir un objet générique dans l'attribut &quot;&lt;strong&gt;imports&lt;/strong&gt;&quot; d'un fichier de configuration externe d'une fabrique &lt;strong&gt;IoC&lt;/strong&gt; avec la signature suivante&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; resource : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;style/style.css&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #0066CC;&quot;&gt;type&lt;/span&gt; : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;style&amp;quot;&lt;/span&gt; , id : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;style_sheet&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;    &lt;p&gt;La ressource ci-dessus permet de charger un fichier &quot;style/style.css&quot; et de créer un objet de type flash.text.StyleSheet, il attache ensuite cet instance dans la fabrique IoC avec une définition d'objet portant l'identifiant &quot;style_sheet&quot;. Cet identifiant servira de référence pour cibler à tout moment dans l'application ou la fabrique la feuille de style correspondante.&lt;/p&gt;


&lt;p&gt;Voici un exemple un peu plus complet d'utilisation d'une ressource de type &quot;style&quot; avec une configuration externe au format eden très simple&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;actionscript&quot;&gt;imports =
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; resource : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;style/style.css&amp;quot;&lt;/span&gt; , &lt;span style=&quot;color: #0066CC;&quot;&gt;type&lt;/span&gt; : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;style&amp;quot;&lt;/span&gt; , id : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;style_sheet&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; ;
&amp;nbsp;
objects =
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
        id         : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;my_field&amp;quot;&lt;/span&gt; ,
        &lt;span style=&quot;color: #0066CC;&quot;&gt;type&lt;/span&gt;       : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;flash.text.TextField&amp;quot;&lt;/span&gt;  ,
        properties :
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;
            &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;name&lt;/span&gt; : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;autoSize&amp;quot;&lt;/span&gt;    , value  : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;left&amp;quot;&lt;/span&gt;        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; ,
            &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;name&lt;/span&gt; : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;x&amp;quot;&lt;/span&gt;           , value  : &lt;span style=&quot;color: #cc66cc;&quot;&gt;20&lt;/span&gt;            &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; ,
            &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;name&lt;/span&gt; : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;y&amp;quot;&lt;/span&gt;           , value  : &lt;span style=&quot;color: #cc66cc;&quot;&gt;20&lt;/span&gt;            &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; ,
            &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;name&lt;/span&gt; : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;styleSheet&amp;quot;&lt;/span&gt;  , ref    : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;style_sheet&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; ,
            &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #0066CC;&quot;&gt;name&lt;/span&gt; : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;htmlText&amp;quot;&lt;/span&gt;    , value  : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;&amp;lt;p class='my-style'&amp;gt;hello world !&amp;lt;/p&amp;gt;&amp;quot;&lt;/span&gt;  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
    ,
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
        id               : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;root&amp;quot;&lt;/span&gt; ,
        &lt;span style=&quot;color: #0066CC;&quot;&gt;type&lt;/span&gt;             : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;flash.display.MovieClip&amp;quot;&lt;/span&gt;  ,
        factoryReference : &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;#root&amp;quot;&lt;/span&gt; ,
        singleton        : &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;true&lt;/span&gt; ,
        properties       :
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;
            &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;col