1 Reply Latest reply on Jun 15, 2015 9:32 AM by sinious

    How to make a button to overlay all objects?

    azkianury

      I'm currently making a flash application. In the application, I'm loading an swf file inside a frame. Here's the code:

      stop(); 

      var url1:URLRequest = new URLRequest("Complete The Words Game 1.swf");

      myLoader.load(url1);

      addChild(myLoader);

      myLoader.scaleX = 1.8;

      myLoader.scaleY = 1.8;

      myLoader.x = 190; 

      addChild(backtopractice_button);


      backtopractice_button.x=20;

      backtopractice_button.y=610;

      backtopractice_button.addEventListener (MouseEvent.CLICK, backtopractice);

      And I want to bring the "backtopractice_button" to the very front to overlay everything, even the SWF file too. Is it possible to do this? Thanks.

        • 1. Re: How to make a button to overlay all objects?
          sinious Most Valuable Participant

          You can set the index of any DisplayObject using setChildIndex:

          DisplayObjectContainer - Adobe ActionScript® 3 (AS3 ) API Reference

           

          I'm not sure where "backtopractice_button" is coming from (assuming code you're not posting) but assuming it's added via code (you can't change things on the timeline and I don't think you'd be running addChild() on a timeline object). So find the stage's highest index with .numChildren and set it to that - 1.

           

          Simple all code example of flipping 2 Sprites added (frame script):

           

          import flash.display.Sprite;

           

          var a:Sprite = new Sprite();

          a.name = 'IAm-A'; // set a name so we know which is which

          this.addChild(a); // 'this' is just representing the stage

           

          var b:Sprite = new Sprite();

          b.name = 'IAm-B';

          this.addChild(b);

           

          trace(this.getChildAt(1).name); // IAm-B

           

          // swap

          this.setChildIndex(a, this.numChildren - 1);

           

          trace(this.getChildAt(1).name); // IAm-A

           

          So for you, should be simply:

           

          this.setChildIndex(backtopractice_button, this.numChildren - 1);