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 6628285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:06:47+00:00 2026-05-25T22:06:47+00:00

In Actionscript 3, is there a way to sort the nodes (instances of type

  • 0

In Actionscript 3, is there a way to sort the nodes (instances of type XML) in an XMLList in document order (as defined in the XDM spec; “Informally, document order is the order in which nodes appear in the XML serialization of a document”)? Alternately, is there a way to compare the document position of two nodes?

Here’s a little example of what I mean. In the real case, the list is constructed by a much more complicated process and might have hundreds of nodes.

var x:XML = <a><b/><b/></a>;
var b0:XML = x.b[0];
var b1:XML = x.b[1];
var l:XMLList = new XMLList();
l += b1;
l += b0;
var sl:XMLList = documentSortFunction(l);
assertTrue(sl[0] === b0);

I’m not sure I have a lot of hope here, since it seems that ECMA-357 (E4X) doesn’t really have a concept of document, much less document order.

  • 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. Editorial Team
    Editorial Team
    2026-05-25T22:06:48+00:00Added an answer on May 25, 2026 at 10:06 pm

    Well, here’s a sketch of the answer I came up with. This hasn’t been tested much yet, but I thought I’d record it before I forget to.

    The idea is to implement a function to generate a string for a node, such that the order of the strings is the same as the order of the nodes.

    protected function generateSortID(n:XML):String
    {
        var ret:String = '';
        while (n != null && n.childIndex() > -1)
        {
            var s:String = '' + n.childIndex();
            ret = '0000000'.substring(s.length) + s + '!' + ret;
            n = n.parent();
        }
        return ret;
    }
    
    protected function compareNodePair(a:Array, b:Array):int
    {
        var ai:String = a[0];
        var bi:String = b[0];
        if (ai < bi)
            return -1;
        else if (ai > bi)
            return 1;
        else
            return 0;
    }
    
    // all nodes in input list must be part of the same document.
    protected function documentSortFunction(l:XMLList):XMLList
    {
        var augArr:Array = [];
        for (var il:String in l)
            augArr.push([generateSortID(l[il]), l[il]]);
        augArr.sort(compareNodePair);
        var ret:XMLList = new XMLList();
        for (var ia:String in augArr)
            ret += augArr[ia][1];
        return ret;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to modify xml document via actionscript? I have bare xml
Is there a way ActionScript 3 can detect the user's screen resolution?
In Flex/ActionScript 3, is there a better way to monitor the date/time to determine
Is there a way to cast dynamically in Actionscript? What I want to accomplish
Working with ActionScript 3.0, is there a way to determine if my SWF file
is there a way to deserialize strings to objects in actionscript: i.e. var str:String
Is there any way to create foldable regions of code in ActionScript 3 (read
Is there a way to get a list of events available in Actionscript 3?
Is there any way to implement waiting for, say, 3 seconds in ActionScript, but
Is there a way within ActionScript 3.0 to: Get all URLRequests() that are made

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.