9 Replies Latest reply on Oct 21, 2010 2:53 PM by kglad

    REMOVED_FROM_STAGE event firing when it shouldn't...

    totallyNoobular

      Hello everyone,

      Wondering if someone has seen this before. I have an application that has a few navigation points on the main timeline. The document class stops the movie at the first frame, and the "home" movieclip's class has Event.ADDED_TO_STAGE and Event.REMOVED_FROM_STAGE listeners on it. Funny thing is, it is calling the ADDED function as normal, then firing the REMOVED function immediately after. However, when I run it, it doesn't actually remove the movieclip from the stage. It is still there. When I navigate to a different section ("remote" or "assist") and navigate back to "home", it doesn't fire a second time, everything works properly after the first time.

       

      So I guess my question is, what would fire the REMOVED_FROM_STAGE event without actually removing the object from the stage? And why would it only happen once?

       

      Thanks for looking!

      -Nick

       

       

       

      Here is some code as well as a screen shot of my main timeline:

       

      package src.modules {
          import flash.display.MovieClip;
          import flash.events.Event;
          import flash.events.MouseEvent;
         
          import src.utils.greensock.TweenLite;
          import src.utils.greensock.easing.*;
         
          public class ModHome extends MovieClip {
             
              private static const DISTANCE:int = 700;
              private static const TWEEN_DURATION:Number = 1.0;
             
              private var _currentPage:int = 1;
              private var _isDone:Boolean = true;
             
              public function ModHome() {
                  super();
      //            trace("home initialized");
                  addEventListener(Event.ADDED_TO_STAGE, onAddedToStage, false, 0, true);
              }
             
              private function onAddedToStage(evt:Event):void {
                  trace("home added to stage");
                  removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
                  addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage, false, 0, true);
                  // BUTTONS
                  pageLeft_btn.addEventListener(MouseEvent.CLICK, onMouseClick, false, 0, true);
                  pageRight_btn.addEventListener(MouseEvent.CLICK, onMouseClick, false, 0, true);
              }
             
              private function onRemovedFromStage(evt:Event):void {
                  removeEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
                  // BUTTONS
                  pageLeft_btn.removeEventListener(MouseEvent.CLICK, onMouseClick);
                  pageRight_btn.removeEventListener(MouseEvent.CLICK, onMouseClick);
      //            trace("home removed from stage");
              }
             
              private function onMouseClick(evt:MouseEvent):void {
                  if(_isDone) {
                      switch (evt.target.name) {
                          case "pageLeft_btn" :
                              movePages("left");
                              break;
                          case "pageRight_btn" :
                              movePages("right");
                              break;
                          default :
      //                        trace("home -- nothing");
                              break;
                      }
                  }
              }
             
              // SCROLLING WINDOW
              private function movePages(thedirection:String):void {
                  _isDone = false;
                  var x1:int;
                  switch (thedirection) {
                      case "right" :
                          if (_currentPage > 1) {
                              _currentPage = _currentPage - 1;
                              x1 = pages_mc.x + DISTANCE;
                              TweenLite.to(pages_mc, TWEEN_DURATION, {x:x1, ease:Quint.easeInOut, onComplete:onTweenComplete});
                          } else {
                              _isDone = true;
                          }
                          break;
                      case "left" :
                          if (_currentPage < 3) {
                              _currentPage = _currentPage + 1;
                              x1 = pages_mc.x - DISTANCE;
                              TweenLite.to(pages_mc, TWEEN_DURATION, {x:x1, ease:Quint.easeInOut, onComplete:onTweenComplete});
                          } else {
                              _isDone = true;
                          }
                          break;                   
                  }
              }
             
              private function onTweenComplete():void {
                  _isDone = true;
                  pageMarker_mc.gotoAndStop(_currentPage);
      //            trace("complete");
              }
          }
      }

       

       

      timeline-1.png