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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

incorrect version of Simple.as<br />

/*<br />

dynamic class Simple {<br />

function callfunc() {<br />

trace(func());<br />

}<br />

}<br />

*/<br />

// correct version of Simple.as<br />

dynamic class simple {<br />

function callfunc() {<br />

trace(this.func());<br />

}<br />

}<br />

Dans le fichier FLA ou un autre fichier <strong>ActionScript</strong>, ajoutez le co<strong>de</strong> suivant :<br />

var obj:Simple = new Simple();<br />

obj.num = 0;<br />

obj.func = function() {<br />

return true;<br />

};<br />

obj.callfunc();<br />

// output: true<br />

Le co<strong>de</strong> ci-<strong>de</strong>ssus fonctionne quand vous utilisez this dans la métho<strong>de</strong> callfunc().<br />

Cependant, vous aurez une erreur <strong>de</strong> syntaxe si vous avez utilisé la mauvaise version <strong>de</strong><br />

Simple.as, qui a été commentée dans l'exemple ci-<strong>de</strong>ssus.<br />

Dans l'exemple suivant, le mot-clé this fait référence à l'objet Circle :<br />

function Circle(radius:Number):Void {<br />

this.radius = radius;<br />

this.area = Math.PI*Math.pow(radius, 2);<br />

}<br />

var myCircle = new Circle(4);<br />

trace(myCircle.area);<br />

Dans l'instruction suivante affectée à une image dans un clip, le mot-clé this fait référence au<br />

clip actuel.<br />

// sets the alpha property of the current movie clip to 20<br />

this._alpha = 20;<br />

Dans l'instruction suivante dans un gestionnaire MovieClip.onPress, le mot-clé this fait<br />

référence au clip actuel :<br />

this.square_mc.onPress = function() {<br />

startDrag(this);<br />

};<br />

this.square_mc.onRelease = function() {<br />

stopDrag();<br />

};<br />

132 Chapitre 1: Eléments <strong>du</strong> <strong>langage</strong> <strong>ActionScript</strong>

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

Saved successfully!

Ooh no, something went wrong!