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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:25:57+00:00 2026-05-23T03:25:57+00:00

While recursive scans are commonly use to scan through nested objects / data. It

  • 0

While recursive scans are commonly use to scan through nested objects / data. It can go on an infinite loop, if some of the objects references one another. So what is the most effective way to scan all items, without crashing the computer, nor skipping a specified parameter?

Here is an example of a recursive scanner…

/**
 * Triggers the scan function for each object given
 **/
function recursiveScanner( object:* , scanFunction:Function ):void {
    if( typeof(object) == 'object' ) {
        for( var key:String in object ) {
            recursiveScanner( object[key], scanFunction );
        }
    } else {
        scanFunction.call(this, object);
    }
}

However a huge problems occur when the following is passed in

//...
obj1.next = obj2;
//...
obj2.next = obj3;
//...
obj3.next = obj1;
//...
recursiveScanner(obj1, scanFuction);

The objects will trigger scans for one another in an eternal loop. So is there a way to solve this?

I do believe in C/C++ : Each scanFunction call, will be added into a list consisting of scanned ‘memory address’, thus preventing a repeat. Is this even possible in AS3? Is there a more elegent way?

  • 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-23T03:25:57+00:00Added an answer on May 23, 2026 at 3:25 am

    Use a Dictionary to keep a list of scanned objects and ignore them if they’ve been scanned before:

    /**
     * Triggers the scan function for each object given
     **/
    function recursiveScanner( object:* , scanFunction:Function, ignoreList:Dictonary = null ):void {
        // if we have no list, create one
        if (!ignoreList) ignoreList = new Dictionary();
    
        // if the item is in the list, we bail
        if (ignoreList[object]) return;
    
        // mark the item as scanned before recursing into it
        ignoreList[object] = true;
    
        if( typeof(object) == 'object' ) {
            for( var key:String in object ) {
                recursiveScanner( object[key], scanFunction, ignoreList );
            }
        } else {
            scanFunction.call(this, object);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can some one explain the below, rather complex recursive generic template usage? public abstract
While going through university and from following the development of SO, I've heard a
While I have written plenty of recursive parsers before, I have recently become interested
I recently learned about Recursive Common Table Expressions (CTEs) while looking for a way
While formulating an answer to another SO question , I came across some strange
While the C# spec does include a pre-processor and basic directives (#define, #if, etc),
While I've seen rare cases where private inheritance was needed, I've never encountered a
While setting up CruiseControl, I added a buildpublisher block to the publisher tasks: <buildpublisher>
While working in a Java app, I recently needed to assemble a comma-delimited list
While in the final throws of upgrading MS-SQL Server 2005 Express Edition to MS-SQL

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.