views:

409

answers:

1

Hello there.

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?

+1  A: 

Hello,

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

George Profenza
Thanks. I'll accept this because it's the best answer I have. Although I'm probably not going to do this because I don't want to start versioning Adobe code.
SP
Thank you. I see your point. You should be able to create a subclass of ScrollPane, and just override endDrag, since it's protected. That way you would be versioning your code, right ?
George Profenza
Yes, that will work. Didn't think of it for some reason. Thanks.
SP