nathaniel
01-18-2006, 10:34 PM
Hi,
I have a question that I'm pleased to announce should tease even the brainiest actionscripters.
I have an slideshow application that has an administrative section with two datagrids. The left datagrid lists slides playing, the right datagrid lists slides that don't. The data is saved to and read from an xml table.
I have no problem getting the datagrid to recognize a selection, and by 'ID' grab that item and save it to the other table (for example, an item moving from 'playing' to 'not playing'). The problem is, I need to be able to select multiple items holding down the shift key, and transfer all of those as an array to the other side.
Does anyone know how to do this? I have posted the code that will move just one item back and forth between playing and not playing grids. On the screen, there are various buttons (they are scripted below) and two grids, the 'ngrid' are slides not playing and the 'pgrid' are slides playing.
Feel free to use this exhaustive code in this next post for your own purposes, but please help me figure out passing multiple select variables to/from these datagrids! :o
Thanks,
Nate
nathaniel
01-18-2006, 10:37 PM
Below is the code, attached is a screenshot of this frame:
js_btn.enabled = false;
if (_root.comingfromshow == true) {
resume_btn._visible = true;
} else {
resume_btn._visible = false;
}
resume_btn.onRelease = function() {
_root.resume = true;
_root.gotoAndPlay('show');
};
import mx.controls.DataGrid;
_parent.setup_mc._visible = false;
_parent.loading_mc._visible = true;
var ngrid:DataGrid;
var pgrid:DataGrid;
right_btn.enabled = false;
left_btn.enabled = false;
up_btn.enabled = false;
down_btn.enabled = false;
var cursel:Object;
var curindex:Number;
var curmsel:Array;
var xmldata:XML;
var ndp:Array;
var pdp:Array;
//var ndpdisplay:Array;
//var pdpdisplay:Array;
laodData();
function laodData():Void {
xmldata = new XML();
ndp = new Array();
pdp = new Array();
xmldata.load("media/data.xml");
xmldata.ignoreWhite = true;
xmldata.onLoad = setupData;
}
function setupData():Void {
var pcnt = 0;
var ncnt = 0;
for (var i = 0; i<xmldata.firstChild.childNodes.length; i++) {
if (xmldata.firstChild.childNodes[i].attributes.Visibility eq "true") {
pdp[pcnt] = {CNo:Number(xmldata.firstChild.childNodes[i].attributes.ChapterNum), ChapterName:xmldata.firstChild.childNodes[i].attributes.ChapterName, PNo:Number(xmldata.firstChild.childNodes[i].attributes.PageNum), PageName:xmldata.firstChild.childNodes[i].attributes.PageName, SMI:xmldata.firstChild.childNodes[i].attributes.SMI, Order:Number(xmldata.firstChild.childNodes[i].attributes.Order), Path:xmldata.firstChild.childNodes[i].attributes.Path};
pcnt++;
} else {
ndp[ncnt] = {CNo:Number(xmldata.firstChild.childNodes[i].attributes.ChapterNum), ChapterName:xmldata.firstChild.childNodes[i].attributes.ChapterName, PNo:Number(xmldata.firstChild.childNodes[i].attributes.PageNum), PageName:xmldata.firstChild.childNodes[i].attributes.PageName, SMI:xmldata.firstChild.childNodes[i].attributes.SMI, Order:Number(xmldata.firstChild.childNodes[i].attributes.Order), Path:xmldata.firstChild.childNodes[i].attributes.Path};
ncnt++;
}
}
setPgrid();
setNgrid();
setupgridLook();
}
function setupgridLook():Void {
pgrid.setStyle("alternatingRowColors", [0xEAFFEB, 0xFFFFFF]);
pgrid.resizableColumns = false;
pgrid.sortableColumns = false;
// pgrid.multipleSelection = true;
pgrid.getColumnAt(0).width = 33;
pgrid.getColumnAt(1).width = 165;
pgrid.getColumnAt(2).width = 34;
pgrid.getColumnAt(3).width = 195;
// pgrid.getColumnAt(4).width = 40;
// pgrid.multipleSelection = true;
pgrid.removeColumnAt(4);
pgrid.removeColumnAt(5);
pgrid.removeColumnAt(6);
ngrid.setStyle("alternatingRowColors", [0xEAFFEB, 0xFFFFFF]);
ngrid.resizableColumns = false;
ngrid.sortableColumns = false;
// pgrid.multipleSelection = true;
ngrid.getColumnAt(0).width = 33;
ngrid.getColumnAt(1).width = 165;
ngrid.getColumnAt(2).width = 34;
ngrid.getColumnAt(3).width = 195;
// pgrid.getColumnAt(4).width = 40;
// pgrid.multipleSelection = true;
ngrid.removeColumnAt(4);
ngrid.removeColumnAt(5);
ngrid.removeColumnAt(6);
left_btn.enabled = false;
right_btn.enabled = false;
up_btn.enabled = false;
down_btn.enabled = false;
}
function setPgrid():Void {
pdp.sortOn("Order", 16);
pgrid.dataProvider = pdp;
setupgridLook();
}
function setNgrid():Void {
ndp.sortOn("PNo", 16);
ngrid.dataProvider = ndp;
if (ndp.length == 0) {
ndp[0] = {CNo:"", ChapterName:"", PNo:"", PageName:"", SMI:"", Order:"", Path:""};
ngrid.dataProvider = ndp;
ngrid.removeItemAt(0);
}
setupgridLook();
}
var pgridListener:Object = new Object();
pgridListener.change = function(event) {
ngrid.selectedIndex = null;
curmsel = event.target.selectedItems;
cursel = pdp[event.target.selectedIndex];
curindex = event.target.selectedIndex;
left_btn.enabled = true;
right_btn.enabled = false;
setUpDown();
js_btn.enabled = true;
};
pgrid.addEventListener("change", pgridListener);
var ngridListener:Object = new Object();
ngridListener.change = function(event) {
pgrid.selectedIndex = null;
curmsel = event.target.selectedItems;
cursel = ndp[event.target.selectedIndex];
curindex = event.target.selectedIndex;
right_btn.enabled = true;
left_btn.enabled = false;
up_btn.enabled = false;
down_btn.enabled = false;
js_btn.enabled = false;
};
ngrid.addEventListener("change", ngridListener);
var leftbtnListener:Object = new Object();
leftbtnListener.click = function(event) {
if (curmsel.length>1) {
for (var i = 0; i<curmsel.length; i++) {
ngrid.addItem(curmsel[i]);
pgrid.removeItemAt(curindex-curmsel.length+1);
}
} else {
ngrid.addItem(cursel);
pgrid.removeItemAt(curindex);
}
left_btn.selected = false;
setNgrid();
};
left_btn.addEventListener("click", leftbtnListener);
var rightbtnListener:Object = new Object();
rightbtnListener.click = function(event) {
if (curmsel.length>1) {
for (var i = 0; i<curmsel.length; i++) {
pgrid.addItem(curmsel[i]);
ngrid.removeItemAt(curindex-curmsel.length+1);
}
} else {
pgrid.addItem(cursel);
ngrid.removeItemAt(curindex);
}
right_btn.selected = false;
setPgrid();
};
right_btn.addEventListener("click", rightbtnListener);
up_btn.onRelease = function() {
if (curindex>0) {
var tmp = cursel.Order;
cursel.Order = pdp[curindex-1].Order;
pdp[curindex-1].Order = tmp;
pgrid.removeItemAt(curindex);
pgrid.addItemAt(curindex-1, cursel);
curindex = curindex-1;
cursel = pdp[curindex];
pgrid.selectedIndex = curindex;
if (curindex == 0) {
up_btn.enabled = false;
}
setUpDown();
}
};
down_btn.onRelease = function() {
if (curindex<pdp.length-1) {
var tmp = cursel.Order;
cursel.Order = pdp[curindex+1].Order;
pdp[curindex+1].Order = tmp;
pgrid.removeItemAt(curindex);
pgrid.addItemAt(curindex+1, cursel);
curindex = curindex+1;
cursel = pdp[curindex];
if (curindex == pdp.length-1) {
down_btn.enabled = false;
}
pgrid.selectedIndex = curindex;
setUpDown();
}
};
function setUpDown():Void {
if (curindex>0 && curindex == pdp.length-1) {
up_btn.enabled = true;
down_btn.enabled = false;
} else if (curindex<pdp.length-1 && curindex == 0) {
down_btn.enabled = true;
up_btn.enabled = false;
} else if (curindex>0 && curindex<pdp.length-1) {
up_btn.enabled = true;
down_btn.enabled = true;
}
}
_root.saveTo = "media/data.xml";
save_btn.onRelease = function() {
_root.saveContent = generateXML();
fscommand("flashstudio.savetofile", "saveTo,saveContent");
_root.msg = "Data Saved Successfully";
fscommand("flashstudio.prompt", "msg");
};
revertlast_btn.onRelease = function() {
laodData();
};
revert_btn.onRelease = function() {
ndp = new Array();
pdp = new Array();
for (var i = 0; i<xmldata.firstChild.childNodes.length; i++) {
pdp[i] = {CNo:Number(xmldata.firstChild.childNodes[i].attributes.ChapterNum), ChapterName:xmldata.firstChild.childNodes[i].attributes.ChapterName, PNo:Number(xmldata.firstChild.childNodes[i].attributes.PageNum), PageName:xmldata.firstChild.childNodes[i].attributes.PageName, SMI:xmldata.firstChild.childNodes[i].attributes.SMI, Order:Number(xmldata.firstChild.childNodes[i].attributes.Order), Path:xmldata.firstChild.childNodes[i].attributes.Path};
}
pdp.sortOn("PNo", 16);
pgrid.dataProvider = pdp;
setupgridLook();
ndp = new Array();
ngrid.removeAll();
};
function generateXML():XML {
var rootXML:XML = new XML();
rootElement = rootXML.createElement("chapters");
for (var i = 0; i<pdp.length; i++) {
subElement = rootXML.createElement("chapter");
subElement.attributes.ChapterNum = pdp[i].CNo;
subElement.attributes.ChapterName = pdp[i].ChapterName;
subElement.attributes.PageNum = pdp[i].PNo;
subElement.attributes.PageName = pdp[i].PageName;
subElement.attributes.SMI = pdp[i].SMI;
subElement.attributes.Order = pdp[i].Order;
subElement.attributes.Path = pdp[i].Path;
subElement.attributes.Visibility = "true";
rootElement.appendChild(subElement);
}
for (var j = 0; j<ndp.length; j++) {
subElement = rootXML.createElement("chapter");
subElement.attributes.ChapterNum = ndp[j].CNo;
subElement.attributes.ChapterName = ndp[j].ChapterName;
subElement.attributes.PageNum = ndp[j].PNo;
subElement.attributes.PageName = ndp[j].PageName;
subElement.attributes.SMI = ndp[j].SMI;
subElement.attributes.Order = ndp[j].Order;
subElement.attributes.Path = ndp[j].Path;
subElement.attributes.Visibility = "false";
rootElement.appendChild(subElement);
}
rootXML.appendChild(rootElement);
return rootXML;
}
var intr = setInterval(showApp, 500);
function showApp():Void {
_parent.loading_mc._visible = false;
_parent.setup_mc._visible = true;
clearInterval(intr);
}
main_btn.onRelease = function() {
_root.gotoAndPlay('main');
};
start_btn.onRelease = function() {
_root.gotoAndPlay('show');
};
js_btn.onRelease = function() {
_root.currentPageNum = pgrid.getItemAt(curindex).PNo;
_root.resume = true;
_root.gotoAndPlay('show');
};
Thanks for yer help :D
nathaniel
01-19-2006, 02:29 PM
Does anyone have any ideas or a direction to point me on (i.e., I've heard of custom components that I can import... maybe there is a datagrid that makes multiple selection more intuitive)? :confused:
vBulletin® v3.7.1, Copyright ©2000-2009, Jelsoft Enterprises Ltd.