News.Flash MX: XMLShortcuts Version 2 coming soon.
I'm already working on version 2 of this XMLNode easy access component.
It will give better performance than the previous version. It will have two components, XMLShortcuts Lite and XMLShortcuts Pro. Both provide the same functionality.
XMLShortcuts Lite is optimized for file size & memory, it is recommended for Small Projects.
XMLShortcuts Pro is optimized for processor & performance, recommended for medium and large projects
What else is new?
1) __text - now it can be used for easily adding text nodes. for example
var my_xml=newXML('<a/>');
my_xml.a.__text='apple';
trace(my_xml)
//<a>apple</a>
2) nodeIndex - unique node index for the node with a unique name in the order of appearance in the xml. for example
It will be great if some one can take initiative to do performance test on both
posted by Arul
| link
| ^top
| next> |
comments [9]
Wednesday, June 15, 2005
Code.Flash MX: XML Shortcuts component released.
The XMLShortcuts component enables shortcut access to All XML nodes.
Biggest advantage of using XML shortcuts is it can be easily added to existing projects with out any modification. Simply drag and drop the component from components window to the stage and then delete it from stage (let it stay in the library).
Available Shortcuts:
Property
Description
childNode
Get the first child node with the specified node name
childNode_index
Get the specific child node with the specified node name and index
$childNode
Get all the child nodes with the specified node name as an array.
_attribute
Get the value for specific attribute name
__text
Get the text node
rootNode
Access the root node of XML from any node using this shortcut
Note: Replace childNode, index, and attribute with their respective values. See the example below
my_xml:
<english>
<a word="apple">a for apple</a>
<a word="Arul">a for Arul</a>
<b word="ball">b for ball</b>
<b word="bee">b for bee</b>
<c word="cat">c for cat</c>
<c word="cow">c for cow</c>
</english>
Using the XML above
Property
Example
Trace output
childNode
trace(my_xml.english.a)
<a word="apple">a for apple</a>
childNode_index
trace(my_xml.english.a_1)
<a word="Arul">a for Arul</a>
$childNode
trace(my_xml.english.$b)
<b word="ball">b for ball</b>,
<b word="bee">b for bee</b>
_attribute
trace(my_xml.english.c._word)
cat
__text
trace(my_xml.english.c.__text)
c for cat
rootNode
trace(my_xml.english.c.rootNode instanceof XML)
true
Caution: Avoid data type declaration while initializing XML and XMLNode
for example the following code will throw a compiler error "There is no property with the name 'x'"
var myXML:XML = new XML ("<x><y/><x>");
trace (myXML.x);
Where as the following code works fine
var myXML = new XML ("<x><y/><x>");
trace (myXML.x);
Hope it is of some use to everyone using flash and xml in their day to day life. Feel free to express your views in the comment, I will be glad to hear from you :)
import com.xfactorstudio.xml.xpath.*;
var _xml:XML = newXML ();
_xml.onLoad = function (done) {
if (done) {
vartitle = XPath.selectNodes(this,"/rss/item/title");
trace(title);
/* variable title is populated with the following value
title=[
"<title>Tools.Flash MX: Actionscript Syntax Highlighting with SE|PY Editor v.1.0.5.4</title>",
"<title>Update.Arul's Blog: I'm back again</title>",
"<title>Code.Flash MX: PriorityQueue Class </title>"
];
*/
}
};
_xml.load ('http://www.shockwave-india.com/blog/example/sample.xml');
Modifies the XMLNodes by adding new attribute called 'id'
Generates new XML object for every result which brakes the hierarchy
Usage Example:-
#include"XMLNodeEasyAccess.as"//
var _xml:XML = newXML ();
_xml.onLoad = function (done) {
if (done) {
//pre-process
this.tagID();
//easy access samples
trace(this.rss.item_0.title.firstChild)
//Tools.Flash MX: Actionscript Syntax Highlighting with SE|PY Editor v.1.0.5.4
trace(this.rss.item_1.title)
//Update.Arul's Blog: I'm back again }
};
_xml.load ('http://www.shockwave-india.com/blog/example/sample.xml');
XML Shortcuts Component (Yet to be released)
Easy to use
Dynamically resolves at runtime (So processor load is distributed among requests)
Mixed type access is possible
No pre processing required
Very lite
Yet t o be found ;)
Usage Example:-
/*
Simply drag and drop XML Shortcuts component to Library
*/var _xml:XML = newXML ();
_xml.ignoreWhite=true//ignoreWhite is defined to help normal access, not needed for shortcut component
_xml.onLoad = function (done) {
if (done) {
/*
normal access
*/trace(this.firstChild.firstChild.firstChild.firstChild)
//Tools.Flash MX: Actionscript Syntax Highlighting with SE|PY Editor v.1.0.5.4
/*
shortcut access
*/trace (this.rss.item.title.__text);
//Tools.Flash MX: Actionscript Syntax Highlighting with SE|PY Editor v.1.0.5.4
/*
mixed access
*/trace (this.rss.firstChild.title.firstChild);
//Tools.Flash MX: Actionscript Syntax Highlighting with SE|PY Editor v.1.0.5.4
/*
access an attribute using _ also accessing the second 'item' using unique id
*/trace(this.rss.item_1.guid._isPermaLink)
//false
/*
get all 'item' nodes as an array using $
*/varitems:Array = this.rss.$item;
for(var i=0; i<items.length; i++){
trace(items[i].category)
}
//<category>Flash MX/Tools</category>
//<category>Arul's Blog/Update</category>
//<category>Flash MX/Code</category>
}
};
_xml.load ('http://www.shockwave-india.com/blog/example/sample.xml');
What do you think?
Will XML Shortcuts component be of any use to you?
Express your views in the comments, based on the demand I will release the component
posted by Arul
| link
|<prev. | ^top
| next> |
comments [18]
Saturday, June 11, 2005
Update.Arul's Blog: Added a new section - ActionScript2.
To better organize my blog, I've added a new section called actionscript2, all the AS2 class files will be placed here for download.
I will also convert some of my as1 functions into as2 class files and place them here
posted by Arul
| link
|<prev. | ^top
| next> |
comments [2]
Wednesday, June 08, 2005
Examples.Flash MX: XML and V2 Tree Example 5 - Limit by Depth.
Lets explore how we can hide nodes beyond the predefined depth from rendering in tree. Before hiding the text nodes, the tree looks like this (as per Example 1) with this XML
Start with a blank FLA, add a tree component to stage, name it "tree", add a text area component name it "textArea"
Write the following in the first frame
tree.labelFunction = function (node) {
return node.nodeType == 1 ? node.nodeName : node.nodeValue;
};
var sample_xml:XML = newXML ();
sample_xml.ignoreWhite = true;
sample_xml.onLoad = function (done) {
if (done) {
tree.dataProvider = limitByDepth (this, 2);
}
};
sample_xml.load ('http://www.shockwave-india.com/blog/example/sample.xml');
//
function limitByDepth (x, limit, depth) {
if (depth == undefined) {
depth = 0;
}
for (var i = 0; i < x.childNodes.length; i++) {
if (depth < limit) {
if (x.childNodes[i].nodeType == 1) {
arguments.callee (x.childNodes[i], limit, depth + 1);
}
} else {
if (x._node == undefined) {
x._node = x.cloneNode(true);
}
x.childNodes[i].removeNode ();
i--;
}
}
return x;
}
then write the following on the tree
on (change) {
var n = this.selectedNode._node;
if (n == undefined) {
n = '';
}
_parent.textArea.text = n;
}
Examples.Flash MX: XML and V2 Tree Example 4 - Hiding Text Nodes.
Lets explore how we can hide text nodes from rendering in tree. Before hiding the text nodes, the tree looks like this (as per Example 1) with this XML
Start with a blank FLA, add a tree component to stage, name it "tree", add a text area component name it "textArea"
Write the following in the first frame
importmx.controls.Tree;
var tree:Tree;
//icon function is added here
tree.labelFunction = function (node) {
return node.nodeType == 1 ? node.nodeName : node.nodeValue;
};
var sample_xml:XML = newXML ();
sample_xml.ignoreWhite = true;
sample_xml.onLoad = function (done) {
if (done) {
tree.dataProvider = hideTextNodes (this);
}
};
sample_xml.load ('http://www.shockwave-india.com/blog/example/sample.xml');
//
function hideTextNodes (x) {
for (var i = 0; i < x.childNodes.length; i++) {
if (x.childNodes[i].nodeType == 1) {
arguments.callee (x.childNodes[i]);
} else {
//text node found, hide it as property text
x.text == undefined ? x.text = x.childNodes[i].nodeValue : x.text += x.childNodes[i].nodeValue;
x.childNodes[i].removeNode ();
i--;
}
}
return x;
}
then write the following on the Tree
on (change) {
var t = this.selectedNode.text;
if (t == undefined) {
t = '';
}
_parent.textArea.text = t;
}
Tools.Flash MX: ColorSyntax Extractor now generates XML for Flash based Syntax Highlighter .
I've modified my Color Syntax Extractor to include XML for Igor's Flash Syntax Highlighter, which is a flash based synctax highlighter for actionscript.