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.

instantiate a new object<br />

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

// define a function for __resolve to call<br />

myObject.myFunction = function(name) {<br />

trace("Method "+name+" was called");<br />

};<br />

// define the __resolve function<br />

myObject.__resolve = function(name) {<br />

// reserve the name "onStatus" for local use<br />

if (name == "onStatus") {<br />

return undefined;<br />

}<br />

trace("Resolve called for "+name); // to check when __resolve is called<br />

// Not only call the function, but also save a reference to it<br />

var f:Function = function () {<br />

this.myFunction(name);<br />

};<br />

// create a new object method <strong>and</strong> assign it the reference<br />

this[name] = f;<br />

// return the reference<br />

return f;<br />

};<br />

// test __resolve using the method name "onStatus"<br />

trace(myObject.onStatus("hello"));<br />

// output: undefined<br />

Usage 5: The following example builds on the previous example by creating a functor that<br />

accepts parameters. This example makes extensive use of the arguments object, <strong>and</strong> uses<br />

several methods of the Array class.<br />

// instantiate a new object<br />

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

// define a generic function for __resolve to call<br />

myObject.myFunction = function (name) {<br />

arguments.shift();<br />

trace("Method " + name + " was called with arguments: " +<br />

arguments.join(','));<br />

};<br />

// define the __resolve function<br />

myObject.__resolve = function (name) {<br />

// reserve the name "onStatus" for local use<br />

if (name == "onStatus") {<br />

return undefined;<br />

}<br />

var f:Function = function () {<br />

arguments.unshift(name);<br />

this.myFunction.apply(this, arguments);<br />

};<br />

// create a new object method <strong>and</strong> assign it the reference<br />

Object 531

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

Saved successfully!

Ooh no, something went wrong!