4 Replies Latest reply on Jul 2, 2007 4:40 PM by Newsgroup_User

    Finding unique paths : Follow up

    Level 7

      > function pathExists(shapeStart, shapeEnd):Boolean {
      > for (var node in shapeStart) {
      > for (var key in shapeStart[node].obj) {
      > if (key == shapeEnd) {
      > return true;
      > } else {
      > pathExists(key,shapeEnd);
      > }
      > }
      > }
      > return false;
      > }

      kglad...

      I implemented your solution this morning but came up with the same type
      of problem I was having before with my own recursive function.

      Here is the code (modified from what you posted) that I am using:
      function pathExists(shapeStart, shapeEnd):Boolean {
      for (var i:Number = 0; i < allConnections[shapeStart].length; i++) {
      if (allConnections[shapeStart] ._parent == shapeEnd) {
      trace("shapeEnd found in list");
      return true;
      } else if (checkedParents.indexOf(allConnections[shapeStart]
      .
      _parent) == -1) {
      checkedParents.push(allConnections[shapeStart] ._parent)
      pathExists(allConnections[shapeStart]
      ._parent,shapeEnd);
      }
      }
      return false;
      }

      The problem is this... once the condition is met which returns true (I
      know this condition is met because my trace works) it does not actually
      return true to the initial caller. So, I end up with false being
      returned. It is as if the true is being returned to the recursive call
      and not to the original function call. Does that make sense?

      Thanks...
        • 1. Re: Finding unique paths : Follow up
          Level 7
          Sean Berry wrote:
          >> function pathExists(shapeStart, shapeEnd):Boolean {
          >> for (var node in shapeStart) {
          >> for (var key in shapeStart[node].obj) {
          >> if (key == shapeEnd) {
          >> return true;
          >> } else {
          >> pathExists(key,shapeEnd);
          >> }
          >> }
          >> }
          >> return false;
          >> }
          >
          > kglad...
          >
          > I implemented your solution this morning but came up with the same type
          > of problem I was having before with my own recursive function.
          >
          > Here is the code (modified from what you posted) that I am using:
          > function pathExists(shapeStart, shapeEnd):Boolean {
          > for (var i:Number = 0; i < allConnections[shapeStart].length; i++) {
          > if (allConnections[shapeStart] ._parent == shapeEnd) {
          > trace("shapeEnd found in list");
          > return true;
          > } else if (checkedParents.indexOf(allConnections[shapeStart]
          .
          > _parent) == -1) {
          > checkedParents.push(allConnections[shapeStart] ._parent)
          > pathExists(allConnections[shapeStart]
          ._parent,shapeEnd);
          > }
          > }
          > return false;
          > }
          >
          > The problem is this... once the condition is met which returns true (I
          > know this condition is met because my trace works) it does not actually
          > return true to the initial caller. So, I end up with false being
          > returned. It is as if the true is being returned to the recursive call
          > and not to the original function call. Does that make sense?
          >
          > Thanks...


          kglad...

          I did what you suggested and it seems to do the trick. However, now I
          am wondering how I would go about finding the actual path. The goal
          here will be to ensure there are at least 2 unique paths from startShape
          to endShape. Specifically I will be evaluating the nodes for uniqueness.

          Thanks for any and all suggestions.
          • 2. Re: Finding unique paths : Follow up
            Level 7
            Sean Berry <sean.berry@cox.net> wrote in news:f6bpal$dnj$1
            @forums.macromedia.com:

            > Sean Berry wrote:
            >>> function pathExists(shapeStart, shapeEnd):Boolean {
            >>> for (var node in shapeStart) {
            >>> for (var key in shapeStart[node].obj) {
            >>> if (key == shapeEnd) {
            >>> return true;
            >>> } else {
            >>> pathExists(key,shapeEnd);
            >>> }
            >>> }
            >>> }
            >>> return false;
            >>> }
            >>

            kglad.

            I would like to enlist your help away from the forums. I would be willing
            to pay for your time, although I do not expect it to take all that long.

            I know it is already listed in the post, but my email is
            sean(dot)berry(at)cox(dot)net

            Just give me an hourly rate and I will supply the question with sample
            flash.

            Thanks.

            • 3. Re: Finding unique paths : Follow up
              kglad Adobe Community Professional & MVP
              email was sent 7/2 at 15:40 pst.
              • 4. Re: Finding unique paths : Follow up
                Level 7
                "kglad" <webforumsuser@macromedia.com> wrote in news:f6but0$k10$1
                @forums.macromedia.com:

                > email was sent 7/2 at 15:40 pst.

                reply sent.