source
PROBLEM SUMMARY
simply using the Delete key work in Flex does not work most of the time and if you have a Tree that's bound to the XMLListCollection Flex will mess up the Tree Selection after deleting an XML element.
SOLUTION SUMMARY
Use a custom method to for loop and delete proper child and reset tree selection
EXPLANATION
__________________________________________________________________________________
Use this method:
private function xmlDeleteNode(xmlToDelete:XML):Boolean
{
var cn:XMLList = XMLList(xmlToDelete.parent()).children();
for ( var i:Number = 0 ; i < cn.length() ; i++ )
{
if ( cn[i] == xmlToDelete )
{
delete cn[i];
return true;
}
}
return false;
}
Also, remember to do on an XML Bound Tree Control:
myTree.selectedItem = null;
_______________________________________________________________________________
i have extended this logic
myTree.selectedItem = null;
after delete ... instead setting the selectedItem to null, it wud b gud
if you select the deleted node's parent
before calling the xmlDeleteNode method
save the xmlToDelete's parent
**************************************
var tmp:XML = xmlToDelete.parent();
xmlDeleteNode(xmlToDelete);
myTree.selectedItem = tmp
**************************************
Adobe Flex is a software development kit released by Adobe Systems for the development and deployment of cross-platform rich Internet applications based on the Adobe Flash platform. Flex applications can be written using Adobe Flex Builder or by using the freely available Flex compiler from Adobe.
Showing posts with label xml. Show all posts
Showing posts with label xml. Show all posts
Tuesday, February 17, 2009
Tuesday, November 11, 2008
Embedding XML in Flex
posted on
27 04 2007
This post is more of a test of my code embedding tool for wordpress. It’s called iG:Syntax Hiliter and it works like a charm. I dig the text view along with the pretty color coded view.
So, about embedding an XML file in a flex swf…Here’s an example of embedding an XML file, then tracing out data at compile time via actionscript. The best part is the the XML is compiled into the swf, and you can access any of the XML file’s properties by accessing it via the singleton XML Manager.
[as][Embed(source=”myXMLFile.xml”,mimeType=”application/octet-stream”)]
public static const XMLFILE:Class;
public static const MY_XML : XML = setConst();
private var cache : Object
public var dataXML : XML;
private static function setConst():XML{
var ba:ByteArray = new XMLFILE() as ByteArray;
trace(”compiling”);
return new XML(ba.readUTFBytes(ba.length));
}
private static var model : XMLManager;
public static function getInstance() : XMLManager
{
if ( model == null )
{
model = new XMLManager();
}
return model;
}
public function XMLManager()
{
if ( model != null )
{
throw new Error( “Only one XML Manager instance should be instantiated” );
}
dataXML = MY_XML;
cache = new Object();
}
[/as]
source
27 04 2007
This post is more of a test of my code embedding tool for wordpress. It’s called iG:Syntax Hiliter and it works like a charm. I dig the text view along with the pretty color coded view.
So, about embedding an XML file in a flex swf…Here’s an example of embedding an XML file, then tracing out data at compile time via actionscript. The best part is the the XML is compiled into the swf, and you can access any of the XML file’s properties by accessing it via the singleton XML Manager.
[as][Embed(source=”myXMLFile.xml”,mimeType=”application/octet-stream”)]
public static const XMLFILE:Class;
public static const MY_XML : XML = setConst();
private var cache : Object
public var dataXML : XML;
private static function setConst():XML{
var ba:ByteArray = new XMLFILE() as ByteArray;
trace(”compiling”);
return new XML(ba.readUTFBytes(ba.length));
}
private static var model : XMLManager;
public static function getInstance() : XMLManager
{
if ( model == null )
{
model = new XMLManager();
}
return model;
}
public function XMLManager()
{
if ( model != null )
{
throw new Error( “Only one XML Manager instance should be instantiated” );
}
dataXML = MY_XML;
cache = new Object();
}
[/as]
source
Subscribe to:
Posts (Atom)
Freelance
Find more freelance jobs