注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

神魔破杜梓的叨叨堂

Programming every day!

 
 
 

日志

 
 
 
 

Actionscript 中包级别的方法闭包  

2008-05-07 09:14:36|  分类: My Tech |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
原文来自Ericfeminella's blog

Package-level function closures are very useful for creating generalized functionality which does not require a class (static methods) or instance of a class (instance methods).

Unlike static and instance methods package-level function closures are not associated with a class or instance of a class but rather with a package. There are no syntactical differences between package-level functions and static or instance methods.

Package-level functions are for the most part utility functions; for instance the flash.utils package contains a number of package-level functions, the most common of which are describeType(), getDefintionByName(), getTimer() and so forth.

Package-level function closures are created by defining a function directly inside the body of a package (where class and interfaces are defined), as can be seen in the following example:

package com.ericfeminella.display
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.IBitmapDrawable;
import mx.graphics.ImageSnapshot;

/**
 *
 * Creates a snap shot of a <code>Bitmap</code> object
 * from the specified <code>IBitmapDrawable</code>
 * implementation.
 *
 * @param  display object in which to create the snapshot
 * @return <code>Bitmap</code> snapshot of the display object
 *
 */
    
public function createSnapShot(target:IBitmapDrawable) : Bitmap
{
    return new Bitmap(ImageSnapshot.captureBitmapData(target));
}
}

Calling a package level function is straightforward, simply import the function just as you would a class or interface and then invoke the function directly…

// import package function
import com.ericfeminella.display.createSnapShot;

// once imported the function can be invoked
createSnapShot( this );

Typically you will find that most functionality can be grouped to a Class or an instance object, however on occasion you may identify specific functionality which is common to packaged functionality as opposed to a specific object, and in these cases utilizing package-level functions is a great option.

  评论这张
 
阅读(358)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017