Some new features:
Create Remote Shared Object on Flash Media Server 2
trace("start");
// Create the shared object to store client objects (users)
this.users_so = SharedObject.get("users_so", false);
Subscribe Remote Shared Object on client
users_so = SharedObject.getRemote("users_so", nc.uri, false);
users_so.addEventListener(SyncEvent.SYNC, usersSync);
users_so.addEventListener(NetStatusEvent.NET_STATUS, onSOnetStatus); //Old 'onStatus()'
users_so.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSOSecurityError);
//SharedObject has a property 'client' that defines obj on which will invoked remote methods
users_so.client = this;
users_so.connect(nc);
Send a function (on client)
var outmsg:String = "Hello World!!";
//Broadcasts a message to all clients connected to the specified remote shared object
chat_so.send("onMsgSend", outmsg);
}
Execute a function (on client) earlier sended
trace("onMsgSend: " + msg);
chatHistory += msg;
dispatchEvent(new Event("histChange"));
}
Adding new Attributes and Elements
<TITLE>Ulysses</TITLE>
<AUTHOR>Joyce, James</AUTHOR>
<PUBLISHER>Hi Books</PUBLISHER>
<DESCRIPTION>A <B>very</B> thick book.</DESCRIPTION>
</BOOK>;
Modify existing element or attribute
novel.@ISBN = "015687982928";
Result:
<TITLE>Last Ulysses</TITLE>
<AUTHOR>Joyce, James</AUTHOR>
<PUBLISHER>Hi Books</PUBLISHER>
<DESCRIPTION>A <B>very</B> thick book.</DESCRIPTION>
</BOOK>
Adding new elements
novel.SETTING.COUNTRY = "Italy";
Result:
<TITLE>Last Ulysses</TITLE>
<AUTHOR>Joyce, James</AUTHOR>
<PUBLISHER>Hi Books</PUBLISHER>
<DESCRIPTION>A <B>very</B> thick book.</DESCRIPTION>
<SETTING>
<CITY>Rome</CITY>
<COUNTRY>Italy</COUNTRY>
</SETTING>
</BOOK>
Adding new attributes
novel.SETTING.@COUNTRY = "Italy";
Result:
<TITLE>Last Ulysses</TITLE>
<AUTHOR>Joyce, James</AUTHOR>
<PUBLISHER>Hi Books</PUBLISHER>
<DESCRIPTION>A <B>very</B> thick book.</DESCRIPTION>
<SETTING CITY="Rome" COUNTRY="Italy" />
</BOOK>
Adding new child after a specific existing child
Adding new child before a specific existing child
Adding new child before all existing child
Deleting Elements and Attributes
delete novel.@ISBN;//Removes the ISBN attribute from the <BOOK> element.
delete novel.TITLE;
//Removes the <TITLE> element from the <BOOK> element.
delete novel.*;
//Removes the <TITLE>, <AUTHOR>, <PUBLISHER>, etc. elements from the <BOOK> element.
delete novel.TITLE.*;
//Removes the text content from the <TITLE> element.
delete novel.@*;
//Removes all attributes.
Accessing descendants
<BOOK ISBN="976568989" DATE="1136091600000">
<TITLE>Ulysses</TITLE>
<AUTHOR>Joyce, James</AUTHOR>
<PUBLISHER>My Books</PUBLISHER>
</BOOK>
<DVD ISBN="5432334456" DATE="1136691000000">
<TITLE>2001 A Space Odysses</TITLE>
<DIRECTOR>Stanley Kubrick</DIRECTOR>
<PUBLISHER>Warner</PUBLISHER>
</DVD>
<DVD ISBN="7878785566" DATE="1136691000000">
<TITLE>Toy Story</TITLE>
<DIRECTOR>John Lasseter</DIRECTOR>
<PUBLISHER>Walt Disney</PUBLISHER>
</DVD>
</LOAN>
theElement..identifier
A descendant operator(..) returns a XMLList representing all descendants of theElement whose name match identifier.
i.e. xml..DIRECTOR//Notice that the <DIRECTOR> elements are not direct children of the <LOAN> element; they are grandchildren.
Above expression yields an XMLList that has two XML instances, representing the two <DIRECTOR> elements.
Example
trace(title);
Ulysses
2001 A Space Odysses
Toy Story
theElement..@attributeName
A descendant operator also works with attributes(..@) returns a XMLList representing all descendants attributes of theElement whose name match attributeName.
i.e. xml..@DUEAbove expression yields an XMLList that has three XML instances, representing the three DUE attributes.
From the previous example
pub.parent();
If the pub is a root node (not in this case) the parent() method returns null. (i.e. novel.parent();)
Accessing Attributes
novel.attributes() and novel.@*
//Returns an XMLList representing <BOOK>'s attributes (which is ISBN node)
Normally attributes are accessed by name, using either the attribute() method
someElement.attribute("attributeName")
or E4X's more convenient variable-access syntax
someElement.@attributeName
Example:
<TITLE>Ulysses</TITLE>
<AUTHOR>Joyce, James</AUTHOR>
<PUBLISHER>Hi Books</PUBLISHER>
<DESCRIPTION>A <B>very</B> thick book.</DESCRIPTION>
</BOOK>;
novel.children() and novel.*
//Returns an XMLList representing 's child nodes
novel.children()[1]
//Reference to 's second child node
novel.child("AUTHOR") and novel.AUTHOR
//Returns all child elements of named "AUTHOR"
novel.AUTHOR[0].setName("WRITER")
//Change name of the first child element named "AUTHOR"
novel.TITLE.children()[0] and novel.TITLE.*[0]
//A reference to the text node Ulysses and not the string "Ulysses"
novel.TITLE.*[0].parent() //A reference to the <TITLE> element
novel.TITLE.*[0].nodeKind() //Returns the string "text"
novel.TITLE.*[0].toString() //Returns the string "Ulysses"
The <DESCRIPTION> element contains both element and text child nodes:
- A (text node);
- <B>very</B> (element node with a child text node);
- thick book. (text node);
The text() method can also used to retrieve the text nodes from an entire XMLList, not just a single XML element.
trace(novel.DESCRIPTION.text()[0]);
//Display: A
trace(novel.DESCRIPTION.text()[1]);
//Display: thick book