Groups | Blog | Home
all groups > flash actionscript > february 2004 >

flash actionscript : Save state of tree component in sharedObject


Brad Berkland
2/8/2004 10:36:04 PM
Hello

I am using tree components (MX 2004 Pro) to present collections of useful
links at couple web sites. I would like to be able to store the current state
of the tree in a sharedObject when a user clicks on a node so that when he/she
returns to the links page, the tree of links has the same branches
opened/closed as when the user was last there. I have used the sharedObject and
understand that part of the problem - what I need to know is how I go about
getting a snapshot of the tree and its branches so I can save that data. Thanks
for your help
W Gerber
3/11/2004 3:01:48 PM
Laiverd.COM
3/11/2004 4:25:29 PM
Please stick to original thread; this is completely useless without context.

--
----------------------------------------------------------------------------
-----------
RESOURCES
http://groups.google.com/advanced_group_search?hl=en&as_ugroup=*flash
----------------------------------------------------------------------------
-----------
TUTORIALS at
www.laiverd.com
Flash & PHP Emailform
Using textfiles in Flash
----------------------------------------------------------------------------
-----------

Mike Horton
3/15/2004 4:01:15 PM
Brad try this. Hope it helps

Mike

//handle tree node selections
function bgTreeCall(component) {
//identify selected node
var s = component.getSelectedNode();
//check for double-click
checkDblClick(s);
//toggle folder state on double-click
if (s.isBranch() && dClick) {
toggleOpen = ((s.isOpen()) ? false : true);
s.setIsOpen(toggleOpen);
t.refresh();
saveBranches();
} else {
//get new data on first click
if (!dClick) cD = s.getData();
//process data
cD.update();
}
}

//restore tree to last saved state
function setBranches() {
fL = this.bg_so.data.folderList;
rO = this.bg_so.data.rootOpen;

if (fL == undefined) {
//define default state
t.getRootNode().setIsOpen(true);
} else {
t.getRootNode().setIsOpen(rO);
var bArray = t.getRootNode().getChildNodes();
var i = 0;
setBranchesLoop(bArray,fL,i);
}
t.refresh();
}

function setBranchesLoop(bArray,fL,i) {
for (var j=0; j<bArray.length; j++) {
if (bArray[j].isBranch()) {
bArray[j].setIsOpen(fl[i]);
i++;
var thisChildren = bArray[j].getChildNodes();
i = setBranchesLoop(thisChildren,fL,i);
}
}
return i;
}

//get tree status when a branch is opened/closed
function saveBranches() {
rOpen = t.getRootNode().isOpen();
var bOpen = new Array();
var bArray = t.getRootNode().getChildNodes();
saveBranchesLoop(bOpen,bArray);
//by defining these parameters as properties of the shared
//object they get automatically saved if the file gets closed
this.bg_so.data.folderList = bOpen;
this.bg_so.data.rootOpen = rOpen;
}

function saveBranchesLoop(bOpen,bArray){
for (var j=0; j<bArray.length; j++) {
if (bArray[j].isBranch()) {
bOpen.push(bArray[j].isOpen());
var thisChildren = bArray[j].getChildNodes();
saveBranchesLoop(bOpen,thisChildren);
}
}
}














[quoted text, click to view]

Mike Horton
3/15/2004 4:04:33 PM
Brad, try this. Hope it helps.

Mike

//handle tree node selections
function bgTreeCall(component) {
//identify selected node
var s = component.getSelectedNode();
//check for double-click
checkDblClick(s);
//toggle folder state on double-click
if (s.isBranch() && dClick) {
toggleOpen = ((s.isOpen()) ? false : true);
s.setIsOpen(toggleOpen);
t.refresh();
saveBranches();
} else {
//get new data on first click
if (!dClick) cD = s.getData();
//process data
cD.update();
}
}

//restore tree to last saved state
function setBranches() {
fL = this.bg_so.data.folderList;
rO = this.bg_so.data.rootOpen;

if (fL == undefined) {
//define default state
t.getRootNode().setIsOpen(true);
} else {
t.getRootNode().setIsOpen(rO);
var bArray = t.getRootNode().getChildNodes();
var i = 0;
setBranchesLoop(bArray,fL,i);
}
t.refresh();
}

function setBranchesLoop(bArray,fL,i) {
for (var j=0; j<bArray.length; j++) {
if (bArray[j].isBranch()) {
bArray[j].setIsOpen(fl[i]);
i++;
var thisChildren = bArray[j].getChildNodes();
i = setBranchesLoop(thisChildren,fL,i);
}
}
return i;
}

//get tree status when a branch is opened/closed
function saveBranches() {
rOpen = t.getRootNode().isOpen();
var bOpen = new Array();
var bArray = t.getRootNode().getChildNodes();
saveBranchesLoop(bOpen,bArray);
//by defining these parameters as properties of the shared
//object they get automatically saved if the file gets closed
this.bg_so.data.folderList = bOpen;
this.bg_so.data.rootOpen = rOpen;
}

function saveBranchesLoop(bOpen,bArray){
for (var j=0; j<bArray.length; j++) {
if (bArray[j].isBranch()) {
bOpen.push(bArray[j].isOpen());
var thisChildren = bArray[j].getChildNodes();
saveBranchesLoop(bOpen,thisChildren);
}
}
}

AddThis Social Bookmark Button