actionscript 3 with flashdevelop3

4

Click here to load reader

Upload: juga-paazmaya

Post on 28-Jun-2015

42 views

Category:

Technology


1 download

DESCRIPTION

Originally published at PAAZMAYA.com in 14th Nov 2007. Creating rich Internet applications has become more easier but also more demanding. Flex 2 SDK and FlashDevelop3 offers an free way of building Flash 9 applications. This document describes how to install the latest versions of these tools and how to start some initial Flash programming.

TRANSCRIPT

Page 1: Actionscript 3 with FlashDevelop3

Actionscript 3 with FlashDevelop3 v1.0 : 14/11/2007

Jukka Paasonen 1(4)

Creating rich Internet applications has become more easier but also more demanding.

Flex 2 SDK and FlashDevelop3 offers an free way of building Flash 9 applications.This document describes how to install the latest versions of these tools and how to startsome initial Flash programming.

Installation

First download Flex 2 SDK from Adobe.com:

http://www.adobe.com/products/flex/downloads/http://download.macromedia.com/pub/flex/sdk/flex2_sdk_hf1.zip

FlashDevelop3 also works with the beta version of Flex SDK, in case you wish to use that. Itoffers the possibility to compile Air applications for example.

Second thing is to get the latest FlashDevelop3. You can download it from:

http://www.flashdevelop.org/community/index.phpsection “releases”. As the time of writing, it is beta 3.

If you like to try out the latest development build, go to:http://www.flashdevelop.org/community/viewtopic.php?t=1734

Installation is rather straight forward, unzip the Flex 2 SDK wherever you like and afterinstalling FlashDevelop3, change the AS3 plugin settings to point in the Flex SDK directory.

This can be found from “Tools – Installed Plugins – AS3Context”. Image 1 hopefully clearsthis a bit.

Image 1. FlashDevelop3 AS3Context plugin settings dialog.

Page 2: Actionscript 3 with FlashDevelop3

Actionscript 3 with FlashDevelop3 v1.0 : 14/11/2007

Jukka Paasonen 2(4)

Programming

Writing code in plain Actionscript 3, which then in turn is compiled to AVM2 byte code by

using Flex SDK, requires some additional care.Each file you write must belong to a package. You can consider this to be a hint for thecompiler of what are the limits of your codes scope.

Usually when writing code in Flash authoring tool, the tool itself takes care of this and thescope is usually the movie clip you are working on.

Another thing is to note that Actionscript 3 is heavily Object Oriented and you shouldalways use classes, possibly extending those, which already exist in the SDK.

The short example here shows how the structure of Actionscript 3 class looks like, complete

file (FlagFinland.as) available at http://paazio.nanbudo.fi/, where you downloaded thisdocument too.

The basic structure usually follows the formula below:

package {

import flash.display.Sprite;

import flash.events.Event;

[SWF(width="360", height="220", frameRate="33", backgroundColor="#FFFFFF")]

public class FlagFinland extends Sprite {

public function FlagFinland() {

this.loaderInfo.addEventListener(Event.INIT, init);

}

private function init(evt:Event):void {

// Draw graphics here...

}

}

}

This time I will build an small application to draw the Finnish flag. For that, I need to addsome more imports:

Page 3: Actionscript 3 with FlashDevelop3

Actionscript 3 with FlashDevelop3 v1.0 : 14/11/2007

Jukka Paasonen 3(4)

import flash.display.Graphics;

import flash.display.Sprite;

import flash.display.StageAlign;

import flash.display.StageDisplayState;

import flash.display.StageQuality;

import flash.display.StageScaleMode;

import flash.events.Event;

Notice the several “Stage...” imports. They are all used to set proper scaling and alignment.

These are usually set in the constructor function:

public function FlagFinland() {

stage.align = StageAlign.TOP_LEFT;

stage.scaleMode = StageScaleMode.NO_SCALE;

stage.quality = StageQuality.MEDIUM;

stage.addEventListener(Event.RESIZE, onResize);

this.loaderInfo.addEventListener(Event.INIT, init);

}

There are two event listeners defined. The first one for resizing and the second to be runwhen the whole flash file has been loaded:

private function init(evt:Event):void {

drawFlag();

}

private function onResize(evt:Event):void {

drawFlag();

}

Both of these call the same function, which in turn will do the drawing. That function and

the complete package is available at http://paazio.nanbudo.fi/

Page 4: Actionscript 3 with FlashDevelop3

Actionscript 3 with FlashDevelop3 v1.0 : 14/11/2007

Jukka Paasonen 4(4)

Compiling of the file is easy, just click on the “Build Current File” button on the toolbar, as

shown in image 2.

Image 2. Toolbar with the compile button hovered.