Reputation: 7105
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?
Upvotes: 3
Views: 3667
Reputation: 3
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. :)
Upvotes: 0
Reputation: 169
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.
Upvotes: 3
Reputation: 21
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...
Upvotes: 2
Reputation: 51847
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:
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
Upvotes: 3