Skip to main content
Inspiring
July 2, 2007
Question

Finding unique paths : Follow up

  • July 2, 2007
  • 2 replies
  • 291 views

> 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...
This topic has been closed for replies.

2 replies

Inspiring
July 2, 2007
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.

kglad
Community Expert
Community Expert
July 2, 2007
email was sent 7/2 at 15:40 pst.
Inspiring
July 2, 2007
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.