调用其他类中的函数不起作用
大家好,不知道这里发生了什么:(
基本上我有一个函数需要告诉其他 2 个类做某事。它适用于其中一个类:BigPlayButton,但由于某种原因不适用于背景。TabMenu.as
Class函数
注意:下面的函数将调用我的 BigPlayButton 类中的 hitPlayCircle 函数,但我收到背景 switchTitle 函数的未定义属性错误
private function thumbClick(e:MouseEvent = null):void
{
trace("YOU CLICKED THUMBNAIL: " + e.target.id);
trace("PLAY THIS VIDEO: " + tabData[tabID].video[e.target.id].@flv);
trace("THE VIDEO TITLE: " + tabData[tabID].video[e.target.id].@title);
newTitle = tabData[tabID].video[e.target.id].@title;
Background.instance.switchTitle(newTitle);
BigPlayButton.instance.playState = false;
BigPlayButton.instance.hitPlayCircle(); // Hide the big play button
vdp.setflvSource(tabData[tabID].video[e.target.id].@flv);
vdp.playNewVideo(tabData[tabID].video[e.target.id].@flv);
}
。 我已经导入了这两个类,所以不确定发生了什么:( 我确实正确设置了 static var 实例变量。
public static var instance:Background; //<- in Background Class
public static var instance:BigPlayButton; // <- in BigPlayButton Class
我在两个类中也都有 instance = this;
...
我试图从 TabMenu 类调用我的后台类中的函数:
public function switchTitle(sentText):void
{
titleString = sentText;
vTitle.text = titleString;
}
错误消息(我似乎总是收到此错误)
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at ui::TabMenu/thumbClick()
Hey everyone, not sure what is going on here :(
Basically I have a function that is needs to tell 2 other classes to do something. It works for one of the classes: BigPlayButton, but not Background for some reason.
TabMenu.as Class function
Note: The function below WILL call the hitPlayCircle function in my BigPlayButton class, but I get an undefined property error for the Background switchTitle function.
private function thumbClick(e:MouseEvent = null):void
{
trace("YOU CLICKED THUMBNAIL: " + e.target.id);
trace("PLAY THIS VIDEO: " + tabData[tabID].video[e.target.id].@flv);
trace("THE VIDEO TITLE: " + tabData[tabID].video[e.target.id].@title);
newTitle = tabData[tabID].video[e.target.id].@title;
Background.instance.switchTitle(newTitle);
BigPlayButton.instance.playState = false;
BigPlayButton.instance.hitPlayCircle(); // Hide the big play button
vdp.setflvSource(tabData[tabID].video[e.target.id].@flv);
vdp.playNewVideo(tabData[tabID].video[e.target.id].@flv);
}
I've imported both classes so not sure what's going on :(
I did correctly set my static var instance variables.
public static var instance:Background; //<- in Background Class
public static var instance:BigPlayButton; // <- in BigPlayButton Class
And I have instance = this;
in Both Classes as well...
The function inside my Background Class I'm trying to call from my TabMenu Class:
public function switchTitle(sentText):void
{
titleString = sentText;
vTitle.text = titleString;
}
Error Message (I always seem to get this error)
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at ui::TabMenu/thumbClick()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜想
Background.instance
在调用此函数时尚未实例化。尝试跟踪
Background.instance
的值。I would guess that
Background.instance
is not instantiated at the point this function is called.Try tracing the value of
Background.instance
.