XML Data in LinkBar
hi guys,
i'm new flex , still learning lot, struggling following issue,
i have simple "book list" style application have created. linked xml document , able edit/delete/add items in xml document.
now want have linkbar @ top 3 buttons different stypes of lists (different xml documents)
i have tried take working application , put linkbar fails work.
any awesome.
cheers
kariko
<mx:windowedapplication xmlns:mx="http://www.adobe.com/2006/mxml" initialize="{init()}"
layout="absolute" height="451" width="542">
<!-- // -->
<mx:script>
<![cdata[
import mx.collections.xmllistcollection;
// code block 1
private var myxml:xml;
private var myloader:urlloader;
[bindable]
private var mybookscol:xmllistcollection;
// --- //
// code block 2 //
public function init():void
{
var datafile:file = new file('app-storage:/data.xml');
if(datafile.exists){
var myreq:urlrequest = new urlrequest('app-storage:/data.xml');
myloader = new urlloader()
myloader.addeventlistener(event.complete, datacomplete);
myloader.load(myreq);
}else{
createfile()
}
}
// code block 3 //
private function createfile():void
{
var xmltosave:xml = new xml('<flashenabled><books>' +
'<book>' +
'<title>contact1</title>' +
'<series></series>' +
'<author></author>'+
'<isbn></isbn>' +
'</book>' +
'</books>' +
'</flashenabled>')
var savestr:string = xmltosave.toxmlstring();
var file:file = new file('app-storage:/data.xml');
var fs:filestream = new filestream();
fs.open(file, filemode.write);
fs.writeutfbytes(savestr);
fs.close();
init();
}
//code block 4
private function datacomplete(e:event):void
{
myxml = new xml(myloader.data.tostring());
mybookscol = new xmllistcollection(myxml..contact);
}
//code block 5
private function updatelist():void
{
mybookscol = new xmllistcollection(myxml..contact.(name.tolowercase().indexof(search_txt.text.tolowercase( )) != -1 ))
}
//code block 6
private function savedata(e:event):void
{
var xmltosave:xml = new xml('<flashenabled><books>'+mybookscol.toxmlstring()+'</books></flashenabled>')
var savestr:string = xmltosave.toxmlstring();
var file:file = new file('app-storage:/data.xml');
var fs:filestream = new filestream();
fs.open(file, filemode.write);
fs.writeutfbytes(savestr);
fs.close();
}
//code block 7
private function additem():void
{
mybookscol.additem(new xml('<book>' +
'<title>contact1</title>' +
'<series></series>' +
'<author></author>' +
'<isbn></isbn>' +
'</book>'))
}
private function removeitem():void
{
mybookscol.removeitemat(mydg.selectedindex);
}
]]>
</mx:script>
<!-- code block 8 -->
<mx:datagrid bottom="60" top="10" left="10" id="mydg" dataprovider="{mybookscol}" editable="true" right="10">
<mx:columns>
<mx:datagridcolumn headertext="title" datafield="title"/>
<mx:datagridcolumn headertext="series" datafield="series"/>
<mx:datagridcolumn headertext="author" datafield="author"/>
<mx:datagridcolumn headertext="isbn" datafield="isbn"/>
</mx:columns>
</mx:datagrid>
<mx:label x="10" text="search:" bottom="10"/>
<mx:textinput x="65" id="search_txt" bottom="10"/>
<!-- code block 9 -->
<mx:button x="233" label="go!" id="go_btn" click="{updatelist()}" bottom="10"/>
<mx:button label="save" click="{savedata(event)}" id="savebutton" bottom="10" right="10"/>
<mx:button x="307" label="add" click="{additem()}" bottom="10"/>
<mx:button x="381" label="remove" click="{removeitem()}" bottom="10"/>
</mx:windowedapplication>
More discussions in Flex (Read Only)
adobe
Comments
Post a Comment