Objects and Methods


Objects and Methods

Flash 5 includes a number of built-in objects. These include everything from the most basic object of them all, the Object object, to the XMLSocket object which handles the transfer of XML data over a TCP/IP socket. The built-in objects in Flash 5 are:

  • Array. An Array object holds a list of data.

  • Boolean. A Boolean object acts as an object wrapper to true/false values.

  • Color . A Color object is used to modify the color of a movie clip with code.

  • Date. A Date object holds and formats all types of date and time information.

  • Key. The Key object is used to track keyboard presses.

  • Math. The Math object acts as a library for complex math operators and functions.

  • Mouse. The Mouse object is used show or hide the mouse pointer.

  • MovieClip. A MovieClip object points to an actual movie clip on the stage.

  • Number. A Number object acts as an object wrapper to normal numbers .

  • Object. An Object object is just a blank object with no methods or properties.

  • Selection. The Selection object is used to set and get information about focus and selected areas of text fields.

  • Sound. A Sound object controls the playback of a sound, including pan and volume.

  • String. A String object acts as an object wrapper to normal strings.

  • XML. A XML object allows for the loading, manipulation, and sending of XML data.

  • XMLSocket. A XMLSocket object allows for the sending and reception of XML data over a socket connection.

Each of these objects is outlined in the following sections, including the object's constructor function, as well as the object's methods and properties. The constructor function is used to instantiate, or create a new instance of, an object. Top-level objects, such as Key and Math, can be accessed without using constructors. The methods are used to control the behavior of the object, and the properties describe attributes or characteristics of the object.

Array Object

Constructor with Syntax

Arguments

new Array();

length

The number of elements in the array.

new Array(length);

new Array(element0, element1, element2...element N );

element0...element N

Elements that can be passed into the array.

Method with Syntax

Description

Arguments

myArray. concat (value0, value1...valueN);

Concatenates the elements specified in the arguments and creates a new array.

value0, value1...value N

Elements to be concatenated in a new array.

myArray. join (); myArray. join (separator);

Concatenates the converted string elements and inserts the separator between them.

separator

A character or string to separate the array elements.

myArray. pop ();

Removes the last element from an array and returns the value of that element.

 

myArray. push (value);

Adds the element in value to the end of the array.

value

The element to be added to the array.

myArray. reverse ();

Reverses the order of the array.

 

myArray. shift ();

Removes the first element of the array and returns the value.

 

myArray. slice (start, end);

Extracts the values contained between the start (inclusive) and end (not inclusive) value and returns it as a new array without modifying the old one.

start

Number specifying the start of the slice.

end

Ending point of the slice.

myArray. sort ();

myArray. sort (orderfunc);

Sorts the array without making a copy.

orderfunc

An optional comparison to set sorting order.

myArray. splice (start, deleteCount, value0, value1...value N );

Adds and removes elements in an array; modifies the array without making a copy.

start

Beginning point to the insert/delete in the array.

deleteCount

Deletes all values from the start to the last element of the array.

value

The elements to be inserted.

myArray. toString ();

Returns the elements in the array as a string.

 

myArray. unshift (value1, value2...value N );

Adds elements to the beginning of the array; returns the length of the array.

value

The elements to be inserted.

Properties with Syntax

Description

myArray. length;

Number of entries in the array.

Color Object

Constructor with Syntax

Arguments

new Color (target);

target

The name of the movie clip to apply the color to.

Method with Syntax

Description

Arguments

myColor. getRGB ();

Returns the RGB value of the color in numeric form.

 

myColor. getTransform ();

Returns the transform value set by setTransform.

 

myColor. setRGB (0xRRGGBB);

Sets the RGB value.

0xRRGGBB

The red, green, and blue values in hexadecimal form.

myColor. setTransform (0xRRGGBBAA);

Sets the color transform of the object.

0xRRGGBBAA

The percentage and offset values for the red, green, blue, and alpha of an object in hexadecimal form.

Date Object

Constructor with Syntax

Arguments

new Date();

new Date(year, month, date, hour , min, sec, ms);

year

Value of 0 “99 representing 1900 “1999; four digits needed for other years .

month

0 (January) “11 (December).

date

1 “31.

hour

0 (midnight) “23 (11 p.m.).

min, sec

0 “59.

ms

0 “999.

Method with Syntax

Description

Arguments

myDate. getDate ();

Returns the day of the month (1 “31).

 

myDate. getDay ();

Returns the day of the week (0 “6).

 

myDate. getFullYear ();

Returns the four-digit year.

 

myDate. getHours ();

Returns the hour (0 “23).

 

myDate. getMiliseconds ();

Returns the milliseconds (0 “999).

 

myDate. getMinutes ();

Returns the minutes (0 “59).

 

myDate. getMonth ();

Returns the month (0 “11).

 

myDate. getSeconds ();

Returns the seconds (0 “59).

 

myDate. getTime ();

Returns the number of milliseconds that have elapsed since January 1, 1970, UT.

 

myDate. getTimezoneOffset ();

Returns the difference between UT and the local time.

 

myDate. getUTCDate ();

Returns the day of the month (1 “31) UT.

 

myDate. getUTCDay ();

Returns the day of the week (0 “6) UT.

 

myDate. getUTCFullYear ();

Returns the four-digit year UT.

 

myDate. getUTCHours ();

Returns the hour (0 “23) UT.

 

myDate. getUTCMiliseconds ();

Returns the milliseconds (0 “999) UT.

 

myDate. getUTCMinutes ();

Returns the minutes (0 “59) UT.

 

myDate. getUTCMonth ();

Returns the month (0 “11) UT.

 

myDate. getUTCSeconds ();

Returns the seconds (0 “59) UT.

 

myDate. getYear ();

Returns the year according to local time.

 

myDate. UTC (year, month, date, hour, min, sec, ms)

Returns the number of milliseconds between January 1, 1970, and the date specified in the argument.

year

Value of 0 “99 representing 1900 “1999; four digits needed for other years.

month

0 (January) “11 (December).

date

1 “31.

hour

0 (midnight) “23 (11 p.m.).

min, sec

0 “59.

ms

0 “999.

myDate. setDate (date);

Sets the day of the month.

date

1 “31.

myDate. setFullYear (year, month, date);

Sets the year, month, and date.

year

The date of the year in four digits.

month

0 (January) “11 (December).

date

1 “31.

myDate. setHours (hour, min, sec, ms);

Sets the hour, minute, second, and millisecond.

hour

0 (midnight) “23 (11 p.m.).

min, sec

0 “59.

ms

0 “999.

Method with Syntax

Description

Arguments

myDate. setMiliseconds (ms);

Sets the milliseconds.

ms

0 “999.

myDate. setMinutes (minutes, seconds, ms);

Sets the minute, second, and millisecond.

min, sec

0 “59.

ms

0 “999.

myDate. setMonth (month,date);

Sets the month and date.

month

0 (January) “11 (December).

date

1 “31.

myDate. setSeconds (seconds,ms);

Sets the seconds.

sec

0 “59.

ms

0 “999.

myDate. setTime (value)

Sets the number of milliseconds that have elapsed since January 1, 1970.

value

The elapsed time.

myDate. setUTCDate (date);

Sets the day of the month in UT.

date

1 “31.

myDate. setUTCFullYear (year, month, date);

Sets the year, month, and date in UT.

year

The date of the year in four digits.

month

0 (January) “11 (December).

date

1 “31.

myDate. setUTCHours (hour, min, sec, ms);

Sets the hour, minute, second, and millisecond in UT.

hour

0 (midnight) “23 (11 p.m.).

min, sec

0 “59.

ms

0 “999.

myDate. setUTCMiliseconds (ms);

Sets the milliseconds.

ms

0 “999.

myDate. setUTCMinutes (minutes,seconds, ms);

Sets the minute, second, and millisecond in UT.

min, sec

0 “59.

ms

0 “999.

myDate. setUTCMonth (month, date);

Sets the month and date in UT.

month

0 (January) “11 (December).

date

1 “31.

myDate. setUTCSeconds (seconds,ms);

Sets the seconds in UT.

sec

0 “59.

ms

0 “999.

myDate. setYear (year);

Sets the year.

year

A four-digit integer for the year.

myDate. toString ();

Returns a string of the date in a readable form.

 

Key Object

Method with Syntax

Description

Arguments

Key. getAscii ();

Returns the ASCII value of the last key pressed.

 

Key. getCode ();

Returns the virtual key code of the last key pressed.

 

Key. isDown ( keycode );

Returns true if the key listed in keycode is depressed.

keycode

A numerical code assigned to each key.

Key. isToggled (keycode);

Returns true if the Num Lock or Caps Key is activated.

keycode

A numerical code assigned to each key.

Properties with Syntax

Description

Key. BACKSPACE;

Keycode for the Backspace key.

Key. CAPSLOCK;

Keycode for the Caps Lock key.

Key. CONTROL;

Keycode for the Control key.

Key. DELETEKEY;

Keycode for the Delete key.

Key. DOWN;

Keycode for the Down Arrow key.

Key. END;

Keycode for the End key.

Key. ENTER;

Keycode for the Enter key.

Key. ESCAPE;

Keycode for the Escape key.

Key. HOME;

Keycode for the Home key.

Key. INSERT;

Keycode for the Insert key.

Key. LEFT;

Keycode for the Left Arrow key.

Key. PGDN;

Keycode for the Page Down key.

Key. PGUP;

Keycode for the Page Up key.

Key. RIGHT;

Keycode for the Right Arrow key.

Key. SHIFT;

Keycode for the Shift Key.

Key. SPACE;

Keycode for the Space key.

Key. TAB;

Keycode for the Tab key.

Key. UP;

Keycode for the Up Arrow key.

Math Object

Method with Syntax

Description

Arguments

Math. abs (x);

Returns the absolute value.

x

Any number.

Math. acos (x);

Returns the arc cosine of the number in radians.

x

A number from “1.0 to 1.0.

Math. asin (x);

Returns the arc sine of the number in radians.

x

A number from “1.0 to 1.0.

Math. atan (x);

Returns the arc tangent of the number in radians.

x

Any number.

Math. atan2 (y,x);

Returns the arc tangent of y/x in radians.

y

The y-axis point.

x

The x-axis point.

Math. ceil (x);

Returns the closest integer that is greater or equal to the number.

x

A number or expression.

Math. cos (x);

Returns the cosine of the number in radians.

x

An angle measured in radians.

Math. exp (x);

Returns the value of the base of the natural algorithm.

x

The exponent; a number or expression.

Math. floor (x);

Returns the closest integer less than or equal to the number.

x

A number or expression.

Math. log (x);

Returns the natural logarithm of the number.

x

A number or expression greater than 0.

Math. max (x,y);

Evaluates x and y and returns the larger number.

x

A number or expression.

y

A number or expression.

Math. min (x, y);

Evaluates x and y and returns the smaller number.

x

A number or expression.

y

A number or expression.

Math. pow (base, exponent);

Computes base to the power of exponent (base exponent ).

base

A number to be raised to a power.

exponent

The number to which the base is raised.

Math. random ();

Returns a random number between 0 and 1.

 

Math. round (x);

Rounds the value to the nearest integer.

x

Any number.

Math. sin (x);

Returns the value of sine in radians.

x

An angle measured in radians.

Math. sqrt (x);

Returns the square root of the number.

x

A number or expression greater than 0.

Math.tan(x);

Returns the tangent of the number in radians.

x

An angle measured in radians.

Properties with Syntax

Description

Math. E;

Euler's constant; the base of natural logarithms expressed as e.

Math. LN2;

Natural log of 2.

Math. LOG2E;

Base 2 of the log of e.

Math. LN10;

Natural log of 10.

Math. LOG10E;

Base 10 of the log of e.

Math. PI;

Value of pi with a value of 3.14159265358979.

Math. SQRT1_2;

Reciprocal of the square root of 1/2; has the approximate value of .707106781186.

Math. SQRT2;

Square root of 2 with the approximate value of 1.414213562373.

Mouse Object

Method with Syntax

Description

Mouse. hide ();

Hides the mouse pointer.

Mouse. show ();

Shows the mouse pointer.

Properties with Syntax

Description

_xmouse

Gets the x position of the mouse pointer.

_ymouse

Gets the y position of the mouse pointer.

MovieClip Object

Method with Syntax

Description

Arguments

anyMovieClip. attachMovie (idname, newname, depth);

Creates a new instance of the movie clip and attaches it.

idname

The name given in the Linkage dialog box in the Library.

newname

A unique name for the instance of the movie clip being placed.

depth

The depth level of the movie clip.

anyMovieClip. duplicateMovieClip (newname, depth);

Creates an instance of the movie clip; begins to play in frame 1.

newname

A unique name for the instance of the movie clip being placed.

depth

The depth level of the movie clip.

anyMovieClip. getBounds (targetCoordinateSpace);

Returns the minimum and maximum x and y coordinates.

target Coordinate Space

The target path of the timeline used as a reference point.

anyMovieClip.getBytes Loaded();

Returns the number of bytes loaded in a movie clip.

 

anyMovieClip.getBytes Total();

Returns the total number of bytes in a movie clip.

 

anyMovieClip. getURL (URL, window, variables );

Loads a document specified in the URL into a specified window.

URL

The URL of the document.

window

Specifies the frame or window to load the URL; blank opens a new window.

variables

Specifies how any variables will be sent.

anyMovieClip. globalToLocal (point);

Converts the point object from global (stage) to local (movie clip) coordinates.

point

The name of an object specifying the X and Y coordinates.

anyMovieClip. gotoAndPlay (frame);

Starts playing a movie at the specified frame.

frame

The frame number to start playing.

anyMovieClip. gotoAndStop (frame);

Goes to a specified frame in the movie and stops playing.

frame

The frame number to go to.

anyMovieClip. hitTest (x, y, shapeFlag);

anyMovieClip. hitTest ((target);

Checks to see if the movie clip specified overlaps with an area specified in target or X and Y coordinates.

x

The X coordinate of the hit area.

y

The Y coordinate of the hit area.

shapeFlag

A Boolean value to specify whether the bounding box (false) or entire shape (true) will be identified as the hit area.

target

The target path of the hit area.

anyMovieClip. loadMovie (url);

Loads additional Flash movies (SWF) without closing the current movie.

url

The URL of the SWF to load.

anyMovieClip. loadVariables (url, variables);

Reads data from an external text file into the movie.

url

The location of the text file.

variables

Method for retrieving the variables.

anyMovieClip. localToGlobal (point);

Converts the point object from the local (movie clip) to global (movie) coordinates.

point

The name of an object, specifying the X and Y coordinates.

anyMovieClip. nextFrame ();

Advances to the next frame.

 

anyMovieClip. play ();

Plays the movie clip.

 

anyMovieClip. prevFrame ();

Sends the playhead back a frame.

 

anyMovieClip. removeMovieClip ();

Removes the movie clip instance created with the duplicateMovieClip action.

 

Method with Syntax

Description

Arguments

anyMovieClip. startDrag (lockCenter,left,top,right,bottom);

Allows the movie clip to be draggable.

lockCenter

A Boolean value; specifies if the movie clip will be locked to the center position of the mouse (true) or not (false).

left, top, right, bottom

Values to constrain the drag of the movie clip.

anyMovieClip. stop ();

Stops the movie clip.

 

anyMovieClip. stopDrag ();

Ends the drag action of the movie clip.

 

anyMovieClip. swapDepths (depth);

anyMovieClip. swapDepths (target);

Swaps the stacking order of the movie clips.

depth

The depth level where the movie clip is to be placed.

target

The movie clip instance depth that is to be swapped with this movie clip.

anyMovieClip. unloadMovie ();

Removes the movie clip loaded using the loadMovie or attachMovie action.

 

Selection Object

Method with Syntax

Description

Arguments

Selection. getBeginIndex ();

Gets the index of the start of the selection.

 

Selection. getCaretIndex ();

Gets the index of the cursor position.

 

Selection. getEndIndex

Gets the index of the end of the selection.

 

Selection. getFocus ()

Sets the focus of the current text box.

 

Selection. setFocus (boxName)

Sets the focus of the text box named in textboxname.

boxName

The name of the text box to set focus.

Selection. setSelecton (beginIndex, endIndex);

Sets the selection in an editable text box.

beginIndex

The start index of the selection.

endIndex

The end index of the selection.

Sound Object

Constructor with Syntax

Arguments

new Sound(target);

target

The target path of the movie clip.

Method with Syntax

Description

Arguments

mySound. attachSound (idName);

Attaches the sound from the Library.

idName

The name set in the Linkage dialog box in the Library.

mySound. getPan ();

Gets the pan level.

 

mySound. getTransform ();

Gets the sound transform.

 

mySound. getVolume ();

Gets the volume level.

 

mySound. setPan (pan);

Sets the pan level.

pan

A number from “100 (left) “100 (right).

mySound. setTransform (transform);

Sets the sound transform.

transform

An object holding the sound transform parameters.

mySound. setVolume (volume);

Sets the volume.

volume

A number from 0 (no volume) “100 (highest volume).

mySound. start (secondsOffset, loops );

Plays the attached sound.

secondsOffset

The starting point of the sound.

loops

The number the sound will loop.

mySound. stop ();

Stops the sound.

 

String Object

Constructor with Syntax

Arguments

new String(value);

value

The value of the string object.

Method with Syntax

Description

Arguments

myString. charAt (index);

Returns the character located at index.

index

The position you wish to retrieve.

myString. charCodeAt (index);

Returns the character code of the character positioned at index.

index

The position you wish to retrieve.

myString. concat (string1, string2,...string N );

Concatenates a set of strings.

string1, string2, . . . string N

The strings to be concatenated.

myString. fromCharCode (char1, char2,...char N );

Returns a string made from the characters specified.

char1, char2,...char N

Characters made into a string.

myString. indexOf (string);

myString. indexOf (string, start);

Returns the position (index) of the first occurrence of the string.

string

The string to be searched for.

myString. lastIndexOf (string, start);

Returns the index of the last occurrence of the string.

start

The point to begin searching in the string.

myString. slice (start, end);

Returns the string between the start and end points.

start

The start point.

end

The end point.

myString. split ( delimiter );

Splits the string in a way specified in the delimiter.

delimiter

No delimiter returns the string; a delimiter of "" sets each character in the string to an element in a array.

myString. substr (start, length);

Returns the characters in a string specified in the start and length variables.

start

The position of the first character in the string at which to begin.

length

The number of characters to select.

myString. toLowerCase ();

Uppercase characters are converted to lowercase characters.

 

myString. toUpperCase ();

Lowercase characters are converted to uppercase characters.

 

Properties with Syntax

Description

myString. length ;

The number of characters in the string.

XML Object

Constructor with Syntax

Arguments

new XML();

new XML(source);

source

The XML document to be parsed by Flash.

Method with Syntax

Description

Arguments

myXML. appendChild ();

Appends the child node to the XML object's child list.

 

myXML. cloneNode (deep);

Creates a new node with the same name, type, and attributes.

deep

A Boolean value; true recursively clones the object.

myXML. createElement (name);

Creates a new XML element.

name

The tag name of the XML element to be created.

myXML. createTextNode (text);

Creates a new XML text node with text specified.

text

The next of the new node.

myXML. hasChildNodes ();

References the first child of a parent node; will return null if the object has no child nodes.

 

myXML. insertBefore (node, beforeNode);

Inserts node before the beforeNode.

node

The node to be inserted.

beforeNode

The node before the node to be inserted.

myXML. load (url);

Loads an XML document from URL.

url

The URL where the XML document is located.

myXML. parseXML (source);

Parses the XML text listed in source.

source

The XML text to be parsed.

myXML. removeNode ();

Removes the XML object from the parent.

 

myXML. send (url, window);

Encodes the XML object into an XML document and sends it the URL using POST.

window

The window to display the data.

myXML. sendAndLoad (ulr, targetXMLobject);

Encodes the XML object into an XML document, sends it to the specified URL, and loads the server's response into the targetXMLobject.

url

The url to send the object.

targetXMLobject

The object to receive the server response.

myXML. toString ();

Creates a string containing the node, children, and attributes of the XML object.

 

myXML. attributes

Returns an array with all the attributes specified in the XML object.

 

myXML. childNodes

Returns an array of the XML object's child nodes.

 

Properties with Syntax

Description

myXML. docTypeDec1;

Returns the XML document's DOCTYPE declaration.

myXML. firstChild;

Refers to the first child of the parent node.

myXML. lastChild;

Refers to the last child of the parent node.

myXML. loaded;

Returns true when the XML document is loaded.

myXML. nextSibling;

Refers to the next sibling of the parent node.

myXML. nodeName;

Returns the node name.

myXML. nodeType;

Returns a nodeType value; 1 is XML element and 3 is text node.

myXML. nodeValue;

Returns the value of the XML object; 1 is XML element and 3 is text node.

myXML. parentNode;

Refers to the parent node.

myXML. previousSibling;

Refers to the previous sibling.

myXML. status;

Returns a numeric value to indicate if the XML document has been successfully parsed.

myXML. xmlDec1;

Sets and returns information about the document's XML declaration.

XMLSocket Object

Constructor with Syntax

Arguments

new XMLSocket();

None

Method with Syntax

Description

Arguments

myXMLSocket. close ();

Closes the XMLSocket connection.

 

myXMLSocket. connect (host, port);

Establishes a connection to host using the specified port.

host

The full domain name.

null

Connects to the file host server.

port

The TCP number used to connect; must be higher than 1024.

myXMLSocket. onClose ();

Is invoked only when an open connection is closed by the server.

 

myXMLSocket. onConnect(success);

A function invoked when a connection request is initiated.

success

A Boolean value that indicates if the connection is successful.

myXMLSocket. onXML (object);

Used to transfer XML documents between the client and server.

object

The XML object to be received by the server.

myXMLSocket. send (object);

Converts object to a string and sends the data to the server.

object

The object to transmit to the server.



Inside Flash
Inside Flash MX (2nd Edition) (Inside (New Riders))
ISBN: 0735712549
EAN: 2147483647
Year: 2005
Pages: 257
Authors: Jody Keating

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net