Pages: [1]
  Print  
Author Topic: help/error # 1009/new to GAIA  (Read 510 times)
ge5
Gaia Novice
*
Posts: 2


« on: February 05, 2010, 05:23:59 PM »

i can't figure out why this message keeps ccoming up/i am loading a scroll bar swf into another swf which then loads into another--its a ui element  i've used in this way many times before without error but NOT in GAIA...i am including the code below from the script that throws the error ("TypeError: Error #1009: Cannot access a property or method of a null object reference at com.macphee.ui::ScrollBar/thumbUp()") --
the "thumbUp" in this file seems not to get removed even though i thought i did that and took care of removing listeners...the error gets thrown after this swf is removed fr the stage and replaced with another and it then gets thrown by any mouse down on the stage).. if anyone can help i am MOST appreciative! thank you.
//////////////////////////////////////////////////////////////////////////
package com.macphee.ui{
   import flash.display.*;
   import flash.events.*;
   
   
public class ScrollBar extends MovieClip {
      private var yOffset:Number;
      private var yMin:Number;
      private var yMax:Number;

public function ScrollBar():void {
         thumb.useHandCursor = true;
         thumb.buttonMode = true;
         yMin = 0;
         yMax = track.height - thumb.height;
         
         //--------------------------------------------------//
         //when you load prototype.swf it's not immediately added to the display list. because of that it's reference to 'stage' is invalid
         //and this line "stage.addEventListener(MouseEvent.MOUSE_UP, thumbUp);" is causing error.
         //so you need to check when your file was actually added to the display list and then add your event listener to the stage.
addEventListener(Event.ADDED_TO_STAGE, addListeners);
addEventListener(Event.REMOVED_FROM_STAGE, removeListeners);
      }
      
      
      //--------- method to add the event listeners -------------------//
      private function addListeners(e:Event):void {
         //trace("addlistener")
         removeEventListener(Event.ADDED_TO_STAGE, addListeners);
         thumb.addEventListener(MouseEvent.MOUSE_DOWN, thumbDown);
         stage.addEventListener(MouseEvent.MOUSE_UP, thumbUp);
      }
      //------------------------------------------------------------//
private function removeListeners(e:Event):void {
      stage.removeEventListener(MouseEvent.MOUSE_MOVE, thumbMove);
      removeEventListener(Event.ADDED_TO_STAGE, addListeners);
      
//trace("REMOVEDListeners")
}
      
private function thumbDown(e:MouseEvent):void {
         stage.addEventListener(MouseEvent.MOUSE_MOVE, thumbMove);
         yOffset = mouseY - thumb.y;
      }
      private function thumbUp(e:MouseEvent):void {
         stage.removeEventListener(MouseEvent.MOUSE_MOVE, thumbMove);
         
      }
      private function thumbMove(e:MouseEvent):void {
         thumb.y = mouseY - yOffset;
         if (thumb.y <= yMin) {
            thumb.y = yMin;
         }
         if (thumb.y >= yMax) {
            thumb.y = yMax;
         }//var sp:Number = thumb.y / yMax; //scroll percentage
         dispatchEvent(new ScrollBarEvent(thumb.y / yMax));
         e.updateAfterEvent();
      }
   }
}
Logged
steven
Gaia Author
Administrator
Gaia Evangelist
*****
Posts: 3871


gaiaframework
WWW
« Reply #1 on: February 05, 2010, 07:48:38 PM »

You need to figure out what is hanging on to the reference and why.  It's just going to take some tracing to figure it out., but I'm sure you will.

Worse comes to worse, you can always do this:

if (stage)

Smiley
Logged

Steven Sacks | Gaia Author
Please support Gaia by donating to the project!  Smiley
ge5
Gaia Novice
*
Posts: 2


« Reply #2 on: February 06, 2010, 06:39:32 AM »

i have traced all the functions  in the "scroll bar" a.s. and can't figure this out..urfgh..can you elaborate on where/how i might use the "if statement" ? and thanks for answering! and so quickly.
Logged
Pages: [1]
  Print  
 
Jump to:  

TinyPortal v1.0 beta 4 © Bloc