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.

}<br />

Pour ajouter une erreur personnalisée, insérez le co<strong>de</strong> suivant dans un fichier .AS intitulé<br />

Divi<strong>de</strong>ByZeroError.as et enregistrez le fichier <strong>de</strong> classe dans le même répertoire que votre<br />

document FLA.<br />

class Divi<strong>de</strong>ByZeroError extends Error {<br />

var name:String = "Divi<strong>de</strong>ByZeroError";<br />

var message:String = "Unable to divi<strong>de</strong> by zero.";<br />

}<br />

Voir également<br />

Instruction throw, Instruction try..catch..finally<br />

toString (métho<strong>de</strong> Error.toString)<br />

public toString() : String<br />

Renvoie la chaîne "Error" par défaut ou la valeur contenue dans Error.message, s'il est défini.<br />

Disponibilité : <strong>ActionScript</strong> 1.0 ; Flash Player 7<br />

Valeur renvoyée<br />

String - Chaîne<br />

Exemple<br />

Dans l'exemple suivant, une fonction renvoie une erreur (avec un message spécifié) si les <strong>de</strong>ux<br />

chaînes qui lui sont transmises ne sont pas i<strong>de</strong>ntiques :<br />

function compareStrings(str1_str:String, str2_str:String):Void {<br />

if (str1_str != str2_str) {<br />

throw new Error("Strings do not match.");<br />

}<br />

}<br />

try {<br />

compareStrings("Dog", "dog");<br />

// output: Strings do not match.<br />

} catch (e_err:Error) {<br />

trace(e_err.toString());<br />

}<br />

Voir également<br />

message (propriété Error.message), Instruction throw, Instruction<br />

try..catch..finally<br />

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

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

Saved successfully!

Ooh no, something went wrong!