当scrollDrag=true时ScrollPane/endDrag()中的空对象引用

发布于 2024-08-24 07:30:11 字数 623 浏览 11 评论 0原文

在我的 Flash 应用程序中,我有多个使用滚动窗格的窗口。对于这些,scrollDrag 属性设置为 true,因为我想要该功能。如果我关闭(在我的应用程序中)其中一个“窗口”并打开另一个,我的日志中似乎会出现大量此错误:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at fl.containers::ScrollPane/endDrag()

有时我会收到数千个这样的错误,我猜这可能会减慢我的速度应用程序下降了一点,但除此之外不会造成问题。浏览一下scrollpane的adobe代码,endDrag非常简单:

protected function endDrag(event:MouseEvent):void {
        stage.removeEventListener(MouseEvent.MOUSE_MOVE, doDrag);
    }

stage var是这里唯一可以为null的东西。

我唯一能想到的就是在应用程序中的窗口关闭之前设置scrollDrag = false,以便没有任何内容侦听该事件。还有其他建议吗?

In my flash application, I've got multiple windows which use Scrollpanes. The scrollDrag property is set to true on these because I want that functionality. If I close (within my application) one of these 'windows' and open another, I seem to get a whole lot of this error showing up in my logs:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at fl.containers::ScrollPane/endDrag()

Sometimes I get thousands of these, which I'm guessing is probably slowing my app down a bit, but otherwise is not causing a problem. Looking through the adobe code for scrollpane, endDrag is really simple:

protected function endDrag(event:MouseEvent):void {
        stage.removeEventListener(MouseEvent.MOUSE_MOVE, doDrag);
    }

The stage var is the only thing that could be null here.

The only thing I can think to do is set scrollDrag=false before the window in my application closes so that nothing is listening for the event. Any other suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

泪意 2024-08-31 07:30:11

我尝试重新创建您的场景,因此我有一个虚拟剪辑由 ScrollPane 加载,并且
ScrollPane 包含在带有链接的 MovieClip 中(导出为 Actionscript),因此我可以创建多个实例。同样在该剪辑中,我在 ScrollPane 组件上方的一层放置了一个关闭按钮。

我的第一个尝试是调试 fla 并查看它首先失败的具体位置。我没有设法找出任何东西,因为我不断得到这个:

Cannot display source code at this location.

然后我按照你的指示操作,找到了 endDrag() 函数。我把它改成这样:

protected function endDrag(event:MouseEvent):void {
            if(stage) stage.removeEventListener(MouseEvent.MOUSE_MOVE, doDrag);
        }

并尝试了一下。第一次不行,好像没有编译过。我尝试在 Flash IDE 中编辑该类,然后我看到了这个小警告的含义。这就是我的意思:

ScrollPane edit

所以我将 ScrollPane.as 从 Flash CS4 文件夹复制到 . /fl/containers/ScrollPane(基本上相对于 .fla)。这个 .as 文件已编译,错误消失了。

简短版本是:是的!您找到了问题点:) 添加一个 if 来检查 null 对象作为快速修复,并且不要忘记在再次编译之前将 ScrollPane.as 相对于 .fla 文件或类路径保存。

哈特哈,
乔治

I've tried to recreate your scenario, so I had a dummy clip to be loaded by the ScrollPane, and
the ScrollPane contained withing a MovieClip with linkage(Export for Actionscript) so I can create several instances. Also in that clip, a layer above the ScrollPane component I've placed a close button.

My first attept was to debug the fla and see where exactly it fails first. I didn't mange to find out anything this was as I kept getting this:

Cannot display source code at this location.

Then I followed your instructions, and found the endDrag() function. I changed it to this:

protected function endDrag(event:MouseEvent):void {
            if(stage) stage.removeEventListener(MouseEvent.MOUSE_MOVE, doDrag);
        }

And tried it. It didn't work the first time, as if it was not compiled. I tried to edit the class within the Flash IDE and I saw what this little caveat was all about. Here's what I mean:

ScrollPane edit

So I copied ScrollPane.as from the Flash CS4 folder into ./fl/containers/ScrollPane (basically relative to the .fla). This .as file got compiled, and the error was gone.

Short version is: Yup! you found the problem spot :) Add an if to check for null object as a quickfix and don't forget to save ScrollPane.as relative to the .fla file or in your classpath before compiling again.

HTH,
George

恰似旧人归 2024-08-31 07:30:11

万一有人仍在寻找解决方案,对我有用的是子类化 ScollPane 类并覆盖 endDrag 函数

package {
import fl.containers.*;
import flash.events.*;
public class ScrollPain extends ScrollPane {
    protected override function endDrag(event:MouseEvent):void {
        if (stage) {
            stage.removeEventListener(MouseEvent.MOUSE_MOVE, doDrag);
        }
    }
}

}

完全归功于 FlashKit 论坛上的 dawsonkFlashKit 线程链接。< /a>

Just in case anyone is still looking for a solution, what worked for me was to subclass the ScollPane class and override the endDrag function

package {
import fl.containers.*;
import flash.events.*;
public class ScrollPain extends ScrollPane {
    protected override function endDrag(event:MouseEvent):void {
        if (stage) {
            stage.removeEventListener(MouseEvent.MOUSE_MOVE, doDrag);
        }
    }
}

}

Full credit to dawsonk over at the FlashKit forums for this one. FlashKit thread link.

过去的过去 2024-08-31 07:30:11

当使用带有scrollDrag=true 的scrollpane 时,我也遇到同样的问题。
我的问题的解决方案是设置 scrollDrag = false,每次我从显示中删除滚动窗格(更改框架等时)

希望它有帮助...

I have the same problem when using scrollpane with scrollDrag=true.
My solution for my problem is to set scrollDrag = false, everytime I remove scrollpane from displaying (when changing the frame etc.)

Hope it helps...

烂人 2024-08-31 07:30:11

本地主机的解决方案对我有用,所以谢谢。然而,我用头撞墙了几个小时,直到我意识到我忘记将所有对 ScrollPane 类的代码引用更改为对 ScrollPain 类的引用。

这是一个示例:即使更改了库中 ScrollPane 组件的类,我仍然收到错误。然后我意识到,在实例化 ScrollPane 的类中,我需要将实例化更改为

var scrollPane:ScrollPane = new ScrollPane(); 

var scrollPane:ScrollPain = new ScrollPain (); 

此外,我需要将导入语句更改为

import fl.components.ScrollPane;

import com.mysite.ScrollPain;

我确实意识到这是一个初学者错误。 :)

localhost's solution worked for me, so thanks. However, I banged my head against the wall for a couple of hours, until I realized that I had forgotten to change all my code references to the ScrollPane class to refer instead to the ScrollPain class.

Here's an example: I was still getting the error, even after changing the class of my ScrollPane component in my library. Then I realized that, in the classes that instantiated a ScrollPane, I needed to change the instantiation from

var scrollPane:ScrollPane = new ScrollPane(); 

to say:

var scrollPane:ScrollPain = new ScrollPain (); 

In addition, I needed to change my import statement from

import fl.components.ScrollPane;

to say:

import com.mysite.ScrollPain;

I do realize this is a beginner mistake. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文