I have a custom tree item renderer that is working out great except one
little small problem. In my item renderer I have some actions for adding /
removing / renaming directories. The only time I don't want the remove or
rename context menu items is when its the home directory. I know that I can
hack it and hard code it here because the data object is passed to each
function.
What I am trying to do though is going back to the main part of the
applicaiton (or pass in) the baseDirectory so I can account for change. Has
anyone got data in/or out of a renderer before? If it was just another class
it would be easy to put in the constructor but there is no constructor when
you add it to the tree.
**** itemRenderer="com.rocketfm.CustomTreeItemRenderer"
package com.rocketfm {
import flash.display.DisplayObject;
import flash.events.ContextMenuEvent;
import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;
import mx.collections.*;
import mx.controls.treeClasses.*;
import mx.core.Application;
import mx.managers.PopUpManager;
import views.AddDirectory;
import views.DeleteDirectory;
import views.RenameDirectory;
public class CustomTreeItemRenderer extends TreeItemRenderer {
private var renameWin:RenameDirectory;
private var addWin:AddDirectory;
private var delWin:DeleteDirectory;
public function CustomTreeItemRenderer(basePath) {
super();
var menu:ContextMenu = new ContextMenu();
var add:ContextMenuItem = new ContextMenuItem("Add Folder");
var remove:ContextMenuItem = new ContextMenuItem("Remove
Folder");
var rename:ContextMenuItem = new ContextMenuItem("Rename
Folder");
var download:ContextMenuItem = new ContextMenuItem("Download
All");
add.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,addDirectory);
remove.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,removeDirectory);
rename.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,renameDirectory);
menu.hideBuiltInItems();
menu.customItems.push(add);
menu.customItems.push(remove);
menu.customItems.push(rename);
this.contextMenu = menu;
}
private function addDirectory(event:ContextMenuEvent):void {
addWin = new AddDirectory();
addWin.dirPath = data.path;
addWin.parentPath = data.parent;
addWin.item = data;
// add window
PopUpManager.addPopUp(addWin,DisplayObject(Application.application),true);
}
private function removeDirectory(event:ContextMenuEvent):void {
delWin = new DeleteDirectory();
delWin.item = data;
// delete window
PopUpManager.addPopUp(delWin,DisplayObject(Application.application),true);
}
private function renameDirectory(event:ContextMenuEvent):void {
renameWin = new RenameDirectory();
renameWin.item = data;
renameWin.oldDirectoryName = data.name;
renameWin.parentPath = data.parent;
// rename window
PopUpManager.addPopUp(renameWin,DisplayObject(Application.application),true);
}
}
}
Thank You
Dan Vega
[email protected]
http://www.danvega.org