03.07.2013 Views

Guide de reference du langage ActionScript 2.0 - PowWeb

Guide de reference du langage ActionScript 2.0 - PowWeb

Guide de reference du langage ActionScript 2.0 - PowWeb

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

L'exemple suivant envoie une chaîne au fichier SWF précé<strong>de</strong>nt et affiche un message d'état<br />

indiquant si la connexion locale a réussi, ou non, à se connecter au fichier. Un composant<br />

TextInput intitulé name_ti, une occurrence TextArea intitulée status_ta et une occurrence<br />

Button intitulée send_button sont utilisés pour afficher le contenu.<br />

var sending_lc:LocalConnection;<br />

var sendListener:Object = new Object();<br />

sendListener.click = function(evt:Object) {<br />

sending_lc = new LocalConnection();<br />

sending_lc.onStatus = function(infoObject:Object) {<br />

switch (infoObject.level) {<br />

case 'status' :<br />

status_ta.text = "LocalConnection connected successfully.";<br />

break;<br />

case 'error' :<br />

status_ta.text = "LocalConnection encountered an error.";<br />

break;<br />

}<br />

};<br />

sending_lc.send("_mylc", "sayHello", name_ti.text);<br />

};<br />

send_button.addEventListener("click", sendListener);<br />

Si votre fichier SWF inclut un composant <strong>de</strong> la version 2, utilisez la classe DepthManager <strong>de</strong>s<br />

composants <strong>de</strong> la version 2 à la place <strong>de</strong> la métho<strong>de</strong> MovieClip.getNextHighestDepth()<br />

utilisée dans l'exemple précé<strong>de</strong>nt.<br />

Dans l'exemple suivant, le fichier SWF <strong>de</strong> réception, qui rési<strong>de</strong> sur thisDomain.com, accepte<br />

uniquement les comman<strong>de</strong>s issues <strong>de</strong> fichiers SWF situés dans thisDomain.com ou<br />

thatDomain.com :<br />

var aLocalConn:LocalConnection = new LocalConnection();<br />

aLocalConn.Trace = function(aString) {<br />

aTextField += aString+newline;<br />

};<br />

aLocalConn.allowDomain = function(sendingDomain) {<br />

return (sendingDomain == this.domain() || sendingDomain ==<br />

"www.macromedia.com");<br />

};<br />

aLocalConn.connect("_mylc");<br />

Lorsque vous publiez <strong>de</strong>s fichiers pour Flash Player 7 ou une version ultérieure, la<br />

correspondance exacte <strong>de</strong>s domaines est utilisée. Cela signifie que l'exemple échoue si les<br />

fichiers SWF sont situés à l'adresse www.thatDomain.com ; en revanche, il fonctionne si les<br />

fichiers sont situés à l'adresse thatDomain.com.<br />

740 Chapitre 2: Classes <strong>ActionScript</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!