PDA

View Full Version : DDTree - finding a components instance name..


fileas
11-04-2003, 08:10 AM
I'm adapting the DDTree for a current project (for those that don't know it's a drag and drop version of the fTree component from flashcomponents.net) and i'm having a little difficulty!

basically I have two instances of the DDTree on the stage - one called 'myArticles' and one called 'mySiteStructure'. The idea is you drag the articles to the site structure and then output the xml of the nodes of the sitestructure (so it acts like a sort of content management system)

If you select a node on the tree (beit a branch/section or an article) the details of that node are displayed below. I've changed the doClick function as follows.


DDTreeClass.prototype.doClick = function(node){
trace(myTree.getRootNode().getLabel());
if (node.isBranch()) {
showSectionDetails();
} else {
showArticleDetails();
}
}


which then calls a function to display the details:

function showSectionDetails(){
hideArticleDetails();
mcSectionDetails.txtMenuLabel.text = mySiteStructure.getSelectedNode().getMenuLabel();
mcSectionDetails.txtSectionName.text = mySiteStructure.getSelectedNode().getLabel();
//more details added here.......
mcSectionDetails._visible = true;
}

the thing is i'd like it to show the details of the other tree too but at the moment i'm having to specify mySiteStructure.

SO the question is.... in the doClick function how do you know which tree had been clicked on and more importantly what the instance name of that tree is?? I guess it would be the same as working

any help would be much appreciated!

later

fil

dross
11-11-2003, 06:26 PM
I've been in your situation before... I have a project with over 10 customized DD-trees in it.. I use it for everything from user selection (move people in one list from another)... to kind of an adapted heirarchical data-grid.

Now, there's a couple ways to get around your issue. You can, but it's probably better not to have any instance-specific code in the ddtree class (fyi, when in a prototype function, "this" refers to any instance of that prototype). What you really want is to do different things whe people click on different instances of your ddtree's right?

So, get rid of your customized doClick function and do something like this for your "mySiteStructure" ddtree instance:

mySiteStructure.doClick = function(node){
hideArticleDetails();
mcSectionDetails.txtMenuLabel.text = node.getMenuLabel();
mcSectionDetails.txtSectionName.text = node.getLabel();
//more details added here.......
mcSectionDetails._visible = true;
}


within that function, 'this' == mySiteStructure. This will allow you to have different doClick functions for different trees... you can do the same for doDrop, etc... You only want to modify the ddtree class when it's something that you need to affect all instances of it... for instance I added some code for a doDblClick function (double clicked a node)...I even changed everything to allow the dragging of multiple nodes at the same time.

hope this helps,

dave

fileas
11-11-2003, 07:06 PM
thanks dave! :)

..that makes perfect sense - never thought to do it that way!

One question though - when you add these extra functions do you put them in the same place as the ddTree class or is it ok to leave them on the main timeline?

I've just started getting my head round prototype's but noticed they seem to occupy the same space as the main timeline like they're global or something (in that you don't have to state a path to them)- wondered what the best practise was?

thanks again

phil

dross
11-11-2003, 07:28 PM
glad i could help...

you would probably want to put instance-specific functions as close as possible to the instance.. so if the instances are on the main timeline they should should go there.

The prototype class is just that, a prototype... it is nothing until it is instantiated, where it gets things like a name (in your case "mySiteStructure"), a size, etc... so any code that pertains to an instance of ddtree should be outside of the prototype class.

This actually makes more sense when you do everything in code... but when you drag something on the stage to create an instance, it can get confusing.