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

Ask A Question

Stats

  • Questions 69k
  • Answers 69k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Everything's possible :) EDIT: haste never leads to quality nor… May 11, 2026 at 12:33 pm
  • added an answer With Django 1.1, which is currently in beta, I would… May 11, 2026 at 12:33 pm
  • added an answer The format for generics is the name, a ` character,… May 11, 2026 at 12:33 pm

Related Questions

So I have a flex tree component with a xmllistcollection as it's data provider.
So I have a module in flex in which I add a custom component.
So I have a Stateful .NET webservice (C#) that I would like Flex to
So, I have Flex project that loads a Module using the ModuleManager - not
So I have a Sybase stored proc that takes 1 parameter that's a comma
Well, not literally, of course, but: I'm new to Flex and I'm trying to
I have a Flex movie that contains a text input box and an (optional)
This question is about a Java JTree or a Window .Net Tree (Winforms) or
In a Flex application, I'm have an xml object that I'm binding to a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.