For faster navigation, this Iframe is preloading the Wikiwand page for ActionScript.

ActionScript

本条目存在以下问题,请协助改善本条目或在讨论页针对议题发表看法。 此条目需要编修,以确保文法、用词、语气格式标点等使用恰当。 (2019年3月22日)请按照校对指引,帮助编辑这个条目。(帮助讨论) 此条目需要补充更多来源。 (2017年5月4日)请协助补充多方面可靠来源改善这篇条目无法查证的内容可能会因为异议提出而被移除。致使用者:请搜索一下条目的标题(来源搜索:"ActionScript"网页新闻书籍学术图像),以检查网络上是否存在该主题的更多可靠来源(判定指引)。
ActionScript
编程范型多重编程范式基于原型的面向对象编程函数编程语言指令式编程脚本语言
设计者Gary Grossman英语Gary Grossman
实现者Adobe Systems
发行时间1998年
当前版本
  • 3.0 (2006年6月27日)
编辑维基数据链接
类型系统强类型静态类型
操作系统跨平台
网站www.adobe.com/devnet/actionscript.html 编辑维基数据链接
主要实现产品
Adobe FlashAdobe AnimateApache Flex
启发语言
JavaScriptJava

ActionScript是原Macromedia公司(后并入Adobe)为其Flash产品开发的一种基于ECMAScript面向对象编程语言。ActionScript可用于网页制作Adobe Flash动画和RIA应用程式的开发。

ActionScript和JavaScript均基于ECMAScript语法,因而拥有类似的语法。理论上它们互相可以很流畅地从一种语言翻译到另一种。不过JavaScript的文档对象模型是以浏览器窗口、文档表单为主的,ActionScript的文档对象模型则以SWF格式动画为主,可包括动画、音频、文字和事件处理。

ActionScript 开发时可借由导入 ANE 作为跨平台使用;并且官方公布之认证Starling (基于OPGL协议)开放框架,可使用GPU高速绘图,而非传统的CPU运算功能。

历史

ActionScript 首次出现于Flash 5并实现了在Flash内编程。这个版本被命名为ActionScript 1.0。Flash 6通过增加大量的内建函数和对动画元素更好的编程控制更进一步增强了编程环境的功能。Flash 7(MX 2004)引进了ActionScript 2.0,它增加了强类型面向对象特征,如显式声明、继承接口和严格数据类型。ActionScript 1.0 和 2.0 使用相同的编译形式编译成Flash SWF文件。

播放器发展时间表

版本 发布日期 描述
Flash Player 2 1997/06/17 第一个支持脚本的版本,包括控制时间轴的gotoAndPlay、 gotoAndStop、nextFrame和nextScene等方法。
Flash Player 3 1998/05/31 增强了加载外部SWF文件的基本脚本支持(loadMovie)。
Flash Player 4 1999/06/15 第一个完全实现脚本功能(称为“动作”)的播放器。这些脚本拥有简练的语法和对循环、条件、变量和其它基本语言结构的支持。
Flash Player 5 2000/08/24 第一个拥有真正意义上的ActionScript的版本。依据ECMAScript,[1]采用基于原型编程,并允许完全的过程式编程面向对象编程
Flash Player 6 2002/03/15 增加了事件处理模型,并且支持switch。
Flash Player 7 2003/09/10 提供一些新特性,如支持CSS显示文本和增强显示效果。Macromedia Flash编译器和Flash Player 7同时支持基于ECMAScript 4 Netscape Proposal[2]编程语言ActionScript 2.0。不过ActionScript 2.0能交叉编译成ActionScript 1.0的字节码,因此它能运行于Flash Player 6。
Flash Player 8 2005/09/13 增加用于运行时图象数据控制和文件上传的新类库及APIs,ActionScript 2.0功能更为完善。
Flash Player 9 2006/06/22 原称为Flash Player 8.5,增加ActionScript 3.0和一个称为AVM2(ActionScript Virtual Machine 2)新的虚拟机,它可以与前版本AVM1共存以便支持旧内容。增强性能是该版本的主要目标。这是adobe收购Macromedia后的第一个版本,并且也是Mac OS X上第一个Universal版本的Flash Player。
Flash Player 10 2008/10/15 支持多线程。
Flash Player 11 2011/10/04 运用Stage3D API提供的硬件加速图像渲染,支持GPU加速。[3]
Flash Player 14 2014/06/10 支持AGAL2[4]
Flash Player 17.0.0.93(阅览版 (Beta)) 2015/03/12
  • 支持64位PC全平台
  • Flash Player 17.0.0.171(正式版)
Flash Player 18(阅览版 (Beta)) 2015/06/09
  • 支持PC浏览器优化
  • 支持3D支持持续扩展
Flash Player 19 2015/09/21
Flash Player 20 2015/12/08 增强视频处理和资讯防盗功能
Flash Player 21 2016/03/10
  • 针对FLASH 与 HTML5结合运用 完善相关API
  • 与火狐团队合作 并针对火狐特殊需求增加支持
  • GPU渲染 3D 存储器处理
  • 强化MAC平台支持
Flash Player 22 2016/06/16
  • 处理字典消息问题
  • XML 修正
  • PPAPI 印刷修正
  • 针对Chrome浏览器修正横向模式
  • 大空字符修正
  • 新增 EnableLocalAppData 作为安全性功能提供
  • 与 Google 合作修正视频路线处理

桌面+APP时间表

  • 2007年3月19日:发布AIR public preview(当时称Apollo)及软件开发工具包(SDK)。
  • 2007年6月10日:Apollo更名为AIR及发布AIR Public beta。
  • 2007年10月1日:发布AIR Public beta 2。
  • 2007年12月12日:发布AIR Public beta 3。
  • 2008年2月25日:发布AIR 1.0版本。
  • 2008年6月17日:发布AIR 1.1版本。
  • 2008年11月17日:发布AIR 1.5版本。
  • 2009年2月24日:发布AIR 1.5.1版本。
  • 2009年7月30日:发布AIR 1.5.2版本。
  • 2009年12月8日:发布AIR 1.5.3版本。
  • 2010年6月10日:发布AIR 2.0版本。
  • 2010年10月24日:发布AIR 2.5版本。
  • 2011年2月24日:发布AIR 2.6版本。
  • 2011年6月14日:发布AIR 2.7版本。
  • 2011年10月3日:发布AIR 3.0版本。
  • 2011年11月11日:发布AIR 3.1版本。
  • 2012年3月28日:发布AIR 3.2版本。
  • 2012年6月5日:发布AIR 3.3版本。
  • 2012年8月21日:发布AIR 3.4版本。
  • 2012年11月6日:发布AIR 3.5版本。
  • 2013年2月12日:发布AIR 3.6版本。
  • 2013年4月9日:发布AIR 3.7版本。
  • 2013年7月24日:发布AIR 3.8版本。
  • 2013年10月8日:发布AIR 3.9版本。
  • 2013年10月30日:发布AIR 4.0版本。
  • 2014年4月8日:发布AIR 13.0版本。
  • 2014年6月10日:发布AIR 14.0版本。
  • 2014年9月9日:发布AIR 15.0版本。
  • 2014年11月11日:发布AIR 16.0版本(Beta),全面支持win8 64位 /android 5.0 /ios 8。
  • 2015年1月22日:发布AIR 16.0版本(正式版),全面支持win8 64位 /android 5.0 /ios 8。
  • 2015年2月4日:发布AIR 17.0版本(Beta),强化支持3D特效与其他视频效果,并优化效率。
  • 2015年4月14日:发布AIR 17.0.0.171版本(正式版)。
  • 2015年4月22日:发布AIR 18.0版本(Beta),3D功能扩展,优化IOS效率20%。
  • 2015年5月13日:开源团队开启支持linux ubuntu项目。
  • 2015年7月8日:发布AIR 18.0版本。
  • 2015年9月21日:发布AIR 19.0版本,增加安全性和增加IOS支持。
  • 2015年11月18日:发布AIR 20.0(Beta)版本。增加android TV 等跨平台 TV 支持技术研发。
  • 2016年6月16日:发布AIR 21.0版本。强化视频和摄影机路线规划、高清处理、性能优化和移动平台相关开发。

语言

语法

在ActionScript 2.0里,函数馆物件(如影片片段、按钮)可与类联系在一起。类可写在外在文档文件内,并且这些文件必须有.as后缀。类是增设部分──对ActionScript语言来说,可让程序员自行开发,虽然有许多内建类譬如MovieClip类──可被用来动态地在屏幕上画出向量──已经满足需求了。类文件可使编程更加容易,并且类文件如果需要的话可在许多项目间转移。

Flash ActionScript实现的特点如下,JavaScript程序员也许感兴趣:

  • 一切设计是异步的;回调函数是普遍存在的,但事件对象不存在。
  • XML的实现从Flash 5便存在了。Flash可送和收XML,该项功能可用来透过网络伺服器创造网上多玩者游戏。

ActionScript代码常常直接写在Flash开发环境。该环境提供参考、代码提示和句法强调。原代码常常与电影一起存在.fla文件里。自外部文档文件透过#include语法导入ActionScript代码也相当常见。在这种情况下,外部文件也许被Flash集成开发环境内建编译器,或Motion Twin ActionScript2编译器(MTASC)编译。

评价

  • 编程人员们说Macromedia ActionScript 2.0编译器有点慢,常常花好几分钟才编译100个类别,然而开放原始码编译器MTASC可以利用;它快多了。
  • ActionScript2.0 非常宽大的语法常常让编程人员们皱眉,因为它常常让不干净代码难以阅读。ActionScript 3.0的类型绑定改善了此缺点
  • 在Flash里使用许多矢量图形可能拖慢执行许多应用程式的机器的性能,因为Flash每帧每帧重画每个向量图。Flash 8引进了cacheAsBitmap变量,它暂时把向量图转换到位图,这种做法帮助降低了延滞。
  • Flash的ActionScript VM倾向在触发内部的暂停处理前就非常快达到它的运算极限,特别在麦金塔版的Flash播放器上更严重。例如,简单从1算到5000会威胁某些用户Flash播放器的能力。
  • 在Flash 8里许多人不喜欢引入(import)某些类直到要用到那些类别前最后一刻。不幸的是,ActionScript 3.0相当倚赖引入类别,没有导入撰写脚本(scripting)实际上不太可能。
  • .swf文件格式容易被反编译,使它非常难以保持原码的隐密性。在日后的发展由于发布后为原生语言结构此问题已不复存在,加上app的平台有自己的加密方式更加的解决所有语言都有的这难题。

[来源请求]

示例

ActionScript 2.0样本

下面打印Hello World。值得注意的是这只能在集成环境下执行,因为trace函数只有支持集成环境。

trace("Hello world!");

下面代码利用onMouseMove事件当滑鼠移动时输出现行滑鼠位置。同样的这只有在集成环境下执行。

onMouseMove = function () {
   trace("X: "+_root._xmouse);
   trace("Y: "+_root._ymouse);
};

这个较先进的示例创造一个包括数字与字符串的数组,并利用原形函数(prototype function)与函数递归给变量名num指定一个数,给变量str指定一个字符串。然后,利用MovieClip应用程式接口,文字区域被显示在屏幕上,文字区域里头写入了变量值。

var my_Array:Array = new Array("Hello", "ActionScript", 3, 7, 11, "Flash");
Array.prototype.pickNumber = function():Number  {
   var rand:Number = random(this.length);
   return (typeof (this[rand]) == "number") ? this[rand] : this.pickNumber();
};
Array.prototype.pickString = function():String  {
   var rand:Number = random(this.length);
   return (typeof (this[rand]) == "string") ? this[rand] : this.pickString();
};
var num:Number = my_Array.pickNumber();
var str:String = my_Array.pickString();
_root.createTextField("txt", 1, 10, 10, 530, 390);
txt.text = "Array = "+my_Array+"\nRandom Number = "+num+"\nRandom String = "+str;

ActionScript 3.0样本

下面先进的Hello World程序目前需要在Flex 2.0公开Alpha测试版集成环境中编译。

package {
   import flash.text.TextField;
   import flash.display.MovieClip;
   import flash.filters.DropShadowFilter;
   public class HelloWorld extends MovieClip {
      public function HelloWorld() {
         var shad:DropShadowFilter = new DropShadowFilter(2, 45, 0x000000, 25, 3, 3, 2, 2);
         var txt:TextField = new TextField();
         txt.textColor = 0xFFFFFF;
         txt.filters = [shad];
         txt.width = 120;
         txt.x = Math.random()*300;
         txt.y = Math.random()*300;
         txt.selectable = false;
         txt.text = "Hello World! ["+Math.round(txt.x)+","+Math.round(txt.y)+"]";
         addChild(txt);
      }
   }
}
//-----ActionScript3.0-----------------
//as3.0最重要的概念就是在效能方面的增進,平時所加入的任何事件都可以被監聽或從記憶體中移除
//以下例子就是監聽與移除記憶體占用,這是as3.0最重要的基礎概念

bt1.addEventListener(MouseEvent.CLICK,bt1_click);

function bt1_click(e:MouseEvent):void{
//觸發的事件內容;
}

//該按紐監聽不需要時則remove掉,增加效能
bt1.removeEventListener(MouseEvent.CLICK,bt1_click);

Starling GPU 开发样本

导入 SWC 或相关 SDK 以后,在构造函数内加入以下这段,便可激活 GPU 高速框架开发相关 swf 或是跨平台软件。[5][6][7]

var _starling = new Starling(MainGame, stage);
_starling.start();

参见

参考资料

  1. ^ Standard ECMA-262. Ecma-international.org. [April 22, 2013]. (原始内容存档于2015-12-30). 
  2. ^ ECMAScript. ECMAScript. [April 22, 2013]. (原始内容存档于2016年5月18日). 
  3. ^ Flash Player 11 Release Notes. [2014-08-27]. (原始内容存档于2014-09-23). 
  4. ^ Flash Player 14 Release Notes. [2014-08-27]. (原始内容存档于2014-10-03). 
  5. ^ Introducing Starling | Adobe Developer Connection. www.adobe.com. [2019-08-31]. (原始内容存档于2019-08-31). 
  6. ^ Starling Features - The Cross Platform Game Engine. Gamua. [2019-08-31]. (原始内容存档于2019-08-31) (英语). 
  7. ^ Bose, Juwal. Starling game development essentials : develop and deploy isometric turn-based games using Starling. Birmingham, UK: Packt Pub. 2013 [2019-08-31]. ISBN 178398354X. OCLC 870467587. (原始内容存档于2019-09-19). 

外部链接

{{bottomLinkPreText}} {{bottomLinkText}}
ActionScript
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?