Getting Started with ActionScript(Flex Programming)

03 / Nov / 2015 by Hari Shukla 0 comments

Flex is an open source framework which allows us to build traditional applications for browser, mobile and desktop. It provides flex SDK, you can download it from here , consisting of the MXML and ActionScript programming language and takes care of the user interface (UI) or the client-side functionality of a web application.

This post will help you to startup with flex programming in easy manner using ActionScript. ActionScript is an object-oriented programming (OOP) language that is designed specifically for Web site animation.

After Downloading flex SDK, unzip this by using following command,
$ unzip flex_sdk_4.6.zip -d flex_sdk_4.6

Set the path in .bashrc, using following command
$ vim  .bashrc
export PATH = $PATH:$FLEX_HOME/bin

You can check if your Flex SDK installation was successful, by run the following command:
$ mxmlc -version

Lets write a simple “Hello World” program. And save this file with the name HelloWorld.as

package {
import flash.display.Sprite;
import flash.text.TextField;
public class HelloWorld extends Sprite {
public function HelloWorld() {
var textField:TextField = new TextField();
textField.text = "Hello, World!";
addChild(textField);
}
}
}

Compile this by using the following command:
$ mxmlc HelloWorld.as

This will create HelloWorld.swf file as output. And this swf will embed into html.

<html>
<head>
  <title>ActionScript Demo</title>
  <script type="text/javascript" src="swfobject.js"></script>
</head>
<body>
<script language="javascript">
  var params = {};
  params.allowscriptaccess = "always";
  var attributes = {};
  attributes.align = "middle";
  swfobject.embedSWF("HelloWorld.swf", "flashContent", "640", "360", "11.1.0", "", {}, params, attributes);
</script>
<div id="flashContent"></div>
</body>
</html>

As you can see in the above html file, one JavaScript library named swfobject.js  is used .You can get the same from the following link swfobject.

Embed HelloWorld.swf file with the use of following javaScript method

swfobject.embedSWF(swfUrl,id,width,height,version,expressInstallSwfurl,flashvars,params,attributes,callbackFn)

Arguments:

  • swfUrl (String, required) specifies the URL of your SWF
  • id (String, required) specifies the id of the HTML element (containing your alternative content) you would like to have replaced by your Flash content
  • width (String, required) specifies the width of your SWF
  • height (String, required) specifies the height of your SWF
  • version (String, required) specifies the Flash player version your SWF is published for (format is: “major.minor.release” or “major”)
  • expressInstallSwfurl (String, optional) specifies the URL of your express install SWF and activates Adobe express install. Please note that express install will only fire once (the first time that it is invoked), that it is only supported by Flash Player 6.0.65 or higher on Win or Mac platforms, and that it requires a minimal SWF size of 310x137px.
  • flashvars (Object, optional) specifies your flashvars with name:value pairs
  • params (Object, optional) specifies your nested object element params with name:value pairs
  • attributes (Object, optional) specifies your object‘s attributes with name:value pairs
  • callbackFn (JavaScript function, optional) can be used to define a callback function that is called on both success or failure of creating a Flash plug-in <object> on the page (SWFObject 2.2+)

Where callbackFn is a JavaScript function that has an event object as a parameter:

function callbackFn(e) { ... }

You can get more details and in-depth knowledge about ActionScript at following link:

http://www.adobe.com/devnet/actionscript/documentation.html

FOUND THIS USEFUL? SHARE IT

Leave a Reply

Your email address will not be published. Required fields are marked *