14 Replies Latest reply on Jun 8, 2016 4:16 PM by sawmangs4

    MovieClip won't add to display list after calling addChild()

    sawmangs4

      I have a MovieClip in the library that refuses to be added to the stage when calling it with addChild(). Below is the code.

       

      You will see a function called clickedACTDD_BTN. You also will see that the function offers a choice if the MovieClip is present then it is removed. If it is not present then it is given properties and added. Additionally, notice my trace statements in each choice. Everything traces as expected but the MovieClip never shows up. I've been going over this code for days and just can't see what I have done wrong. Can anyone else see it?

       

      package
      {
      // PAheader 1.0

      import flash.display.*;
      import flash.events.*;
      import flash.geom.*;

      public class PAheader extends MovieClip
      {
        public var headerScreen:Screen = Screen.mainScreen;
        public var hdrLogo;
        public var BLKback;
        public var PRFLAVTR:profileAvatarMC = new profileAvatarMC(); // Profile Avatar
        public var msgbubble:messageBubbleMC = new messageBubbleMC(); // Message Bubble
        public var magGlass:magnifyingGlassMC = new magnifyingGlassMC(); // Magnifying Glass
        public var ACTDD_BTN:ActionsDDBtnMC = new ActionsDDBtnMC(); // ACTIONS dropdown button.
        public var HISDropD_BTN:HistoryDDBtnMC = new HistoryDDBtnMC(); // HISTORY dropdown button.
        public var REPDD_BTN:ReportsDDBtnMC = new ReportsDDBtnMC(); // REPORTS dropdown button.
        public var actionbucket:ActionBucket = new ActionBucket();

        public function PAheader()
        {
         addEventListener(Event.ADDED_TO_STAGE, initPAheader);
        } // ----------------------------------------------------------------------------------------- ------------------ End public constructor function PAheader().
       
        public function initPAheader(e:Event = null):void
        {
         trace("==============================================");
         trace("PAheader called!");
         //trace("From PAheader: visibleBounds.width: "+headerScreen.visibleBounds.width+" visibleBounds.width: "+headerScreen.visibleBounds.height);
         addEventListener(Event.RESIZE, resizedHeader);
        
         BLKback.width = AWSplash.resizeAsset(1024,headerScreen.visibleBounds.width,1024);
         BLKback.scaleY = BLKback.scaleX;
         //------------- adding Assets ----------------------------------------------------------------------------------------- ---------------------------------
        
         //--- Profile Avatar
         PRFLAVTR.x = stage.fullScreenWidth - PRFLAVTR.width - 10;
         PRFLAVTR.y = height/2 - PRFLAVTR.height/2;
         addChild(PRFLAVTR);
         //--- Message Bubble
         msgbubble.x = PRFLAVTR.x - PRFLAVTR.width - 10;
         msgbubble.y = height/2 - msgbubble.height/2;
         addChild(msgbubble);
         //--- Magnifying Glass
         magGlass.x = msgbubble.x - msgbubble.width - 10;
         magGlass.x = msgbubble.x - msgbubble.width - 10;
         magGlass.y = height/2 - magGlass.height/2;
         addChild(magGlass);

        } // ----------------------------------------------------------------------------------------- -------------------------- End public function initPAheader().
        public function resizedHeader(e:Event = null):void
        {
         trace("HEADER RESIZED");
        
        } // ----------------------------------------------------------------------------------------- ------------------------- End public function resizedHeader().
       
        public function addActionsDDButton(caller:MovieClip):void
        {
         trace("addActionsDDButton. caller is: "+caller);
        
         // --- ACTIONS button
         ACTDD_BTN.width = AWSplash.resizeAsset(1024,headerScreen.visibleBounds.width,60);
         ACTDD_BTN.addEventListener(MouseEvent.CLICK, clickedACTDD_BTN);
         ACTDD_BTN.addEventListener(MouseEvent.MOUSE_OUT, outACTDD_BTN);
         ACTDD_BTN.scaleY = ACTDD_BTN.scaleX;
         ACTDD_BTN.x = HISDropD_BTN.x - ACTDD_BTN.width;
         ACTDD_BTN.y = BLKback.y;
         caller.addChild(ACTDD_BTN);
         trace("Added ACTIONS!");
         
        } // ------------------------------------------------------------------------------------ End public static function addDDButtons().
       
        public function addHistoryDDButton(caller:MovieClip):void
        {
         trace("addHistoryDDButton. caller is: "+caller);
         // --- HISTORY button
         HISDropD_BTN.width = AWSplash.resizeAsset(1024,headerScreen.visibleBounds.width,60);
         HISDropD_BTN.scaleY = HISDropD_BTN.scaleX;
         HISDropD_BTN.x = headerScreen.visibleBounds.width/2 - HISDropD_BTN.width/2;
         HISDropD_BTN.y = BLKback.y;
         caller.addChild(HISDropD_BTN);
         trace("Added HISTORY!");
        } // ------------------------------------------------------------------------------------ End public function addHistoryDDButton().
       
        public function addReportsDDButton(caller:MovieClip):void
        {
         trace("addReportsDDButton. caller is: "+caller);
         // --- REPORTS button
         REPDD_BTN.width = AWSplash.resizeAsset(1024,headerScreen.visibleBounds.width,60);
         REPDD_BTN.scaleY = REPDD_BTN.scaleX;
         REPDD_BTN.x = HISDropD_BTN.x + ACTDD_BTN.width;
         REPDD_BTN.y = BLKback.y;
         caller.addChild(REPDD_BTN);
         trace("Added REPORTS!");
        } // ------------------------------------------------------------------------------------ End public function addHistoryDDButton().
       
        /*public function removeButtons(theCaller:MovieClip)
        {
         if(theCaller.contains(HISDropD_BTN) || theCaller.contains(ACTDD_BTN) || theCaller.contains(REPDD_BTN))
         {
          theCaller.removeChild(HISDropD_BTN);
          theCaller.removeChild(ACTDD_BTN);
          theCaller.removeChild(REPDD_BTN);
         }
        } // ----------------------------------------------------------------------------------------- ------------------ End public static function removeButtons().*/
       
        public function clickedACTDD_BTN(e:MouseEvent = null):void
        {
         trace("Clicked clickedACTDD_BTN!");
         if(contains(actionbucket))
         {
          trace(this);
          removeChild(actionbucket);
          trace("1");
         }
         else
         {
          trace(this);
          actionbucket.width = AWSplash.resizeAsset(1024,headerScreen.visibleBounds.width,161);
          actionbucket.scaleY = actionbucket.scaleX;
          actionbucket.x = ACTDD_BTN.x;
          //actionbucket.y = ACTDD_BTN.y + ACTDD_BTN.height;
          actionbucket.y = ACTDD_BTN.y;
          addChild(actionbucket);
          trace("2");
         }
         } // ----------------------------------------------------------------------------------------- ---------------------- End public function clickedACTDD_BTN().
       
        public function outACTDD_BTN(e:MouseEvent = null):void
        {
         if(contains(actionbucket))
         {
          detectTarget(actionbucket);
         }
        } // ----------------------------------------------------------------------------------------- -------------------------- End public function outACTDD_BTN().
       
        public function detectTarget(target:MovieClip):Boolean
        {
         var mousePoint:Point = target.localToGlobal(new Point(target.mouseX,target.mouseY));
         if(target.hitTestPoint(mousePoint.x,mousePoint.y))
         {
          trace("Over ACTIONS Bucket!");
          return true;
         }
         else
         {
          trace("Not over ACTIONS Bucket!");
          return false;
         }
        } // ----------------------------------------------------------------------------------------- -------------------------- End public function detectTarget().
      } // ========================================================================================= ======== End public class PAheader{}.
      } // ========================================================================================= =================== End package{}.