Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 75993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:36:13+00:00 2026-05-10T20:36:13+00:00

So I have a flex tree component with a xmllistcollection as it’s data provider.

  • 0

So I have a flex tree component with a xmllistcollection as it’s data provider. I would like to be able to rearrange the leaves and branches in the tree by drag and drop. I want to limit the drop area to the current level of the item being dragged. Like

       branch        branch 0          leaf 1          leaf 2        branch x          leaf a          leaf b        

So, branch x can’t be moved under branch 0 and leaf a could not be moved under branch 0.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T20:36:14+00:00Added an answer on May 10, 2026 at 8:36 pm

    Okay, here’s a pretty simple way to do this, based on the last example in this Flex Quick Starts article. This should probably be improved by using the ‘proper’ drop indicators (the lines between items) instead of just selecting the item under the mouse when dragging.

    The most relevant part is the onDragOver() method, where we restrict where items can be dropped.

    <?xml version='1.0' encoding='utf-8'?> <mx:Application xmlns:mx='http://www.adobe.com/2006/mxml'>     <mx:Script>         <![CDATA[              import mx.events.DragEvent;             import mx.managers.DragManager;             import mx.core.DragSource;             import mx.core.UIComponent;             import mx.controls.Tree;              private var _draggedItem:XML = null;               private function onDragEnter( event:DragEvent ) : void             {                 event.preventDefault();                 event.currentTarget.hideDropFeedback(event);                  var ds:DragSource = event.dragSource;                 var items:Array = ds.dataForFormat('treeItems') as Array;                 if (items != null && items.length > 0 && (items[0] is XML))                     _draggedItem = items[0];                  DragManager.acceptDragDrop(UIComponent(event.currentTarget));             }              private function onDragOver( event:DragEvent ) : void             {                 event.preventDefault();                 event.currentTarget.hideDropFeedback(event);                  tree.selectedIndex = tree.calculateDropIndex(event);                 var node:XML = tree.selectedItem as XML;                  // restrict drag & drop to nodes within same parent                 if (_draggedItem.parent() != node.parent())                 {                     DragManager.showFeedback(DragManager.NONE);                     return;                 }                  DragManager.showFeedback(DragManager.MOVE);             }              private function onDragDrop( event:DragEvent ) : void             {                 event.preventDefault();                 event.currentTarget.hideDropFeedback(event);                  tree.selectedIndex = tree.calculateDropIndex(event);                 var node:XML = tree.selectedItem as XML;                  var addToIndex:int = node.childIndex();                 if ((_draggedItem.parent() == node.parent()) && (addToIndex != _draggedItem.childIndex()))                 {                     tree.dataDescriptor.removeChildAt(node.parent(), _draggedItem, _draggedItem.childIndex());                     tree.dataDescriptor.addChildAt(node.parent(), _draggedItem, addToIndex);                 }             }              private function onDragComplete( event:DragEvent ) : void             {                 tree.selectedIndex = -1;             }             ]]>     </mx:Script>         <mx:XML id='treeData' xmlns=''>         <root>             <node label='Massachusetts' type='state' data='MA'>                 <node label='Boston' type='city' >                     <node label='Smoke House Grill' type='restaurant' />                     <node label='Equator' type='restaurant' />                     <node label='Aquataine' type='restaurant' />                     <node label='Grill 23' type='restaurant' />                 </node>                 <node label='Provincetown' type='city' >                     <node label='Lobster Pot' type='restaurant' />                     <node label='The Mews' type='restaurant' />                 </node>             </node>             <node label='California' type='state' data='CA'>                 <node label='San Francisco' type='city' >                     <node label='Frog Lane' type='restaurant' />                 </node>             </node>         </root>     </mx:XML>     <mx:Tree width='100%' height='100%' id='tree'         labelField='@label'         dataProvider='{treeData.node}'         allowMultipleSelection='false'         dragEnabled='true'         dropEnabled='true'         dragMoveEnabled='false'         dragEnter='onDragEnter(event)'         dragOver='onDragOver(event)'         dragDrop='onDragDrop(event)'         dragComplete='onDragComplete(event)'>     </mx:Tree>         </mx:Application> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In flex 3 I have a hierarchical data structure. I would like to display
I have a Flex tree with an ArrayCollection as data provider. The collection holds
I'm creating a reusable flex tree component. And i would like to stick in
I am working on the flex tree drag and drop functionality and i have
I have Flex 4 DataGrid, what I would like to do is when an
I have a tree in flex built from an XML document into an XMLlist
I am having some trouble with the flex Tree control. I have a control
I have a basic Tree built in Flex. The Tree works fine. I'm attempting
I have flex advancedDataGrid (could use dataGrid if that works better, though i like
I have a Flex Application, and I need to track site catalyst data with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.