Tải bản đầy đủ (.pdf) (104 trang)

Tài liệu Flash: ActionScript Language Reference- P11 docx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (321.57 KB, 104 trang )

Video.height 1001
my_mc._height = my_mc.my_video.height;
};
See also
MovieClip._height, Video.width
1002 Chapter 2: ActionScript Language Reference
Video.smoothing
Availability
Flash Player 6.
Usage
my_video.smoothing:Boolean
Description
Property; a Boolean value that specifies whether the video should be smoothed (interpolated)
when it is scaled. For smoothing to work, the player must be in high-quality mode. The default
value is
false
(no smoothing).
Example
The following example uses a button (called
smoothing_btn
) to toggle the smoothing property
that is applied to the video
my_video
when it plays in a SWF file. Create a button called
smoothing_btn
and add the following ActionScript to your FLA or AS file:
this.createTextField("smoothing_txt", this.getNextHighestDepth(), 0, 0, 100,
22);
smoothing_txt.autoSize = true;
var my_nc:NetConnection = new NetConnection();
my_nc.connect(null);


var my_ns:NetStream = new NetStream(my_nc);
my_video.attachVideo(my_ns);
my_ns.play("video1.flv");
my_ns.onStatus = function(infoObject:Object) {
updateSmoothing();
};
smoothing_btn.onRelease = function() {
my_video.smoothing = !my_video.smoothing;
updateSmoothing();
};
function updateSmoothing():Void {
smoothing_txt.text = "smoothing = "+my_video.smoothing;
}
Video.width 1003
Video.width
Availability
Flash Player 6.
Usage
my_video.width:Number
Description
Property (read-only); an integer specifying the width of the video stream, in pixels. For live
streams, this value is the same as the
Camera.width
property of the Camera object that is
capturing the video stream. For FLV files, this value is the width of the file that was exported as an
FLV file.
You may want to use this property, for example, to ensure that the user is seeing the video at the
same size at which it was captured, regardless of the actual size of the Video object on the Stage.
Example
See the examples for Video.height.

1004 Chapter 2: ActionScript Language Reference
void
Availability
Flash Player 5.
Usage
void (expression)
function functionName():Void {}
Description
Usage 1: Operator; a unary operator that discards the
expression
value and returns an undefined
value. The
void
operator is often used in comparisons using the equality (
==
) operator to test for
undefined values.
Usage 2: Data type; used in function definitions to indicate that a function will not return a value.
Example
Usage 1: In the following ActionScript, the
void
operator is used to test for undefined values:
if (someUndefinedVariable == void (0)) {
trace("someUndefinedVariable is undefined");
}
The previous code can also be written in the following way:
if (someUndefinedVariable == undefined) {
trace("someUndefinedVariable is undefined");
}
Usage 2: In the following example, a function that returns a value is defined using the

Void
return
type, which results in a compile-time error:
function myFunction():Void {
return "This will cause a compile-time error.";
}
/* the following function call will generate a compile-time error:
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 2: A function with return
type Void may not return a value.
return "This will cause a compile-time error.";
*/
myFunction();
CHAPTER 2
ActionScript Language Reference
while 1005
while
Availability
Flash Player 4.
Usage
while(condition) {
statement(s);
}
Parameters
condition
An expression that evaluates to
true
or
false
.
statement(s)

The instructions to execute if the condition evaluates to
true
.
Returns
Nothing.
Description
Statement; evaluates a condition and if the condition evaluates to
true
, runs a statement or series
of statements before looping back to evaluate the condition again. After the condition evaluates to
false
, the statement or series of statements is skipped and the loop ends.
The
while
statement performs the following series of steps. Each repetition of steps 1 through 4
is called an iteration of the loop. The
condition
is retested at the beginning of each iteration, as
shown in the following steps:
1.
The expression
condition
is evaluated.
2.
If
condition
evaluates to
true
or a value that converts to the Boolean value
true

, such as a
nonzero number, go to step 3.
Otherwise, the
while
statement is completed and execution resumes at the next statement
after the
while
loop.
3.
Run the statement block
statement(s)
.
4.
Go to step 1.
Looping is commonly used to perform an action while a counter variable is less than a specified
value. At the end of each loop, the counter is incremented until the specified value is reached. At
that point, the
condition
is no longer
true
, and the loop ends.
The curly braces (
{}
) used to enclose the block of statements to be executed by the
while

statement are not necessary if only one statement will execute.
Example
In the following example, the
while

statement is used to test an expression. When the value of
i

is less than 20, the value of
i
is traced. When the condition is no longer
true
, the loop exits.
var i:Number = 0;
while (i<20) {
trace(i);
CHAPTER 2
ActionScript Language Reference
1006 Chapter 2: ActionScript Language Reference
i += 3;
}
The following result is displayed in the Output panel.
0
3
6
9
12
15
18
See also
do while, continue, for, for..in
with 1007
with
Availability
Flash Player 5.

Usage
with (object:Object) {
statement(s);
}
Parameters
object
An instance of an ActionScript object or movie clip.
statement(s)
An action or group of actions enclosed in curly braces ({}).
Returns
Nothing.
Description
Statement; lets you specify an object (such as a movie clip) with the
object
parameter and
evaluate expressions and actions inside that object with the
statement(s)
parameter. This
prevents you from having to repeatedly write the object’s name or the path to the object.
The
object
parameter becomes the context in which the properties, variables, and functions in
the
statement(s)
parameter are read. For example, if
object
is
my_array
, and two of the
properties specified are

length
and
concat
, those properties are automatically read as
my_array
.
length
and
my_array.concat
. In another example, if
object
is
state.california
,
any actions or statements inside the
with
statement are called from inside the
california

instance.
To find the value of an identifier in the
statement(s)
parameter, ActionScript starts at the
beginning of the scope chain specified by the
object
and searches for the identifier at each level
of the scope chain, in a specific order.
The scope chain used by the
with
statement to resolve identifiers starts with the first item in the

following list and continues to the last item:

The object specified in the
object
parameter in the innermost
with
statement.

The object specified in the
object
parameter in the outermost
with
statement.

The Activation object. (A temporary object that is automatically created when a function is
called that holds the local variables called in the function.)

The movie clip that contains the currently executing script.

The Global object (built-in objects such as Math and String).
To set a variable inside a
with
statement, you must have declared the variable outside the
with

statement, or you must enter the full path to the Timeline on which you want the variable to live.
If you set a variable in a
with
statement without declaring it, the
with

statement will look for the
value according to the scope chain. If the variable doesn’t already exist, the new value will be set
on the Timeline from which the
with
statement was called.
CHAPTER 2
ActionScript Language Reference
1008 Chapter 2: ActionScript Language Reference
Instead of using
with()
, you can use direct paths. If you find that paths are long and
cumbersome to type, you can create a local variable and store the path in the variable, which you
can then reuse in your code, as shown in the following ActionScript:
var shortcut = this._parent._parent.name_txt;
shortcut.text = "Hank";
shortcut.autoSize = true;
For more information on best practices in writing code and code readability, see Chapter 3,
“Avoiding the with statement,” on page 87 of Using ActionScript in Flash.
Example
The following example sets the
_x
and
_y
properties of the
someOther_mc
instance, and then
instructs
someOther_mc
to go to Frame 3 and stop.
with (someOther_mc) {

_x = 50;
_y = 100;
gotoAndStop(3);
}
The following code snippet shows how to write the preceding code without using a
with

statement.
someOther_mc._x = 50;
someOther_mc._y = 100;
someOther_mc.gotoAndStop(3);
The
with
statement is useful for accessing multiple items in a scope chain list simultaneously. In
the following example, the built-in
Math
object is placed at the front of the scope chain. Setting
Math
as a default object resolves the identifiers
cos
,
sin
, and
PI
to
Math.cos
,
Math.sin
, and
Math.PI

, respectively. The identifiers
a
,
x
,
y
, and
r
are not methods or properties of the
Math

object, but because they exist in the object activation scope of the function
polar()
, they resolve
to the corresponding local variables.
function polar(r:Number):Void {
var a:Number, x:Number, y:Number;
with (Math) {
a = PI*pow(r, 2);
x = r*cos(PI);
y = r*sin(PI/2);
}
trace("area = "+a);
trace("x = "+x);
trace("y = "+y);
}
polar(3);
The following result is displayed in the Output panel.
area = 28.2743338823081
x = -3

y = 3
See also
tellTarget
XML class 1009
XML class
Availability
Flash Player 5 (became a native object in Flash Player 6, which improved
performance significantly).
Description
Use the methods and properties of the XML class to load, parse, send, build, and manipulate
XML document trees.
You must use the constructor
new XML()
to create an XML object before calling any method of
the XML class.
An XML document is represented in Flash by the XML class. Each element of the hierarchical
document is represented by an XMLNode object.
Note: The XML and XMLNode objects are modeled after the W3C DOM Level 1 recommendation:
www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core.html. That recommendation
specifies a Node interface and a Document interface. The Document interface inherits from the Node
interface, and adds methods such as
createElement()
and
createTextNode()
. In ActionScript, the
XML and XMLNode objects are designed to divide functionality along similar lines.
Method summary for the XML class
Method Description
XML.addRequestHeader()
Adds or changes HTTP headers for

POST
operations.
XML.appendChild()
Appends a node to the end of the specified object’s child list.
XML.cloneNode()
Clones the specified node and, optionally, recursively clones all children.
XML.createElement()
Creates a new XML element.
XML.createTextNode()
Creates a new XML text node.
XML.getBytesLoaded()
Returns the number of bytes loaded for the specified XML document.
XML.getBytesTotal()
Returns the size of the XML document, in bytes.
XML.hasChildNodes()
Returns
true
if the specified node has child nodes; otherwise, returns
false
.
XML.insertBefore()
Inserts a node in front of an existing node in the specified node’s child list.
XML.load()
Loads a document (specified by the XML object) from a URL.
XML.parseXML()
Parses an XML document into the specified XML object tree.
XML.removeNode()
Removes the specified node from its parent.
XML.send()
Sends the specified XML object to a URL.

XML.sendAndLoad()
Sends the specified XML object to a URL, and loads the server response
into another XML object.
XML.toString()
Converts the specified node and any children to XML text.
CHAPTER 2
ActionScript Language Reference
1010 Chapter 2: ActionScript Language Reference
Property summary for the XML class
Collections summary for the XML class
Event handler summary for the XML class
Property Description
XML.contentType
The MIME type transmitted to the server.
XML.docTypeDecl
Sets and returns information about an XML document’s
DOCTYPE
declaration.
XML.firstChild
Read-only; references the first child in the list for the specified node.
XML.ignoreWhite
When set to
true
, discards, during the parsing process, text nodes that
contain only white space.
XML.lastChild
Read-only; references the last child in the list for the specified node.
XML.loaded
Read-only; checks whether the specified XML object has loaded.
XML.nextSibling

Read-only; references the next sibling in the parent node’s child list.
XML.nodeName
The node name of an XML object.
XML.nodeType
The type of the specified node (XML element or text node).
XML.nodeValue
The text of the specified node if the node is a text node.
XML.parentNode
Read-only; references the parent node of the specified node.
XML.previousSibling
Read-only; references the previous sibling in the parent node’s child list.
XML.status
A numeric status code that indicates the success or failure of an XML
document parsing operation.
XML.xmlDecl
Specifies information about a document’s XML declaration.
Method Description
XML.attributes
Returns an associative array that contains all the attributes of the specified
node.
XML.childNodes
Read-only; returns an array that contains references to the child nodes of
the specified node.
Event handler Description
XML.onData
Invoked when XML text has been completely downloaded from the
server, or when an error occurs downloading XML text from a server.
XML.onLoad
Returns a Boolean value indicating whether the XML object was
successfully loaded with

XML.load()
or
XML.sendAndLoad()
.
XML class 1011
Constructor for the XML class
Availability
Flash Player 5.
Usage
new XML([source:String]) : XML
Parameters
source
A string; the XML text parsed to create the new XML object.
Returns
A reference to an XML object.
Description
Constructor; creates a new XML object. You must use the constructor to create an XML object
before you call any of the methods of the XML class.
Note: Use the
createElement()
and
createTextNode()
methods to add elements and text nodes to
an XML document tree.
Example
The following example creates a new, empty XML object:
var my_xml:XML = new XML();
The following example creates an XML object by parsing the XML text specified in the
source


parameter, and populates the newly created XML object with the resulting XML document tree:
var other_xml:XML = new XML("<state name=\"California\">
<city>San Francisco</city></state>");
See also
XML.createElement(), XML.createTextNode()
1012 Chapter 2: ActionScript Language Reference
XML.addRequestHeader()
Availability
Flash Player 6.
Usage
my_xml.addRequestHeader(headerName:String, headerValue:String) : Void
my_xml.addRequestHeader(["headerName_1":String, "headerValue_1":String ...
"headerName_n":String, "headerValue_n":String]) : Void
Parameters
headerName
A string that represents an HTTP request header name.
headerValue
A string that represents the value associated with
headerName
.
Returns
Nothing.
Description
Method; adds or changes HTTP request headers (such as
Content-Type
or
SOAPAction
) sent
with
POST

actions. In the first usage, you pass two strings to the method:
headerName
and
headerValue
. In the second usage, you pass an array of strings, alternating header names and
header values.
If multiple calls are made to set the same header name, each successive value replaces the value set
in the previous call.
You cannot add or change the following standard HTTP headers using this method:
Accept-Ranges
,
Age
,
Allow
,
Allowed
,
Connection
,
Content-Length
,
Content-Location
,
Content-Range
,
ETag
,
Host
,
Last-Modified

,
Locations
,
Max-Forwards
,
Proxy-Authenticate
,
Proxy-Authorization
,
Public
,
Range
,
Retry-After
,
Server
,
TE
,
Trailer
,
Transfer-Encoding
,
Upgrade
,
URI
,
Vary
,
Via

,
Warning
, and
WWW-Authenticate
.
Example
The following example adds a custom HTTP header named
SOAPAction
with a value of
Foo
to
an XML object named
my_xml
:
my_xml.addRequestHeader("SOAPAction", "'Foo'");
The following example creates an array named
headers
that contains two alternating HTTP
headers and their associated values. The array is passed as a parameter to the
addRequestHeader()
method.
var headers:Array = new Array("Content-Type", "text/plain",
"X-ClientAppVersion", "2.0");
my_xml.addRequestHeader(headers);
See also
LoadVars.addRequestHeader()
XML.appendChild() 1013
XML.appendChild()
Availability
Flash Player 5.

Usage
my_xml.appendChild(childNode:XMLNode) : Void
Parameters
childNode
An XMLNode that represents the node to be moved from its current location to the
child list of the
my_xml
object.
Returns
Nothing.
Description
Method; appends the specified node to the XML object’s child list. This method operates directly
on the node referenced by the
childNode
parameter; it does not append a copy of the node. If the
node to be appended already exists in another tree structure, appending the node to the new
location will remove it from its current location. If the
childNode
parameter refers to a node that
already exists in another XML tree structure, the appended child node is placed in the new tree
structure after it is removed from its existing parent node.
Example
This example does the following things in the order shown:

Creates two empty XML documents,
doc1
and
doc2
.


Creates a new node using the
createElement()
method, and appends it, using the
appendChild()
method, to the XML document named
doc1
.

Shows how to move a node using the
appendChild()
method, by moving the root node from
doc1
to
doc2
.

Clones the root node from
doc2
and appends it to
doc1
.

Creates a new node and appends it to the root node of the XML document doc1.
var doc1:XML = new XML();
var doc2:XML = new XML();
// create a root node and add it to doc1
var rootnode:XMLNode = doc1.createElement("root");
doc1.appendChild(rootnode);
trace ("doc1: " + doc1); // output: doc1: <root />
trace ("doc2: " + doc2); // output: doc2:

// move the root node to doc2
doc2.appendChild(rootnode);
trace ("doc1: " + doc1); // output: doc1:
trace ("doc2: " + doc2); // output: doc2: <root />
// clone the root node and append it to doc1
1014 Chapter 2: ActionScript Language Reference
var clone:XMLNode = doc2.firstChild.cloneNode(true);
doc1.appendChild(clone);
trace ("doc1: " + doc1); // output: doc1: <root />
trace ("doc2: " + doc2); // output: doc2: <root />
// create a new node to append to root node (named clone) of doc1
var newNode:XMLNode = doc1.createElement("newbie");
clone.appendChild(newNode);
trace ("doc1: " + doc1); // output: doc1: <root><newbie /></root>
XML.attributes 1015
XML.attributes
Availability
Flash Player 5.
Usage
my_xml.attributes:Array
Description
Property; an associative array that contains all the attributes of the specified XML object.
Associative arrays use keys as indexes, instead of the simple ordinal integer indexes used by regular
arrays. In the
XML.attributes
associative array, the key index is a string representing the name of
the attribute. The value associated with that key index is the string value associated with that
attribute. For example, if you have an attribute named color, you would retrieve that attribute’s
value by using the color as the key index, as the following code shows:
var myColor:String = doc.firstChild.attributes.color

Example
The following example shows the XML attribute names:
// create a tag called 'mytag' with
// an attribute called 'name' with value 'Val'
var doc:XML = new XML("<mytag name=\"Val\"> item </mytag>");
// assign the value of the 'name' attribute to variable y
var y:String = doc.firstChild.attributes.name;
trace (y); // output: Val
// create a new attribute named 'order' with value 'first'
doc.firstChild.attributes.order = "first";
// assign the value of the 'order' attribute to variable z
var z:String = doc.firstChild.attributes.order
trace(z); // output: first
The following is displayed in the Output panel:
Val
first
1016 Chapter 2: ActionScript Language Reference
XML.childNodes
Availability
Flash Player 5.
Usage
my_xml.childNodes:Array
Description
Read-only property; an array of the specified XML object’s children. Each element in the array is
a reference to an XML object that represents a child node. This is a read-only property and
cannot be used to manipulate child nodes. Use the XML.appendChild(), XML.insertBefore(),
and XML.removeNode() methods to manipulate child nodes.
This property is undefined for text nodes (
nodeType ==
3).

Example
The following example shows how to use the
XML.childNodes
property to return an array of
child nodes:
// create a new XML document
var doc:XML = new XML();
// create a root node
var rootNode:XMLNode = doc.createElement("rootNode");
// create three child nodes
var oldest:XMLNode = doc.createElement("oldest");
var middle:XMLNode = doc.createElement("middle");
var youngest:XMLNode = doc.createElement("youngest");
// add the rootNode as the root of the XML document tree
doc.appendChild(rootNode);
// add each of the child nodes as children of rootNode
rootNode.appendChild(oldest);
rootNode.appendChild(middle);
rootNode.appendChild(youngest);
// create an array and use rootNode to populate it
var firstArray:Array = doc.childNodes;
trace (firstArray);
// output: <rootNode><oldest /><middle /><youngest /></rootNode>
// create another array and use the child nodes to populate it
var secondArray:Array = rootNode.childNodes;
trace(secondArray);
// output: <oldest />,<middle />,<youngest />
See also
XML.nodeType
XML.cloneNode() 1017

XML.cloneNode()
Availability
Flash Player 5.
Usage
my_xml.cloneNode(deep:Boolean) : XMLNode
Parameters
deep
A Boolean value; if set to
true
, the children of the specified XML object will be
recursively cloned.
Returns
An XMLNode object.
Description
Method; constructs and returns a new XML node of the same type, name, value, and attributes as
the specified XML object. If
deep
is set to
true
, all child nodes are recursively cloned, resulting in
an exact copy of the original object’s document tree.
The clone of the node that is returned is no longer associated with the tree of the cloned item.
Consequently,
nextSibling
,
parentNode
, and
previousSibling
all have a value of
null

. If the
deep
parameter is set to
false
, or the
my_xml
node has no child nodes,
firstChild
and
lastChild
are also
null
.
Example
The following example shows how to use the
XML.cloneNode()
method to create a copy of a
node:
// create a new XML document
var doc:XML = new XML();
// create a root node
var rootNode:XMLNode = doc.createElement("rootNode");
// create three child nodes
var oldest:XMLNode = doc.createElement("oldest");
var middle:XMLNode = doc.createElement("middle");
var youngest:XMLNode = doc.createElement("youngest");
// add the rootNode as the root of the XML document tree
doc.appendChild(rootNode);
// add each of the child nodes as children of rootNode
rootNode.appendChild(oldest);

rootNode.appendChild(middle);
rootNode.appendChild(youngest);
// create a copy of the middle node using cloneNode()
var middle2:XMLNode = middle.cloneNode(false);
1018 Chapter 2: ActionScript Language Reference
// insert the clone node into rootNode between the middle and youngest nodes
rootNode.insertBefore(middle2, youngest);
trace(rootNode);
// output (with line breaks added):
// <rootNode>
// <oldest />
// <middle />
// <middle />
// <youngest />
// </rootNode>
// create a copy of rootNode using cloneNode() to demonstrate a deep copy
var rootClone:XMLNode = rootNode.cloneNode(true);
// insert the clone, which contains all child nodes, to rootNode
rootNode.appendChild(rootClone);
trace(rootNode);
// output (with line breaks added):
// <rootNode>
// <oldest />
// <middle />
// <middle />
// <youngest />
// <rootNode>
// <oldest />
// <middle />
// <middle />

// <youngest />
// </rootNode>
// </rootNode>
XML.contentType 1019
XML.contentType
Availability
Flash Player 6.
Usage
my_xml.contentType:String
Description
Property; the MIME content type that is sent to the server when you call the XML.send() or
XML.sendAndLoad() method. The default is
application/x-www-form-urlencoded
, which is
the standard MIME content type used for most HTML forms.
Example
The following example creates a new XML document and checks its default content type:
// create a new XML document
var doc:XML = new XML();
// trace the default content type
trace(doc.contentType); // output: application/x-www-form-urlencoded
The following example defines an XML packet, and sets the content type for the XML object.
The data is then sent to a server and shows a result in a browser window.
var my_xml:XML = new XML("<highscore><name>Ernie</name><score>13045</score>
</highscore>");
my_xml.contentType = "text/xml";
my_xml.send(" "_blank");
Press F12 to test this example in a browser.
See also
XML.send(), XML.sendAndLoad()

1020 Chapter 2: ActionScript Language Reference
XML.createElement()
Availability
Flash Player 5.
Usage
my_xml.createElement(name:String) : XMLNode
Parameters
name
The tag name of the XML element being created.
Returns
An XMLNode; an XML element.
Description
Method; creates a new XML element with the name specified in the parameter. The new element
initially has no parent, no children, and no siblings. The method returns a reference to the newly
created XML object that represents the element. This method and the XML.createTextNode()
method are the constructor methods for creating nodes for an XML object.
Example
The following example creates three XML nodes using the
createElement()
method:
// create an XML document
var doc:XML = new XML();
// create three XML nodes using createElement()
var element1:XMLNode = doc.createElement("element1");
var element2:XMLNode = doc.createElement("element2");
var element3:XMLNode = doc.createElement("element3");
// place the new nodes into the XML tree
doc.appendChild(element1);
element1.appendChild(element2);
element1.appendChild(element3);

trace(doc);
// output: <element1><element2 /><element3 /></element1>
See also
XML.createTextNode()
XML.createTextNode() 1021
XML.createTextNode()
Availability
Flash Player 5.
Usage
my_xml.createTextNode(text:String) : XMLNode
Parameters
text
A string; the text used to create the new text node.
Returns
An XMLNode.
Description
Method; creates a new XML text node with the specified text. The new node initially has no
parent, and text nodes cannot have children or siblings. This method returns a reference to the
XML object that represents the new text node. This method and the XML.createElement()
method are the constructor methods for creating nodes for an XML object.
Example
The following example creates two XML text nodes using the
createTextNode()
method, and
places them into existing XML nodes:
// create an XML document
var doc:XML = new XML();
// create three XML nodes using createElement()
var element1:XMLNode = doc.createElement("element1");
var element2:XMLNode = doc.createElement("element2");

var element3:XMLNode = doc.createElement("element3");
// place the new nodes into the XML tree
doc.appendChild(element1);
element1.appendChild(element2);
element1.appendChild(element3);
// create two XML text nodes using createTextNode()
var textNode1:XMLNode = doc.createTextNode("textNode1");
var textNode2:XMLNode = doc.createTextNode("textNode2");
// place the new nodes into the XML tree
element2.appendChild(textNode1);
element3.appendChild(textNode2);
trace(doc);
// output (with line breaks added between tags):
// <element1>
// <element2>textNode1</element2>
// <element3>textNode2</element3>
// </element1>
1022 Chapter 2: ActionScript Language Reference
See also
XML.createElement()
XML.docTypeDecl 1023
XML.docTypeDecl
Availability
Flash Player 5.
Usage
my_xml
.
docTypeDecl:String
Description
Property; specifies information about the XML document’s

DOCTYPE
declaration. After the XML
text has been parsed into an XML object, the
XML.docTypeDecl
property of the XML object is
set to the text of the XML document’s
DOCTYPE
declaration (for example,
<!DOCTYPE

greeting
SYSTEM "hello.dtd">
). This property is set using a string representation of the
DOCTYPE

declaration, not an XML node object.
The ActionScript XML parser is not a validating parser. The
DOCTYPE
declaration is read by the
parser and stored in the
XML.docTypeDecl
property, but no DTD validation is performed.
If no
DOCTYPE
declaration was encountered during a parse operation, the
XML.docTypeDecl

property is set to
undefined
. The XML.toString() method outputs the contents

of
XML.docTypeDecl
immediately after the XML declaration stored in
XML.xmlDecl
, and before
any other text in the XML object. If
XML.docTypeDecl
is undefined, no
DOCTYPE
declaration is
output.
Example
The following example uses the
XML.docTypeDecl
property to set the
DOCTYPE
declaration for an
XML object:
my_xml.docTypeDecl = "<!DOCTYPE greeting SYSTEM \"hello.dtd\">";
See also
XML.toString(), XML.xmlDecl
1024 Chapter 2: ActionScript Language Reference
XML.firstChild
Availability
Flash Player 5.
Usage
my_xml.firstChild:XMLNode
Description
Read-only property; evaluates the specified XML object and references the first child in the parent
node’s child list. This property is

null
if the node does not have children. This property is
undefined
if the node is a text node. This is a read-only property and cannot be used to
manipulate child nodes; use the
appendChild()
,
insertBefore()
, and
removeNode()
methods
to manipulate child nodes.
Example
The following example shows how to use
XML.firstChild
to loop through a node’s child nodes:
// create a new XML document
var doc:XML = new XML();
// create a root node
var rootNode:XMLNode = doc.createElement("rootNode");
// create three child nodes
var oldest:XMLNode = doc.createElement("oldest");
var middle:XMLNode = doc.createElement("middle");
var youngest:XMLNode = doc.createElement("youngest");
// add the rootNode as the root of the XML document tree
doc.appendChild(rootNode);
// add each of the child nodes as children of rootNode
rootNode.appendChild(oldest);
rootNode.appendChild(middle);
rootNode.appendChild(youngest);

// use firstChild to iterate through the child nodes of rootNode
for (var aNode:XMLNode = rootNode.firstChild; aNode != null; aNode =
aNode.nextSibling) {
trace(aNode);
}
// output:
// <oldest />
// <middle />
// <youngest />
The following example is from the XML_languagePicker FLA file in the Examples directory and
can be found in the
languageXML.onLoad
event handler function definition:
// loop through the strings in each language node
// adding each string as a new element in the language array
XML.firstChild 1025
for (var stringNode:XMLNode = childNode.firstChild; stringNode != null;
stringNode = stringNode.nextSibling, j++) {
masterArray[i][j] = stringNode.firstChild.nodeValue;
}
To view the entire script, see XML_languagePicker.fla in the HelpExamples folder:

Windows: \Program Files\Macromedia\Flash MX 2004\Samples\HelpExamples\

Macintosh: HD/Applications/Macromedia Flash MX 2004/Samples/HelpExamples/
See also
XML.appendChild(), XML.insertBefore(), XML.removeNode()

×