Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

error 1009 ScrollPane/endDrag() null fix

New Here ,
Jun 16, 2010 Jun 16, 2010

I have a scrollPane that I am removing from the stage that has scrollDrag = true. When its removed however I get this error when clicking on other objects and the stage.

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

anyone know a fix for this?

TOPICS
ActionScript
4.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 16, 2010 Jun 16, 2010

The obvious choice would be the set scrollDrag to false before removing the scrollpane from the display list. When scrollDrag is true, the instance adds event listeners to the stage. I suspect, the stage mouse up event is firing the endDrag.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 16, 2010 Jun 16, 2010

instead of setting scrollDrag = false, would there be a way to find out what event listeners are being added and

remove those instead?


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 16, 2010 Jun 16, 2010

endDrag is a protected method, so you can't remove the listener from outside the instance.

You should take a look at the source code for ScrollPane - more specifically, the setScrollDrag method, which is called after you change scrollDrag.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 16, 2010 Jun 16, 2010

ok im not sure if im actually removing if from the display list.

I have a menu button2 that gotoAndStop(2)

on frame 2 there is a movieclip homeLoader_mc. inside that mc on frame 1 loads the scrollPane. So then when you click on menu button1 and it gotoAndStop(1) homeLoader_mc does not exist in frame 1 so the loaded content is no longer displayed. However I never actually say removeChild(homeLoader) anywhere.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 16, 2010 Jun 16, 2010

Well, you'll most likely need to play around with Event.REMOVED_FROM_STAGE, and turn off scrollDrag.

In a test scenario, this is what I did:

// on the frame that contains the ScrollPane:

sp.scrollDrag=true;
sp.addEventListener(Event.REMOVED_FROM_STAGE, h);
function h(e:Event)
{
sp.scrollDrag=false;
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 16, 2010 Jun 16, 2010

that makes sense however how do I get that to work with this code

var homeRequest:URLRequest = new URLRequest("home1.swf");
var homeLoader:Loader = new Loader;
homeLoader.load(homeRequest);

homeLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadCOMPLETE);
function onLoadCOMPLETE(e:Event):void{
    var home1:MovieClip = e.target.content;
    addChild(homeLoader);
        homeLoader.x = 0;
        homeLoader.y = 0;
}

obviously I cant place that function outside of this function and still reference  var home1

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 16, 2010 Jun 16, 2010

If I understand the architecture, the ScrollPane instance that's causing the problem is in home1.swf.

If so, the simplest way would be to edit home1.fla. Is that an option?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 16, 2010 Jun 16, 2010

yes the scrollPane is inside of home1

it is editable but what would you suggest, it pretty much needs to stay inside home1

also how does the REMOVED_FROM_STAGE listener be able to control the scrollDrag method if the scrollPane has been removed from the stage?

I now have this in the first frame and im still getting the error

scrollPane.addEventListener(Event.REMOVED_FROM_STAGE, scrollPaneRemoved);
function scrollPaneRemoved(e:Event)
{
scrollPane.scrollDrag=false;
}
scrollPane.addEventListener(Event.ADDED_TO_STAGE, scrollPaneAdded);
function scrollPaneAdded(e:Event)
{
scrollPane.scrollDrag=true;
}

Any function were I try and set scrollDrag then gives me a null object reference inside that function, even if that function is in the same frame of the scrollPane

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 16, 2010 Jun 16, 2010

If home1 is a single frame swf, or if scrollPane is on the stage for all frames in home1, then you shouldn't need to handle ADDED_TO_STAGE. All you would need is this in the first frame:

scrollPane.scrollDrag=true;

scrollPane.addEventListener(Event.REMOVED_FROM_STAGE, scrollPaneRemoved);
function scrollPaneRemoved(e:Event)
{
scrollPane.scrollDrag=false;
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 16, 2010 Jun 16, 2010

sorry I should have been more specific.

home1.fla is multiframed. since it is going to be loaded externaly by another .swf the frame(1) is the preloader, frame(2) contains the scrollPane and another frame, currently frame(4) has other content, not containing the scrollPane.

essentially I have a content box, you click menu button1 to goto frame(2) the scrollPane appears, click on menu button2 to goto frame(4) were the scrollPlane is replaced by a single image.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 16, 2010 Jun 16, 2010

OK, so the script needs to go on the frame that contains the scrollPane. When the frame is entered, scrollPane is available, and scrollDrag is set to true and the handler is attached.  Before scrollPane is removed, for whatever reason, scrollDrag is set to false - removing any stage listeners.

scrollPane.scrollDrag=true;

scrollPane.addEventListener(Event.REMOVED_FROM_STAGE, scrollPaneRemoved);
function scrollPaneRemoved(e:Event)
{
scrollPane.scrollDrag=false;
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 16, 2010 Jun 16, 2010

Yes I have that exactly in the frame that contains the scrollPane.

It allows me to click the menu button2 and go to the next frame without an error. but then when I click menu button1 to go back to the frame containing the scrollPane, I still get the null object error for scrollDrag

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 16, 2010 Jun 16, 2010

Hmm, perhaps there's a timing issue - the instance may not yet be created when the script runs. Try delaying with an ENTER_FRAME:

stop();

function setupScrollPane()
{
if(scrollPane==null)
{
  addEventListener(Event.ENTER_FRAME, enterFrameHandler);
  return;
}
removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
scrollPane.scrollDrag=true;
scrollPane.addEventListener(Event.REMOVED_FROM_STAGE, scrollPaneRemoved);

}

function scrollPaneRemoved(e:Event)
{
scrollPane.scrollDrag=false;
}

function enterFrameHandler(e:Event)
{
setupScrollPane();
}
setupScrollPane();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 16, 2010 Jun 16, 2010

Thats not working either. This is a rediculous problem I have found. does anyone have a work around?

for now I think im just going to go with scrollPane.visible = false. But thats still not going to fix the problem for when I have home1.swf loaded into the main.swf

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 17, 2010 Jun 17, 2010
LATEST

on another forum I was told to create a subclass to override the function like this

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);
               }
          }
     }
}

how do i set this subclass up tho? im not familiar

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines