反比例函数。。

ActionScript& 3.0 Reference for the Adobe& Flash& Platform
Retrieving Data from Server...
Function& - AS3
Language Version:&ActionScript 3.0Runtime Versions:&AIR 1.0, Flash Player 9, Flash Lite 4 &
A function is the basic unit of code that can be invoked in ActionScript.
Both user-defined and built-in functions in ActionScript are represented by Function objects,
which are instances of the Function class.
Methods of a class are slightly different than Function objects. Unlike an ordinary function object, a method is tightly linked to its associated class object. Therefore, a method or property has a definition that is shared among all instances of the same class. Methods can be extracted from an instance and treated as "bound" methods (retaining the link to the original instance). For a bound method, the this keyword points to the original object that implemented the method. For a function, this points to the associated object at the time the function is invoked.
Public Properties&PropertyDefined ByPublic Methods &MethodDefined BythisArg: (default = NaN) & The object to which the function is applied.
&argArray: (default = NaN) & An array whose elements are passed to the function as parameters.
Returns & Any value that the called function specifies.
Related API ElementsthisArg: (default = NaN) & An object that specifies the value of thisObject within the function body.
& args & The parameter or parameters to be passed to the function. You can specify zero or more parameters.
ReturnsRelated API Elements The following example uses the FunctionExample,
SimpleCollection, EventBroadcaster, and EventListener classes
to show various uses of functions in ActionScript.
This is accomplished with the following steps:
The constructor for FunctionExample creates a local variable named
simpleColl, which is populated with an array of integers ranging from 1 to
8. The simpleColl object is printed using trace().An EventListener object, listener, is added to simpleColl.When the insert() and remove() functions are called, the listener responds
to their events.A second SimpleCollection object is created named greaterThanFourColl.The greaterThanFourColl object is assigned the result of simpleColl.select()
with the argument 4 and an anonymous function. The SimpleCollection object's select method is an
internal iterator that uses the anonymous function parameter as a block.
import flash.display.S
public class FunctionExample extends Sprite {
public function FunctionExample() {
var simpleColl:SimpleC
simpleColl = new SimpleCollection(0, 1, 2, 3, 4, 5, 6, 7, 8);
trace(simpleColl);
// 0, 1, 2, 3, 4, 5, 6, 7, 8
var listener:EventListener = new EventListener();
simpleColl.addListener(listener);
simpleColl.insert(9);
// itemInsertedHandler: 9
simpleColl.remove(8);
// itemRemovedHandler: 8
trace(simpleColl);
// 0, 1, 2, 3, 4, 5, 6, 7, 9
var greaterThanFourColl:SimpleC
greaterThanFourColl = simpleColl.select(4, function(item:int, value:int){ return item & value });
trace(greaterThanFourColl);
// 5, 6, 7, 9
import flash.display.S
class EventBroadcaster {
private var listeners:A
public function EventBroadcaster() {
listeners = new Array();
public function addListener(obj:Object):void {
removeListener(obj);
listeners.push(obj);
public function removeListener(obj:Object):void {
for(var i:uint = 0; i & listeners. i++) {
if(listeners[i] == obj) {
listeners.splice(i, 1);
public function broadcastEvent(evnt:String, ...args):void {
for(var i:uint = 0; i & listeners. i++) {
listeners[i][evnt].apply(listeners[i], args);
class SimpleCollection extends EventBroadcaster {
private var arr:A
public function SimpleCollection(... args) {
arr = (args.length == 1 && !isNaN(args[0])) ? new Array(args[0]) :
public function insert(obj:Object):void {
remove(obj);
arr.push(obj);
broadcastEvent("itemInsertedHandler", obj);
public function remove(obj:Object):void {
for(var i:uint = 0; i & arr. i++) {
if(arr[i] == obj) {
var obj:Object = arr.splice(i, 1)[0];
broadcastEvent("itemRemovedHandler", obj);
public function select(val:int, fn:Function):SimpleCollection {
var col:SimpleCollection = new SimpleCollection();
for(var i:uint = 0; i & arr. i++) {
if(fn.call(this, arr[i], val)) {
col.insert(arr[i]);
public function toString():String {
var str:String = new String();
for(var i:uint = 0; i & arr.length - 1; i++) {
str += arr[i] + ", ";
str += arr[arr.length - 1];
class EventListener {
public function EventListener() {
public function itemInsertedHandler(obj:Object):void {
trace("itemInsertedHandler: " + obj);
public function itemRemovedHandler(obj:Object):void {
trace("itemRemovedHandler: " + obj);}

我要回帖

更多关于 幂函数ppt 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信