Monday, November 30, 2009

Hello World in ActionScript

If you are an old-school programmer (which doesn't necessarily mean better --that will always depend on the subject), when learning a language you always look for the simplest program that print "hello world" and that you can create with "vi".
Well, if you want to start some development in ActionScript then you might be troubled trying to find a "hello world" source code program to start familiarizing with the language (most examples and tutorials assume that you are using a IDE).
In this case do the following:
1.- Download and install FlexSDK.
2.- Modify PATHs in order to be able to execute the programs coming in flexsdk (e.g. the compiler mxmlc).
3.- Open a text file named "hello.as", paste and save the following:

package {
import flash.display.*;
import flash.text.*;

public class hello extends Sprite{
public function hello (){
var t:TextField = new TextField();
t.text = "Hello World";
t.width = 100;
t.height = 100;
t.x = 50;
t.y = 50;
addChild(t);
}
}
}

3.- Compile it: mxmlc hello.as (this will create hello.swf)
4.- Create an HTML file in your webserver with:

<html>
<body>
<object width="100" height="100">
<param name="movie" value="hello.swf">
<embed src="hello.swf" width="100" height="100">
</embed>
</object>
</body>
</html>
5.- VoilĂ ! your are seeing your first ActionScript program.

No comments:

Post a Comment