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!
==Syntax== ActionScript code is [[free-form language|free form]] and thus may be created with whichever amount or style of whitespace that the author desires. The basic syntax is derived from [[ECMAScript]]. ===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 [[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); greet.text = "Hello, world"; </syntaxhighlight> When writing external ActionScript 2.0 class files the above example could be written in a file named {{Mono|Greeter.as}} as following. <syntaxhighlight lang="actionscript"> class com.example.Greeter extends MovieClip { public function Greeter() { var txtHello: TextField = this.createTextField("txtHello", 0, 0, 0, 100, 100); txtHello.text = "Hello, world"; } } </syntaxhighlight> ===ActionScript 3.0=== ActionScript 3.0 has a similar syntax to ActionScript 2.0, but a different set of APIs for creating objects. Compare the script below to the previous ActionScript 2.0 version: <syntaxhighlight lang="actionscript3"> var txtHello: TextField = new TextField(); txtHello.text = "Hello World"; this.addChild(txtHello); </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}}: <syntaxhighlight lang="actionscript3"> package com.example { import flash.text.TextField; import flash.display.Sprite; public class Greeter extends Sprite { public function Greeter() { var txtHello: TextField = new TextField(); txtHello.text = "Hello World"; this.addChild(txtHello); } } } </syntaxhighlight> {{See also|Sprite (computer graphics)}} ActionScript 3 can also be used in [[MXML]] files when using [[Apache Flex|Apache's Flex]] framework: <syntaxhighlight lang="mxml"> <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/mx/polysylabi" xmlns:mx="library://ns.adobe.com/flex/mx" layout="vertical" creationComplete="initApp()"> <fx:Script> <![CDATA[ public function initApp(): void { // Prints our "Hello, world!" message into title title.text = "Hello, World!"; } ]]> </fx:Script> <s:Label id="title" fontSize="54" fontStyle="bold" /> </s:Application> </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)