0

I am working in Flash CS4 with AS3.

I have a TextPage.fla file that contains a dynamic text field (name: PageTitle) as an instance on the stage. In the document class (TextPage) I set the text of PageTitle according to some XML. This all works fine.

I have another fla file, SpecialTextPage.fla, and that also has the PageTitle dynamic text field on the stage.

I now try to have the SpecialTextPage document class inherit from Textpage:

public class SpecialTextPage extends TextPage
{
...
}

but I get a "1120: Access of undefined property PageTitle." error when trying to publish SpecialTextPage. The error location is given as TextPage.as

As a workaround I can just copy the whole TextPage.as file and add in the extra things I need in SpecialTextPage.as but I'd obviously prefer it if I could just extend it.

I got the feeling I am not quite understanding the relationship between flash's objects on the stage and the document class.

Can someone help?

2 Answers 2

0

A document class is basically taken and dumped on the first frame of the timeline of a SWF then executed at run time and therefore has access to everything on the stage like they were hand written properties in your class.

Now imagine you create a variable in your SpecialTextPage that you call var i:int; No matter what you do, the parent class will never have access to i (nor should it). The same way, the stage elements linked through to your document class, the parent will never have access to them.

Similar to MovieClip extending Sprite, Sprite can never make reference to the MovieClips timeline because it has no awareness of it.

But not all is lost! A nice way to achieve your goal is to have the following:

/* TextPage */
/* Parent Class */
/* ... */
public function TextPage() {
    pageTitle.text = getTitle(); // This textfield would be the one in TextPage.fla
}

protected function getTitle():String {
    return "All the text you could ever need in your title";
}
/* ... */


/* SpecialTextPage */
/* Child */
/* ... */
public function SpecialTextPage() {
   pageTitle.text = getTitle(); // This textfield would be in SpecialTextPage.fla
}
1
  • Thanks for your answer. I had assumed that the base class would pick up the field on the child class as long as it has the same name. I didn't see how your proposed solution would work as it is still referencing the field name but I did find a solution that worked for me - see my answer to the question.
    – nicodenzl
    Mar 1, 2011 at 12:10
0

The way I got around the problem was to disable declaring stage instances automatically. (Publish Settings --> Flash Tab --> Uncheck 'Automatically declare stage instances')

I then needed to declare pageTitle on my TextPage class as a public field:

public class TextPage extends MovieClip
{
    public var pageTitle:TextField;
    ...
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.