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

Library MovieClip linkage and class inheritance

Contributor ,
Jul 10, 2013 Jul 10, 2013

Copy link to clipboard

Copied

I've come across this problem several times and never figured out a clean solution; might as well try now. I'll explain the problem with a simplified example.

I have three different MovieClips in my library used as popup dialogs. They each share core functionality but have some different controls. For this reason it makes sense to use class extension. However, trying to have the base class refer to a control found in all three child classes causes an error.

Say we have

Dialog is a base class that extends MovieClip but is not directly linked to anything in the library

MovieClip NotificationDialogMC is linked to the class NotificationDialog

     NotificationDialog extends the class Dialog

MovieClip SaveDialogMC is linked to the class SaveDialog

     SaveDialog extends the class Dialog

MovieClip OpenDialogMC is linked to the class OpenDialog

     OpenDialog extends the class Dialog

NotificationDialogMC, SaveDialogMC, and OpenDialogMC all contain a TextField named "textLabel" that is supposed to behave in the same way. Normally if you link a library MovieClip to a class, you can refer to children inside the MovieClip directly by their instance name. So I try to create a function in the base class as follows:

public function set labelText(value:String):void {

     this.textLabel.text = value

}

Although "textLabel" exists in all three children, during compilation Dialog gives the error "Access of possibly undefined property textLabel" because it does not exist in the base class. However, if I create a variable called textLabel, this causes a conflict because the base class and the MovieClip linked to the child class have two different objects with the same name.

I can fix this problem by making Dialog a dynamic class, but making a class dynamic opens a whole host of other issues. Is there another strategy that will work here? I know I could add the TextField in code, but I feel like coding static layouts instead of creating them in the IDE is wasting one of the biggest benefits of Flash.

The forum text editing pane is not rendering this post correctly at all; hopefully that gets fixed when I post it.

TOPICS
ActionScript

Views

1.5K

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Jul 11, 2013 Jul 11, 2013

oh, i see.  that's a compiler screw-up.

just cast "this" in your base class as a MovieClip:

public function set labelText(value:String):void {

     MovieClip(this).textLabel.text = value

}

Votes

Translate

Translate
Community Expert ,
Jul 10, 2013 Jul 10, 2013

Copy link to clipboard

Copied

i don't see that problem:  http://www.kglad.com/Files/forums/test.zip

Votes

Translate

Translate

Report

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
Contributor ,
Jul 11, 2013 Jul 11, 2013

Copy link to clipboard

Copied

That's because you didn't set up the code the way I explained. You put

public function set tfF(value:String):void {

                              this.tf.text = value

}

into the child classes. I'm saying Flash throws a compile-time error if you put that in the base class (Page in your sample), even if the child has that TextField

Votes

Translate

Translate

Report

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 ,
Jul 11, 2013 Jul 11, 2013

Copy link to clipboard

Copied

oh, i see.  that's a compiler screw-up.

just cast "this" in your base class as a MovieClip:

public function set labelText(value:String):void {

     MovieClip(this).textLabel.text = value

}

Votes

Translate

Translate

Report

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
Contributor ,
Jul 11, 2013 Jul 11, 2013

Copy link to clipboard

Copied

Wow, I never would have thought of that! That did the trick. Thank you very much!

Votes

Translate

Translate

Report

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 ,
Jul 11, 2013 Jul 11, 2013

Copy link to clipboard

Copied

LATEST

you're welcome.

that's a common compiler short-comming though that's the first time i've seen it in that guise.  a more typical problem triggering an 1119 error is with:

root.variable_defined_on_root;  // root will need to be cast as a MovieClip

or

this.parent.variable_defined_on_a_parent_timeline;  // this.parent often needs to be cast as a MovieClip

Votes

Translate

Translate

Report

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