03.05.2013 Views

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

References an object or movie clip instance. When a script executes, this references the<br />

movie clip instance that contains the script. When a field is called, this contains a reference<br />

to the object that contains the called field.<br />

Inside an on() event h<strong>and</strong>ler attached to a button, this refers to the Timeline that contains<br />

the button. Inside an onClipEvent() event h<strong>and</strong>ler attached to a movie clip, this refers to<br />

the Timeline of the movie clip itself.<br />

Because this is evaluated in the context of the script that contains it, you can't use this in a<br />

script to refer to a variable defined in a class file. Create ApplyThis.as, <strong>and</strong> enter the following<br />

code:<br />

class ApplyThis {<br />

var str:String = "Defined in ApplyThis.as";<br />

function conctStr(x:String):String {<br />

return x+x;<br />

}<br />

function addStr():String {<br />

return str;<br />

}<br />

}<br />

Then, in a FLA or AS file, add the following ActionScript:<br />

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

var abj:ApplyThis = new ApplyThis();<br />

abj.str = "defined in FLA or AS";<br />

trace(obj.addStr.call(abj, null)); //output: defined in FLA or AS<br />

trace(obj.addStr.call(this, null)); //output: undefined<br />

trace(obj.addStr.call(obj, null)); //output: Defined in applyThis.as<br />

Similarly, to call a function defined in a dynamic class, you must use this to invoke the<br />

function in the proper scope:<br />

// 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 />

Inside the FLA or AS file, add the following ActionScript:<br />

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

obj.num = 0;<br />

104 ActionScript language elements

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

Saved successfully!

Ooh no, something went wrong!