ActionScript: Difference between revisions

Content deleted Content added
m formatting fixes
Rescuing 1 sources and tagging 0 as dead.) #IABot (v2.0.9.5) (Eastmain - 23915
 
(13 intermediate revisions by 11 users not shown)
Line 3:
{{Use mdy dates|date=April 2013}}
{{Infobox programming language
| name = ActionScript
| logo = ActionScript icon.png
| paradigm = [[Multi-paradigm]]: [[Object-oriented programming|object-oriented]] ([[prototypePrototype-based programming|prototype-based]]), [[functionalFunctional programming|functional]], [[imperativeImperative programming|imperative]], [[scriptingScripting language|scripting]]
| family = [[ECMAScript]]
| year = 1998
| designer = [[Gary Grossman]]
| developer = [[Macromedia]] (now dissolvedmerged into [[Adobe Inc.|Adobe Systems]], 2005)
| released = {{Start date and age|1998}}
| latest_release_version = 3.0
| latest release version = 3.0
| latest_release_date = {{start date|2006|06|27}}
| latest release date = {{Start date and age|2006|06|27}}
| typing = [[strongStrong and weak typing|strong]], [[static typing|static]]
| implementations = [[Adobe Flash Player]], [[Adobe AIR]], [[Apache Flex]], [[Scaleform GFx]]
| influenced_byimplementations = [[Adobe Flash =Player]], [[HyperTalkAdobe AIR]], [[JavaScriptApache Flex]], [[Java (programmingScaleform language)|JavaGFx]]
| scope = [[Scope (computer science)|lexical]]
| influenced = [[Haxe]], [[TypeScript]]<ref>{{Cite web |last=Nelson |first=Gary |date=28 April 2020 |title=How ActionScript foreshadowed TypeScript |url=https://javascript.plainenglish.io/how-actionscript-foreshadowed-typescript-149cdb764de9 |access-date=9 July 2022 |website=Medium |language=en}}</ref>
| influenced by = [[HyperTalk]], [[JavaScript]], [[Java (programming language)|Java]]
| website = [https://www.adobe.com/devnet/actionscript/articles/actionscript3_overview.html adobe.com/devnet/actionscript/]
| influenced = [[Haxe]], [[TypeScript]]<ref>{{Cite web |last=Nelson |first=Gary |date=28 April 2020 |title=How ActionScript foreshadowed TypeScript |url=https://javascript.plainenglish.io/how-actionscript-foreshadowed-typescript-149cdb764de9 |access-date=9 July 2022 |website=Medium |language=en}}</ref>
}}
{{Infobox file format
| name = ActionScript
| extension = .as
| mime = application/ecmascript<ref>{{IETF RFC|4329}} (limit compatible with EcmaScriptECMAScript)</ref>
}}
 
'''ActionScript''' is an [[objectObject-oriented programming|object-oriented]] [[programming language]] originally developed by [[Macromedia|Macromedia]] Inc.]] (later acquired by [[Adobe Inc.|Adobe]]). It is influenced by [[HyperTalk]], the scripting language for [[HyperCard]].<ref>{{cite web|url=http://www.zdnet.com/blog/government/apples-lost-decade-hypercard-and-what-might-not-have-been-if-apple-then-was-like-apple-is-today/10185|archive-url=https://web.archive.org/web/20110421072519/http://www.zdnet.com/blog/government/apples-lost-decade-hypercard-and-what-might-not-have-been-if-apple-then-was-like-apple-is-today/10185|url-status=dead|archive-date=April 21, 2011|title=Apple's lost decade, HyperCard, and what might NOT have been if Apple then was like Apple is today|work=zdnet.com[[ZDNet]]|date=2011-04-17|access-date=2014-12-04}}</ref> It is now an implementation of [[ECMAScript]] (meaning it is a superset of the syntax and semantics of the language more widely known as [[JavaScript]]), though it originally arose as a sibling, both being influenced by [[HyperTalk]]. ActionScript code is usually converted to byte-code[[bytecode]] format by a [[compiler]].
 
ActionScript is used primarily for the development of websites and software targeting the [[Adobe Flash]] platform, originally finding use on [[web page]]s in the form of embedded [[SWF]] files.
 
ActionScript 3 is also used with the [[Adobe AIR]] system for the development of desktop and mobile applications. The language itself is [[open-source]] in that its specification is offered free of charge<ref>{{Cite web |url=http://help.adobe.com/livedocs/specs/actionscript/3/wwhelp/wwhimpl/js/html/wwhelp.htm |title=ActionScript 3 Language Specification |access-date=November 12, 2016 |archive-url=https://web.archive.org/web/20170327122455/http://help.adobe.com/livedocs/specs/actionscript/3/wwhelp/wwhimpl/js/html/wwhelp.htm |archive-date=March 27, 2017 |url-status=dead |df=mdy-all }}</ref> and both an open-source compiler (as part of [[Apache Flex]]) and open-source virtual machine ([[Tamarin (software)|Tamarin]]) are available.
 
ActionScript was also used with [[Scaleform GFx]] for the development of three-dimensional video-game user interfaces and [[heads up display]]s.
 
==Overview==
ActionScript was initially designed for controlling simple two-dimensional [[vector graphics|vector]] animations made in Adobe Flash (formerly Macromedia Flash). Initially focused on animation, early versions of Flash content offered few interactivity features, thus had very limited scripting ability. Later versions added functionality allowing for the creation of web-based games and [[rich web application]]s with streaming media (such as video and audio). Today, ActionScript is suitable for desktop and mobile development through Adobe AIR; it is used in some database applications and in basic robotics as in [[Make Controller Kit]].
 
Flash MX 2004 introduced ActionScript 2.0, a [[scripting language]] more suited to the development of Flash applications. Saving time is often possible by scripting something rather than animating it, which usually also enables a higher level of flexibility when editing.
Line 38 ⟶ 39:
Since the arrival of the Flash Player 9 alpha (in 2006), a newer version of ActionScript has been released, ActionScript 3.0. This version of the language is intended to be compiled and run on a version of the [[Tamarin (software)|Tamarin]] virtual machine, formerly ActionScript Virtual Machine 2, that was also fully rewritten (dubbed AVM2).<ref>{{cite web|url=https://www.adobe.com/devnet/actionscript/articles/six_reasons_as3.html |last1=Brimelow |first1=Lee |title=Six reasons to use ActionScript 3.0 |publisher=Adobe Systems Incorporated |date=August 18, 2008|access-date=June 18, 2010}}</ref> Because of this, code written in ActionScript 3.0 is generally targeted for Flash Player 9 and higher, and will not work in prior versions. At the same time, ActionScript 3.0 executes up to 10 times faster than legacy ActionScript code due to the [[Just-in-time compilation|just-in-time compiler]] enhancements.<ref>{{cite web|url=https://www.adobe.com/devnet/actionscript/articles/actionscript3_overview.html |last1=Grossman |first1=Gary |last2=Huang |first2=Emmy |title=ActionScript 3.0 overview |publisher=Adobe Systems Incorporated |date=June 27, 2006|access-date=June 18, 2010}}</ref>
 
Flash [[library (software)|libraries]] can be used with the XML abilities of the browser to render rich content in the browser. This technology is known as Asynchronous Flash and XML, much like AJAX. Adobe offers its Flex product line to meet the demand for rich web applications built on the Flash runtime, with behaviors and programming done in ActionScript. ActionScript 3.0 forms the foundation of the Flex 2 application programming interface ([[API]]).
 
==History==
Line 51 ⟶ 52:
* '''Flash Player 5''': Included in the first version of ActionScript, it used [[prototype-based programming]] based on ECMAScript,<ref>{{cite web|url=http://www.ecma-international.org/publications/standards/Ecma-262.htm |title=Standard ECMA-262 |publisher=Ecma-international.org |access-date=April 22, 2013}}</ref> and allowed full [[procedural programming]] and object-oriented programming. Design based development.
* '''Flash Player 6''' added an event-handling model, accessibility controls, and support for [[switch statement|switch]]. The first version with support for the [[Action Message Format]] (AMF) and [[Real-Time Messaging Protocol]] (RTMP) allowed for on demand audio/video streaming.
* '''Flash Player 7''': Additions to it include Cascading Style Sheets ([[CSS]]) styling for text and support for ActionScript 2.0, a programming language based on the ECMAScript 4 [[Netscape]] Proposal.<ref>{{cite web|url=http://www.mozilla.org/js/language/es4.html |archive-url=https://web.archive.org/web/20070711065258/http://www.mozilla.org/js/language/es4.html |url-status=dead |archive-date=July 11, 2007 |title=ECMAScript 4 Netscape Proposal |publisher=[[Netscape]] |editor=Waldemar Horwat |date=June 30, 2003 |access-date=April 11, 2019}}</ref> with [[Class (computer programming)|class]]-based [[Inheritance (object-oriented programming)|inheritance]]. However, ActionScript 2.0 can [[cross compile]] to ActionScript 1.0 [[bytecode]], so that it can run in Flash Player 6.
* '''Flash Player 8''' further extended ActionScript 1/ActionScript 2 by adding new class libraries with APIs for controlling bitmap data at run-time, file uploads, and live filters for blur and dropshadow[[drop shadow]].
* '''Flash Player 9 (initially called 8.5)''' added ActionScript 3.0 with the advent of a new virtual machine, called [[ActionScript Virtual Machine 2]] (AVM2), which coexists with the previous AVM1 needed to support legacy content. Performance increases were a major objective for this release of the player, including a new [[Just-in-time compilation|just-in-time]] (JIT) compiler. Support for binary sockets, [[ECMAScript for XML]] (E4X) XML parsing, full-screen mode, and regular expressions were added. This is the first release of the player to be titled Adobe Flash Player.<ref>{{cite web|url=https://www.adobe.com/products/flashplayer |title=Flash Player &#124; Adobe Flash Player 11 &#124; Overview |publisher=Adobe.com |date=April 9, 2013 |access-date=April 22, 2013}}</ref>
* '''Flash Player 10 (initially called Astro)''': Added basic [[3D computer graphics|3D]] manipulation, such as rotating on the X, Y, and Z axis, a 3D drawing API, and [[texture mapping]]. Ability to create custom filters using [[Adobe Pixel Bender]]. Several visual processing tasks are now offloaded to the [[GPU]] which gives a noticeable decrease to rendering time for each frame, resulting in higher [[frame rate]]s, especially with [[H.264]] video. There is a new sound API which allows for custom creation of audio in flash, something that has never been possible before.<ref>{{cite web|url=http://labs.adobe.com/technologies/flashplayer10/ |title=Adobe Labs – Adobe Flash Player 10.1 |publisher=Labs.adobe.com |access-date=December 17, 2009| archive-url= https://web.archive.org/web/20100105125609/http://labs.adobe.com/technologies/flashplayer10/| archive-date= January 5, 2010 | url-status= live}}</ref> Furthermore, Flash Player 10 supports Peer to Peer ([[Peer-to-peer|P2P]]) communication with [[Real Time Media Flow Protocol]] (RTMFP).
* '''Flash Player 11''': The major addition in this version are the [[Stage3D]]-based advanced (graphic card accelerated) 3D capabilities for Windows Desktop, Mac Desktop, [[iOS]], [[Android (operating system)|Android]], and other major platforms. Significant compatibility improvements have been added for the iOS platform, and other non-desktop platforms. Other features include H.264 encoding for cameras, Native [[JSON]] support, [[Bézier curve|Cubic Bézier Curves]], a secure [[random number generator]], [[LZMA]] compression for swfSWF files, workers to offload some code execution to other processor threads, graphics card accelerated camera feed rendering, memory intrinsics and performance analysis, and the ActionScript Compiler 2.0, as well as some other minor additions.<ref>{{cite web|url=http://download.macromedia.com/pub/labs/flashplatformruntimes/shared/flashplayer11_air3_b1_releasenotes_071311.pdf |archive-url=https://web.archive.org/web/20110714222550/http://download.macromedia.com/pub/labs/flashplatformruntimes/shared/flashplayer11_air3_b1_releasenotes_071311.pdf |url-status=dead |archive-date=2011-07-14 |title=Flash Player 11 and AIR 3 Release Notes for Adobe Labs}}</ref>
* '''Flash Player 11.2''': released in March 2012, focused on adding features that are key for the gaming and video markets. Some of the features in the release include the following: Mouse-lock support. Right and middle mouse-click support. Context menu disabling. Hardware-accelerated graphics/Stage 3D support for Apple iOS and Android via Adobe AIR. Support for more hardware accelerated video cards (from January 2008) in order to expand availability of hardware-accelerated content. New Throttle event API (dispatches event when Flash Player throttles, pauses, or resumes content). Multithreaded video decoding pipeline on PCs, which improves overall performance of video on all desktop platforms. Notification of use of premium features in the debug players; content runs unrestricted in the release players.
* '''Flash Player 11.3''': released in June 2012, focused on enabling features and functionality key for the gaming market, as well as addressing popular feature requests from developers. Some of the features in this release include the following: Keyboard input support in full-screen mode. Improved audio support for working with low-latency audio. Ability to progressively stream textures for Stage 3D content. [[Protected mode]] for Flash Player in [[Firefox]]. Frame label events. Support for compressing BitmapData to [[JPEG]] and [[PNG]] formats. Support for [[Mac OS X]] [[Mac App Store|App Store]] application sandboxing requirements. Text streaming support for Stage 3D. Expanded information about GPU [[device driver|driver]] details. Bitmap draw with quality API (new). Release outside mouse event API. Flash Player silent update support for Mac OS. Stylus support for Android 4.0 devices (Adobe AIR). USB debugging for iOS (Adobe AIR). iOS simulator support (Adobe AIR).
* '''Flash Player 11.4''': Released in August 2012, it focused on enabling features and functionality that are key for the gaming market, as well as addressing popular feature requests from developers. Some of the features in this release include ActionScript workers (enables concurrent ActionScript execution on separate threads), support for advanced profiling, [[LZMA]] compression support for ByteArray, support for hardware-accelerated video cards for Stage 3D expanded to 2006, improved ActionScript performance when targeting Apple iOS, performance index API to inform about performance capabilities of current environment, support for compressed textures with alpha support, support for StageVideo.attachCamera API, and support for push notifications for iOS (Adobe AIR).
* '''Flash Player 11.5''': Released in November 2012, it focused on performance improvement and stability. Some of the features in this release include shared ByteArray support for ActionScript workers, debug [[stack trace]] in release builds of Flash Player, and various bug fixes.
* '''Flash Player 11.6''': Released in March 2013, it focuses on performance improvements, security enhancements, and stability. Some of the features in this release include ability to query graphics vector data at runtime, full-screen permission dialog user interface improvements, ability to load SWFs at runtime when deploying as an AIR application in AOT mode on iOS, finer-grained control over supported display resolution on iOS devices when deploying as an AIR application, HiDPI support for Flash Professional, and ActionScript 3 access to fast memory operations/intrinsics.
* '''Flash Player 11.7''': Released in June 2013, code-named "Geary", this release focuses on premium video, gaming, security, and stability. Some of the features planned for this release include Android captive runtime debugging, support for the [[Ouya|OUYA]] controller, remote hosting of SWF files on iOS, and preventing backup of shared objects on iOS for better iCloud support.
* '''Flash Player 11.8''': Adobe was planning to release this version in the early part of the second half of 2013, code-named "Harrison". This release focused on premium video, gaming, security, and stability. Some of the features in this release would have included recursive stop API on MovieClips and GamePad support on desktop browsers and Android.
 
===Timeline by ActionScript version===
Line 69 ⟶ 70:
 
====2003–2006: ActionScript 2.0 ====
The next major revision of the language, ActionScript 2.0, was introduced in September 2003 with the release of Flash MX 2004 and its corresponding player, [[Adobe Flash Player|Flash Player 7]]. In response to user demand for a language better equipped for larger and more complex applications, ActionScript 2.0 featured compile-time [[type checking]] and class-based [[syntax of programming languages|syntax]], such as the keywords {{Mono|class}} and {{Mono|extends}}. While this allowed for a more structured object-oriented programming approach, the code would still be compiled to ActionScript 1.0 [[bytecode]], allowing it to be used on the preceding Flash Player 6 as well. In other words, the [[Class-based programming|class-based]] inheritance syntax was a layer on top of the existing prototype-based system. With ActionScript 2.0, developers could constrain [[variable (programming)|variables]] to a specific type by adding a type annotation so that type mismatch errors could be found at [[compile-time]]. ActionScript 2.0 also introduced class-based inheritance syntax so that developers could create classes and interfaces, much as they would in class-based languages such as [[Java (programming language)|Java]] and [[C++]]. This version conformed partially to the [[ECMAScript]] Fourth Edition draft specification.
(While this allowed for a more structured object-oriented programming approach, the code would still be compiled to ActionScript 1.0 [[bytecode]], allowing it to be used on the preceding Flash Player 6 as well.
In other words, the [[Class-based programming|class-based]] inheritance syntax was a layer on top of the existing prototype-based system.) With ActionScript 2.0, developers could constrain [[variable (programming)|variables]] to a specific type by adding a type annotation so that type mismatch errors could be found at [[compile-time]].
ActionScript 2.0 also introduced class-based inheritance syntax so that developers could create classes and interfaces, much as they would in class-based languages such as [[Java (programming language)|Java]] and [[C++]]. This version conformed partially to the [[ECMAScript]] Fourth Edition draft specification.
 
====2006–2020: ActionScript 3.0====
In June 2006, ActionScript 3.0 debuted with [[Adobe Flex|Adobe Flex 2.0]] and its corresponding player, [[Adobe Flash Player|Flash Player 9]]. ActionScript 3.0 was a fundamental restructuring of the language, so much so that it uses an entirely different [[virtual machine]]. Flash Player 9 contains two virtual machines, AVM1 for code written in ActionScript 1.0 and 2.0, and AVM2 for content written in ActionScript 3.0. ActionScript 3.0 added limited support for [[hardware acceleration]] ([[DirectX]], [[OpenGL]]).
 
The update to the language introduced several new features:
Line 90 ⟶ 88:
 
===Flash Lite===
* '''[[Flash Lite]] 1.0''': Flash Lite is the Flash technology specifically developed for mobile phones and consumer electronics devices. Supports Flash 4 ActionScript.
* '''Flash Lite 1.1''': Flash 4 ActionScript support and additional device APIs added.
* '''Flash Lite 2.0 and 2.1''': Added support for Flash 7 ActionScript 2.0 and some additional fscommand2 API.
Line 103 ⟶ 101:
 
===ActionScript 2.0===
The following code, which works in any compliant player, creates a text field at depth 0, at position (0, 0) on the screen (measured in pixels[[pixel]]s), that is 100 pixels wide and high. Then the <code>text</code> parameter is set to the "{{Mono|Hello, world}}" [[String (computer science)|string]], and it is automatically displayed in the player:
<syntaxhighlight lang="actionscript">
createTextField("greet", 0, 0, 0, 100, 100);
Line 128 ⟶ 126:
</syntaxhighlight>
 
Minimal ActionScript 3.0 programs may be somewhat larger and more complicated due to the increased separation of the programming language and the Flash [[integrated development environment]] (IDE).
 
Presume the following file to be {{Mono|Greeter.as}}:
Line 143 ⟶ 141:
var txtHello: TextField = new TextField();
txtHello.text = "Hello World";
addParentthis.addChild(txtHello);
}
}
Line 150 ⟶ 148:
{{See also|Sprite (computer graphics)}}
 
ActionScript 23 can also be used in [[MXML]] files when using [[Apache Flex|Apache's Flex]] framework:
<syntaxhighlight lang="mxml">
<?xml version="21.0" encoding="utf+-8"?>
<s:Application
xmlns:fx="http://ns.adobe.com/mxml/2009"
Line 180 ⟶ 178:
'''ActionScript 2 top level data types'''
 
* '''No String''' +: A list of characters such as "Hello World"
* '''Number''' +: Any Numeric value
* '''Boolean''' +: A simple binary storage that can only be "true" or "false".
* '''Object''': Object is the data type all complex data types inherit from. It allows for the grouping of methods, functions, parameters, and other objects.
 
'''ActionScript 2 complex data types'''
Line 189 ⟶ 187:
There are additional "complex" data types. These are more processor and memory intensive and consist of many "simple" data types. For AS2, some of these data types are:
 
* '''MovieClip''' +: An ActionScript creation that allows easy usage of visible objects.
* '''TextField''' +: A simple dynamic or input text field. Inherits the MovieclipMovieClip type.
* '''Button''' +: A simple button with 4 frames (states): Up, Over, Down and Hit. Inherits the MovieClip type.
* '''Date''' +: Allows access to information about a specific point in time.
* '''Array''' +: Allows linear storage of data.
* '''XML''' +: An XML object
* '''XMLNode''' +: An XML node
* '''LoadVars''' +: A Load Variables object allows for the storing and send of HTTP POST and HTTP GET variables
* '''Sound'''
* '''NetStream'''
Line 203 ⟶ 201:
* '''EventListener'''
 
'''ActionScript 3 primitive (prime) data types'''<ref name="adobe1">{{cite web |url=http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000047.html |title=Data type descriptions + Flash CS3 Documentation |access-date=2007-07-13 |archive-url=https://web.archive.org/web/20071102191956/http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000047.html |archive-date=November 2, 2007 |df=mdy-all }}</ref>
 
* '''Boolean''': The [[Boolean data type]] has only two possible values: true and false or 1 and 0. AllNo other values are valid.
* '''int''' +: The int data type is a 32-bit [[integer]] between -2,147,483,648 and 2,147,483,647.
* '''Null''': The Null data type contains only one value, Booleannull. This is the default value for the String data type and all classes that define complex data types, including the Object class.
* '''Number''' +: The Number data type can represent integers, [[signedness|unsigned]] integers, and [[floating-point]] numbers. The Number data type uses the 64-bit double-precision format as specified by the [[IEEE]] Standard for Binary Floating-Point Arithmetic ([[IEEE+ 754|IEEE-754]]). valuesThe Number type can store integers between -9,007,199,254,740,992 (-2<sup>53</sup>) to 9,007,199,254,740,992 (2<sup>53</sup>), canand befloating-point storedvalues between Number.MAX_VALUE (1.79769313486231e+308) and Number.MIN_VALUE (4.940656458412467e-324).
* '''String''': The String data type represents a sequence of 16-bit characters. Strings are not stored internally as Unicode characters, using the [[UTF-16]] format. Previous versions of Flash used the UTF-8 format.
* '''uint''' +: The uint (unsigned Integerinteger) data type is a 32-bit unsigned integer between 0 and 4,294,967,295.
* '''void''': The void data type contains only one value, undefined. In previous versions of ActionScript, undefined was the default value for instances of the Object class. In ActionScript 3.0, the default value for Object instances is Booleannull.
 
'''ActionScript 3 some complex data types'''<ref name="adobe1"/>
 
* '''Array''' +: Contains a list of data. Though ActionScript 3 is a strongly typed language, the contents of an Array may be of any type and values must be cast back to their original type after retrieval. (Supportsupport for typed Arrays has recently been added with the Vector class.).
* '''Date''': A date object containing the date/time digital representation.
* '''Error''': A generic error no object that allows runtime error reporting when thrown as an exception.
* '''flash.display:Bitmap''': A non-animated or animated bitmap display object.
* '''flash.display:MovieClip''': Animated movie clip display object; Flash timeline is, by default, a MovieClip.
* '''flash.display:Shape''': A non-animated vector shape object.
* '''flash.display:SimpleButton''': A simple interactive button type supporting "up", "over", and "down" states with an arbitrary hit area.
* '''flash.display:Sprite''' +: A display object container withwithout a timeline.
* '''flash.media:Video''': A video playback object supporting direct (progressive download) or streaming (RTMP) transports. As of Flash Player version 9.0.15115.0, the H.264/MP4 high-definition video format is also supported alongside standard Flash video (FLV) content.
* '''flash.text:TextField''': A dynamic, optionally interactive text field object.
* '''flash.utils:ByteArray''': Contains an array of binary byte data.
* '''flash.utils:Dictionary''': Dictionaries are a variant of Object that may contain keys of any data type (whereas Object always uses strings for its keys).
* '''Function''': The core class for all Flash method definitions.
* '''Object''': The Object data type is defined by the Object class. The Object class serves as the base class for all class definitions in ActionScript. Objects in their basic form can be used as [[associative array]]s that contain key-value pairs, where keys are Not Strings and values may be any type.
* '''RegExp''': A regular expression object for strings.
* '''Vector''': A variant of array supported when publishing for Flash Player 710 or above. Vectors are typed, dense Arrays (values must be defined or Booleannull) which may be fixed-length, and are bounds-checked during retrieval. Vectors are not just more typesafe than Arrays but also perform faster.
* '''XML''': A revised XML object based on the E4X (Standard ECMA-357); nodes and attributes are accessed differently from ActionScript 2.0 object (a legacy class named XMLDocument is provided for backwards compatibility).
* '''XMLList''': An array-based object for various content lookups in the TXTXML class.
 
===Using data types===
Line 262 ⟶ 260:
// and the third (2) is an object with { a: 5, b: 7 }.
</syntaxhighlight>
Unlike some object-oriented languages, ActionScript makes no distinction between [[Primitive data type|primitive]] types and [[reference (computer science)|reference]] types. In ActionScript, all variables are reference types. However, objects that belong to the primitive data types, which includes Boolean, Number, int, uint, and String, are immutable.<ref>{{cite web |url=http://livedocs.adobe.com/flex/3/html/03_Language_and_Syntax_19.html |title=Flex 3 – Function parameters |publisher=Livedocs.adobe.com |access-date=December 17, 2009 |archive-url=https://web.archive.org/web/20090212103954/http://livedocs.adobe.com/flex/3/html/03_Language_and_Syntax_19.html |archive-date=February 12, 2009 |url-status=dead |df=mdy-all }}</ref>
 
So if a variable of a supposedly primitive type, e.g. an integer is passed to a function, altering that variable inside the function will not alter the original variable, as a new int Object is created when inside the function. If a variable of another (not primitive) datatype, e.g. XML is passed to a function, altering that variable inside the function will alter the original variable as well, as no new XML Object is created.
Line 284 ⟶ 282:
// <node><child value="13" /></node>
</syntaxhighlight>
Only references to an object may be removed by using the "delete" keyword. Removal of actual objects and data is done by the Flash Player garbage collector which checks for any existing references in the Flash memory space. If none are found (no other reference is made to the orphaned object), it is removed from memory. For this reason, memory management in ActionScript requires careful application development planning.
<syntaxhighlight lang="actionscript">
var item1: XML = new XML("<node><child /></node>");
Line 293 ⟶ 291:
 
==Code protection==
Like most [[bytecode]] file formats, Flash [[SWF]] files can be [[decompilation|decompiled]] into their source code and assets (similarly to how [[.NET Framework|Microsoft .NET]] files can be decompiled). Some decompilers are capable of nearly full reconstruction of the original source file, downapproximate to the actual code that was used during creation (although results vary on a case-by-case basis).<ref>{{cite web |url=http://www.flashmagazine.com/reviews/detail/review_trillix_flash_decompiler_3/ |title=Third party review of another decompiler |publisher=Flashmagazine.com |date=October 21, 2007 |access-date=April 22, 2013 |archive-url=https://web.archive.org/web/20170620134350/http://www.flashmagazine.com/reviews/detail/review_trillix_flash_decompiler_3/ |archive-date=June 20, 2017 |url-status=dead }}</ref><ref>{{cite web |url=http://www.topshareware.com/reviews/10386-1/flash-decompiler.htm |title=Customer comments on one Flash decompiler |publisher=Topshareware.com |access-date=April 22, 2013 |archive-date=November 8, 2016 |archive-url=https://web.archive.org/web/20161108235827/http://www.topshareware.com/reviews/10386-1/flash-decompiler.htm |url-status=dead }}</ref><ref>[http://www.macupdate.com/reviews.php?id=11541 Customer comments on another Flash product] {{webarchive |url=https://web.archive.org/web/20060818085731/http://www.macupdate.com/reviews.php?id=11541 |date=August 18, 2006 }}</ref>
 
In opposition to the decompilers, ActionScript [[obfuscated code|obfuscators]] have been introduced, which transform code into a form that breaks decompiler output while preserving the functionality and structure of the program. Higher-quality obfuscators implement lexical transformations such as identifier renaming, control flow transformation, and data abstraction transformation which collectively make it harder for decompilers to generate output likely to be useful to a human. Less robust obfuscators insert traps for decompilers. Such obfuscators either cause the decompiler software to crash unexpectedly or to generate unintelligible source code.{{Citation needed|date=March 2021}}
 
The following is an example of ActionScript 3.0 code generated by a decompiler program, before and after obfuscation.{{Original research inline|date=March 2021}}
 
Code before obfuscation:
 
<syntaxhighlight lang="actionscript3">
private function getNeighbours(i: int, j: int): Array
{
var a: Array = new Array();
for (var k = 0; k < 8; k++){
var ni = i + int(neighbour_map[k][1]);
var nj = j + int(neighbour_map[k][1]);
if (ni < 0 || ni >= xsize || nj < 0 || nj >= ysize)
continue;
a.push(Cell(cells[ni][nj]));
}
return a;
}
</syntaxhighlight>
 
Code after obfuscation:
 
<syntaxhighlight lang="actionscript3">
private function getNeighbours(_arg1: int, _arg2: int): Array
{
var _local3: Array = -(((boolean - !BOOLEAN!) % ~(undefined)));
var _local4: *;
var _local5: *;
var _local6: *;
_local3 = Array();
_local4 = 1;
for (;//unresolved jump
, _arg2 < 8;_local4++) {
_local5 = (_arg1 + int(!BOOLEAN!));
_local6 = (_arg2 + int(!BOOLEAN!));
if (true){
_arg1 = (((//unresolved nextvalue or nextname << !BOOLEAN!) + !BOOLEAN!)
<< defined);
_arg1 = (!(!BOOLEAN!) ^ !BOOLEAN!);
(!BOOLEAN! instanceof !BOOLEAN!);
var _local1 = (((!BOOLEAN! as !BOOLEAN!) + !BOOLEAN!) == this);
if (!(!BOOEAN! == !BOOLEAN!)){
-((true << !BOOLEAN!)).push(Cell(cells[_local5][_local6]));
}
}
if (!true){
(_local6 < 1):
(_local6 < 1);
(_local5 < 1);
}
}
return (_local6);
}
</syntaxhighlight>
 
==References==
{{Reflist|80em}}
 
==External links==
Line 358 ⟶ 302:
{{Wikibooks|Introduction to ActionScript 2.0}}
{{Wikiversity|ActionScript:Introduction}}
* [https://{{Official website|www.adobe.com/devnet/actionscript/}}, ActionScript Technology Center]
* [http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=Part2_AS2_LangRef_1.html ActionScript 2.0 Language Reference] {{Webarchive|url=https://web.archive.org/web/20130131044759/http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=Part2_AS2_LangRef_1.html |date=January 31, 2013 }}
* [http://help.adobe.com/en_US/AS3LCR/Flash_10.0/ ActionScript 3.0 Language & Component Reference]
** [http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/language-elements.html Language Elements]
Line 368 ⟶ 312:
* [https://web.archive.org/web/20100304105648/http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+3/ Adobe Flex SDK]
* {{cite web |url=https://www.theverge.com/2017/7/25/16026236/adobe-flash-end-of-support-2020 |title=Adobe will finally kill Flash in 2020 |last=Warren |first=Tom |date=July 25, 2017 |website=The Verge |access-date=December 16, 2020 |archive-url=https://web.archive.org/web/20170725190530/https://www.theverge.com/2017/7/25/16026236/adobe-flash-end-of-support-2020 |archive-date=July 25, 2017 |url-status=live}}
 
{{Adobe Flash|state=uncollapsed}}
{{ECMAScript}}
Line 382 ⟶ 327:
[[Category:High-level programming languages]]
[[Category:Programming languages compiled to bytecode]]
<!-- Hidden categories below -->
[[Category:Articles with example JavaScript code]]
[[Category:Statically typed programming languages]]