Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Parent problems

Explorer ,
Sep 03, 2008 Sep 03, 2008
Hi all,
I have a custom class called ToolBar which is attached to a library item. The library item has other clips within it and each is an instance of ToolBarButtonA, B, C etc and these all extend the generic class ToolBarButton.
If I set an event handler for CLICK within each ToolBarButton to trace 'parent' it comes back [Object ToolBar] which is what I expected but if I try to then call a method through 'parent.methodName()' it fails saying 'call to possibly undefined method'

Can anyone give any advice?
Cheers
TOPICS
ActionScript
603
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 03, 2008 Sep 03, 2008
methodName() is a public method?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 03, 2008 Sep 03, 2008
You should be using just methodName() instead of parent.methodName()
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 04, 2008 Sep 04, 2008
methodName() is public and I am using parent because the buttons are children of the ToolBar movie clip rather than extensions of the attached class.
I have worked round this problem now but would still be interested to find an answer. I found that I could access parent.x, .y etc but not my custom methods which made me wonder, could it be something to with parent returning a reference to the class object rather than to a specific instance of it?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 04, 2008 Sep 04, 2008
Ah, I misread the inheritance.

parent is a property of DisplayObject and gives you access to the hierarchy of the display list. It returns a DisplayObjectContainer and that gives you access to its public properties and methods, like x and y. It doesn't return the specialized datatype ToolBar. Doing a trace on parent accesses the Object.toString method and returns the string representation of object ToolBar.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 04, 2008 Sep 04, 2008
Ok, that makes sense (I think). I am loving AS3 but every time I think I have a handle on it something like this comes up and I have to go back and research something else.
Oh well, cheers for the help.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 04, 2008 Sep 04, 2008
as long as that method is public you can access it. you probably just needed to cast the parent as a ToolBar instance:

ToolBar(this.parent).methodName();
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 04, 2008 Sep 04, 2008
Yes, that cast will work.
I would declare public properties in ToolBar.as and register an event listener on the toolbar buttons instead.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 04, 2008 Sep 04, 2008
Hi Every Body
I a new to AS3. i am facing problem in accessing Children of a Movie Clip.
p1, p2 p3 are childern of movieclip Chracter and character is child of cSelection that is child of CMotion
i want to access p1,p2,p3 dynamically using a loop like
for(var i:int=1; i<4;i++)
{
MovieClip(Cmotion).cSelection.["p"+i].alpha =0;
}

Please tell me how i can do it. Thanks in advance
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 04, 2008 Sep 04, 2008
LATEST
Hi Every Body
I am new to AS3. i am facing problem in accessing Children of a Movie Clip.
p1, p2 p3 are childern of movieclip Chracter and character is child of cSelection that is child of CMotion
i want to access p1,p2,p3 dynamically using a loop like
for(var i:int=1; i<4;i++)
{
MovieClip(Cmotion).cSelection.p .alpha =0;
}

Please tell me how i can do it. Thanks in advance
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines