Table of Contents

Flash - Action Script

Basic syntax

//variable
var varName:String="valueData";
// type: Number, Interger, Boolean
 
//function
function funName():void { }
 
//as3 only:events
objName.addEventListener(MouseEvent.CLICK, funName);
function funName(event:MouseEvent): void { }
// event type: keyboard event
 
// classes
package { 
import flash.display.MovieClip
public class MyClass extends MovieClip
{
public function MyClass() {}
}
}
// conditional statements
if (condition) { } else { }
// loops
for (var i:Number=0;i<10;i++) { }

Programming structure with ActionScript

  1. (main stage) frame-label based state switch screen linear structure
    • hard to manage large amount of status
    •  on(click){_parent.gotoAndStop(theFrame)}
  2. (button click) movieclip attaching structure
    •  on(click){_parent.attachMovie(theMC, "currentScreen",0);}
      //overwrites, and with mc as export for actionscript
  3. form based screen non-linear structure
    • only exists in Flash MX 2004, Flash 8, CS3 and CS4, CS5 has dropped it

Programming with interaction and game like feedback

Element Scripting

button

// actionscript 2.0
box_mc.onRollOver = function():Void
{ box_mc.gotoAndStop(2); };
 
box_mc.onRollOut = function():Void
{ box_mc.gotoAndStop(1);};
 
box_mc.onPress = function():Void
{ trace("Mouse was pressed down.");};
 
box_mc.onRelease = function():Void
{ trace("Clicked the button.");};
 
// actionscript 3.0
box_mc.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler); // or MouseEvent.ROLL_OVER
box_mc.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler); // or MouseEvent.ROLL_OUT
box_mc.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
box_mc.addEventListener(MouseEvent.CLICK, mouseClickHandler); // or MouseEvent.MOUSE_UP
 
box_mc.buttonMode = true; // enables use of hand cursor
 
function mouseOverHandler($e:MouseEvent):void
{  box_mc.gotoAndStop(2);}
 
function mouseOutHandler($e:MouseEvent):void
{  box_mc.gotoAndStop(1);}
 
function mouseDownHandler($e:MouseEvent):void
{  trace("Mouse was pressed down.");}
 
function mouseClickHandler($e:MouseEvent):void
{  trace("Clicked the button.");}

component flvplayer

// change flv content, instance name as "flv_view"
// as2
flv_view.contentPath = "heart3d.flv";
 
// as3
flv_view.source = "heart3d.flv";

Drawing element

actionscript 2

external script loader

#include "externalfile.As"

XML loader

var myXML:XML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = function (success:Boolean):Void{
	var colors:XML = this.firstChild;
	for (x=0;x<colors.childNodes.length;x++){
		var node:XMLNode = colors.childNodes[x];
		yourActionFun({label:node.attributes.label, data:node.attributes.data});
	}
}
myXML.load("colors.xml");

text field

// ActionScript 2.0
createTextField("theTextField", 0, 10, 10, 100, 100);
theTextField.type = "input";
theTextField.border = true;
theTextField.multiline = true;
theTextField.wordWrap = true;

actionscript 3

difference in ActionScript 3

external as loader

include "scripts/myscript.as"

xml loader

var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("data.xml"));

FLV loader

// load flv function

text field

// ActionScript 3.0
var theTextField:TextField = new TextField();
theTextField.type = TextFieldType.INPUT;
theTextField.border = true;
theTextField.x = 10;
theTextField.y = 10;
theTextField.multiline = true;
theTextField.wordWrap = true;
addChild(theTextField);

image loader

var myholder=new Loader();
myholder.load(newURLRequest("Photo1.jpg"));
 
//add to stage at position
myholder.x=20;
myholder.y=20;
myholder.name="test";
addChild(myholder);
 
//change holder content
myholder=new Loader();
myholder.load(newURLRequest("Landscape1.jpg"));
 
//update
myholder.x=30;
myholder.y=30;
addChild(myholder);

movieclip control

fk/ik animation control

Common js_fl_script for flash UI interaction

Common config:

get js_fl interaction script from history panel

Display the commands

  1. open “history panel”
  2. right on panel > view > “JavaScript in panel”
  3. note: what you see in history panel is what the command drives

Execute the commands

  1. copy the command to a text file, save as “Name.jsfl”
  2. go to Command menu > Run command … (load that file) to run

jsfl script

SWF UI created in Flash for Flash

reference: http://www.gotoandlearn.com/play.php?id=66 (source)

jsfl api reference

Flash - Online Application Development

embed flash in html

<object width="550" height="400">
<param name="movie" value="somefilename.swf">
<embed src="somefilename.swf" width="550" height="400">
</embed>
</object>

XML server communication

Flash → data.xml → PHP <PROCESS XML> PHP → data.xml → Flash

flash data driven app structure

Flex - development environment

Flash Open Component

Best Flash Game I like

Flash Developer Blogs