继承文档类时AS3错误1120
我正在 Flash CS4 和 AS3 中工作。
我有一个 TextPage.fla 文件,其中包含一个动态文本字段(名称:PageTitle)作为舞台上的实例。 在文档类(TextPage)中,我根据一些 XML 设置 PageTitle 的文本。 这一切都很好。
我有另一个 fla 文件 SpecialTextPage.fla,并且舞台上也有 PageTitle 动态文本字段。
我现在尝试让 SpecialTextPage 文档类继承自 Textpage:
public class SpecialTextPage extends TextPage
{
...
}
但我收到“1120:访问未定义的属性 PageTitle”。尝试发布 SpecialTextPage 时出错。 错误位置以 TextPage.as 形式给出。
作为一种解决方法,我可以复制整个 TextPage.as 文件并在 SpecialTextPage.as 中添加我需要的额外内容,但如果我可以扩展它,我显然更喜欢它。
我感觉我不太理解舞台上的Flash对象和文档类之间的关系。
有人可以帮忙吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
文档类基本上是在 SWF 时间线的第一帧上获取和转储,然后在运行时执行,因此可以访问舞台上的所有内容,就像它们是类中手写的属性一样。
现在假设您在 SpecialTextPage 中创建一个变量,并将其称为 var i:int;无论你做什么,父类都永远无法访问 i (也不应该)。同样,通过链接到文档类的舞台元素,父级将永远无法访问它们。
与扩展 Sprite 的 MovieClip 类似,Sprite 永远无法引用 MovieClip 时间线,因为它不知道它。
但并非一切都失去了!实现目标的一个好方法是具备以下条件:
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:
我解决这个问题的方法是禁用自动声明阶段实例。
(发布设置 --> Flash 选项卡 --> 取消选中“自动声明阶段实例”)
然后我需要在 TextPage 类上将 pageTitle 声明为 public 字段:
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: