duh!

Thanks, Andy.

On 4/24/07, Andy Herrman <[EMAIL PROTECTED]> wrote:
You need a 'return' before the recursive call:


class com.research.StaticRecurse
{
       public static function
getOuterMostParent(mc:MovieClip,mcRoot:MovieClip):MovieClip
       {
               if (mc._parent._name == "garden")
               {
                       trace("inside getOuterMostParent: " + mc);
                       return mc;
               }
               else
               {
                       // Add a return here:
                       return getOuterMostParent(mc._parent);
               }
       }
}

  -Andy

On 4/24/07, me myself <[EMAIL PROTECTED]> wrote:
> Okay, so I have an FLA with a series of embedded movieclips:
>
> garden > tree > branch > twig > flower.
>
> I want a static function -- in an as 2.0 class -- that, when given
> flower, returns tree. In other words, you can give in an embedded
> movieclip and it finds that clips ALMOST outermost parent.
>
> Here's my class & function:
>
> class com.research.StaticRecurse
> {
>         public static function
> getOuterMostParent(mc:MovieClip,mcRoot:MovieClip):MovieClip
>         {
>                 if (mc._parent._name == "garden")
>                 {
>                         trace("inside getOuterMostParent: " + mc);
>                         return mc;
>                 }
>                 else
>                 {
>                         getOuterMostParent(mc._parent);
>                 }
>         }
> }
>
>
> and inside the fla, I use the following code:
>
> import com.research.StaticRecurse;
>
> var innerMostChild:MovieClip = garden.tree.branch.twig.flower;
> var mc:MovieClip = StaticRecurse.getOuterMostParent(innerMostChild);
> trace("outside getOutMostParent: " + mc);
>
> the trace is as follows:
>
> inside getOuterMostParent: _level0.garden.tree
> outside getOutMostParent: undefined
>
> As you can see, the first trace -- which works beautifully -- occurs
> RIGHT BEFORE the return statement. But the value that's actually
> returned is undefined. I've never encountered anything like this
> before. To me, it seems as if I'm doing this:
>
> function x():Number
> {
>       var n:Number = 1000;
>       trace(n); //1000
>       return n;
> }
>
> trace(x()); //undefined
>
> ... which would be insane. I'm guessing it's a scoping issue that has
> to do with recursion and the fact that this is a static function
> (which it kind of has to be). Why is this happening? Is there a
> workaround? Thanks!
> _______________________________________________
> Flashcoders@chattyfig.figleaf.com
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
>
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to