3

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?

George Profenza
  • 50,687
  • 19
  • 144
  • 218
Erix
  • 7,059
  • 2
  • 35
  • 61

4 Answers4

3

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.

localhost
  • 169
  • 6
3

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

Community
  • 1
  • 1
George Profenza
  • 50,687
  • 19
  • 144
  • 218
  • 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. – Erix Mar 22 '10 at 22:09
  • 1
    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 Mar 23 '10 at 10:45
  • Yes, that will work. Didn't think of it for some reason. Thanks. – Erix Mar 25 '10 at 13:41
2

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...

Baz
  • 36,440
  • 11
  • 68
  • 94
0

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. :)

Shulim
  • 3
  • 4