Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

_parent from a class

1 view
Skip to first unread message

brian914

unread,
Feb 10, 2009, 2:35:16 PM2/10/09
to
I am having a hard time with scope.
I am working on a class that is linked to an MC and from that class trying to
call a function on the timeline of the _parent MC. I thought I could do
something like the following, but can't seem to reach the function. I am pretty
sure it has to do with scope, but I just don't quite get it yet. What am I
doing wrong? How is this done?

Thank you so much!

private function onItemClick(e:Object):Void
{
_parent.loadVideo(e.target.id);
}


kglad

unread,
Feb 10, 2009, 2:48:45 PM2/10/09
to
use trace(this._parent) below your loadVideo() call to see what you're doing. if that's undefined, use trace(this) to see the scope of onItemClick().

brian914

unread,
Feb 10, 2009, 3:01:36 PM2/10/09
to
OK, I made a mistake with my post, sorry. The function actually looks like this:

private function newSection(whichVid:Number):Void
{
_parent.loadVideo(whichVid);
trace("this trace is: " + this);
trace("this._parent trace is: " + this._parent);
}

Both traces return an undefined. How is that possible?

Thank you!

brian914

unread,
Feb 10, 2009, 3:03:54 PM2/10/09
to
I also tried calling:
this._parent.loadVideo(whichVid);
which did not seem to work either.

kglad

unread,
Feb 10, 2009, 4:32:24 PM2/10/09
to
what code causes newSection() to execute?

brian914

unread,
Feb 10, 2009, 4:39:50 PM2/10/09
to
It gets called from here:

private function onItemClick(e:Object):Void
{

TweenLite.to(this.white_out, aniTime2, {_alpha:100, overwrite:0,
onComplete:newSection, onCompleteParams:[e.target.id]});
}

And if I trace the Params from inside the other function I get the right
values, so it seems that they are coming through.

kglad

unread,
Feb 10, 2009, 6:28:33 PM2/10/09
to
yep. you're losing scope there.

in your onCompleteParams send a reference to your class ("this") and use that
in newSection():

private function onItemClick(e:Object):Void
{

TweenLite.to(this.white_out, aniTime2, {_alpha:100, overwrite:0,

onComplete:newSection, onCompleteParams:[e.target.id,this]});
}

private function newSection(whichVid:Number,yourclassRef:YourClass):Void
{
yourclassRef._parent.loadVideo(whichVid);

}

brian914

unread,
Feb 10, 2009, 7:27:35 PM2/10/09
to
Wow, ok, that works! Thank you so much.
I need to somehow learn that concept, it is giving me a hard time...

Thank you!!!

kglad

unread,
Feb 11, 2009, 1:31:01 AM2/11/09
to
you're welcome.

and i had a lot of trouble "getting" it, too. it's certainly not the easiest thing to fully grasp. (but once you get it, things are much easier when using oop.)

0 new messages