Monday, September 17, 2007


Arrays are the same:

var verbs:Array = ["jumped", "ran", "flew"];

//2D array:
var multiD:Array = [
["row 0 col 0","row 0 col 1"],
["row 1 col 0","row 1 col 1"],
["row 2 col 0","row 2 col 1"],
["row 3 col 0","row 3 col 1"]

Here is a list of Properties:
array.pop() = This method removes the last item from an array
array.push() = The push method adds a series of values to the end of an existing array
array.shift() = removes a value from the beginning of array
array.unshift() = adds a value or series of values to the beginning of your array
array.concat() = merges two arrays together ... arrayOne.concat(arrayTwo);
array.slice() = can create array with certain elements of existing array
array.sort() = will sort an array (alphabetically by default)
array.reverse() = Reverses the direction of an array.
slice() = Extracts a section of an array and returns it as a new array.
array.toString = Returns a string value representing the elements in the Array object.

var myArray:Array = new Array(); //creates a new blank array

some links to help:
Adobe Array Help

Thursday, September 6, 2007

Text Fields

This is how you can create a new text field with actionscript yo (amongst other things):
var myText:TextField = new TextField(); //make a new text field
var myFormat:TextFormat = new TextFormat(); //make text format object

myFormat.font = "Verdana"; //set font
myFormat.color = 0xFF0000; //set text color
myFormat.size = 14; //set size

addChild(myText); //add it to the stage (top-left)
myText.text = "text goes in here"; //put text into it
myText.autoSize = TextFieldAutoSize.LEFT; //text will auto size from the left

myText.setTextFormat(myFormat); //You need this before you can modify proporties

Capture data from text field:
//assuming there is a button called "submit_btn" and a text field called "name_txt"

var body_txt:TextField = new TextField(); //create a text field called "body_txt"
yourName:String; //set up variable
body_txt.x = 98; //you can place text where ever
body_txt.y = 66;

submit_btn.addEventListener(mouseEvent.CLICK, onClick); //set up click mouse event

function onClick(event:MouseEvent):void{
addChild(body_txt); //place body_txt on stage (this is where user will type)
yourName = body_txt.text; //put whatever user types into yourName variable
name_txt.text = "Hi " + yourName + "!"; //put that text in the name_txt field (plus "hi")

Loading External Text File:
//Assume there's a field called external_txt

var externalReq:URLRequest = new URLRequest("news.txt"); //new URL Request (request file)
var externalLoad:URLLoader = new URLLoader(); //new URL Loader

externalLoad.load(externalReq); //Start Loading

externalLoad.addEventListener(Event.COMPLETE, textReady); //Listen for load completion

external_txt.wordWrap = true; //this will wrap the text

function textReady(event:Event):void{
external_txt.text =; //places data in txt file into text field

Scroll Text
Assume there is a text field full of dynamic text called myText_txt. Also assume there is a button called up_btn and one called down_btn:

up_btn.addEventListener(MouseEvent.CLICK, scrollUp);
down_btn.addEventListener(MouseEvent.CLICK, scrollDown);

function scrollUp(event:MouseEvent):void{
external_txt.scrollV --; //this moves the text down

function scrollDown(event:MouseEvent):void{
external_txt.scrollV ++; //this moves the text up