Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
ActionScript
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Data structures== ===Data types=== ActionScript primarily consists of "fundamental" or "simple" data types that are used to create other data types. These data types are very similar to [[Java (programming language)|Java]] data types. Since ActionScript 3 was a complete rewrite of ActionScript 2, the data types and their inheritances have changed. '''ActionScript 2 top level data types''' * '''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''' 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 MovieClip 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''' * '''NetConnection''' * '''MovieClipLoader''' * '''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. No 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, null. 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]]). The 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>), and floating-point values 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 stored internally as Unicode characters, using the [[UTF-16]] format. Previous versions of Flash used the UTF-8 format. * '''uint''': The uint (unsigned integer) 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 null. '''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 (support 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 object that allows runtime error reporting when thrown as an exception. * '''flash.display:Bitmap''': A non-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 without a timeline. * '''flash.media:Video''': A video playback object supporting direct (progressive download) or streaming (RTMP) transports. As of Flash Player version 9.0.115.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 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 10 or above. Vectors are typed, dense Arrays (values must be defined or null) 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 XML class. ===Using data types=== The basic syntax is: <syntaxhighlight lang="actionscript"> var variableName: VariableType = new VariableType(param1, param2, ..., paramN); </syntaxhighlight> So in order to make an empty Object: <syntaxhighlight lang="actionscript"> var myObject: Object = new Object(); </syntaxhighlight> Or, in an informal way: <syntaxhighlight lang="actionscript"> var myObject = {}; </syntaxhighlight> Some types are automatically put in place: <syntaxhighlight lang="actionscript"> var myString: String = "Hello Wikipedia!"; // This would automatically set the variable as a string. var myNumber: Number = 5; // This would do the same for a number. var myObject: Object = { param1: "Hi!", param2: 76 }; // This creates an object with two variables. // param1 is a string with the data of "Hi!", // and param2 is a number with the data of 76. // This is the syntax for automatically creating an Array. var myArray: Array = [5, "Hello!", { a: 5, b: 7 }]; // It creates an Array with 3 variables. // The first (0) is a number with the value of 5, // the second (1) is a string with the value of "Hello!", // 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. Some data types can be assigned values with [[Object literal|literals]]: <syntaxhighlight lang="actionscript"> var item1: String = "ABC"; var item2: Boolean = true; var item3: Number = 12; var item4: Array = ["a", "b", "c"]; var item5: Object = { name: "Actionscript", version: "3.0" }; var item6: XML = <node><child /></node>; // Note that the primitive XML is not quoted </syntaxhighlight> A reference in ActionScript is a pointer to an instance of a class. A reference stores the memory address of an object β operations against references will follow the value of the reference to the memory address of the object and carry out the operation on that object. All objects in ActionScript are accessed through references instead of being accessed directly. <syntaxhighlight lang="actionscript"> var item1: XML = new XML("<node><child /></node>"); var item2: XML = item1; item2.firstChild.attributes.value = 13; // item1 now equals item2 since item2 simply points to what item1 points to. // Both are now: // <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>"); delete item1; // If no other reference to item1 is present anywhere else in the application, // it will be removed on the garbage collector's next pass </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)