3 Replies Latest reply on Dec 16, 2009 2:27 PM by PhilipKeiter

    Display order

    SiHoop Level 1

      The code below places a button on the stage, then places a sprite on top of the entire stage to trap a mouse click.The trouble is that I cannot click on the button because it is coverered by the sprite.

       

      How can I make the button clickable?

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="*"    applicationComplete="init()">
      <mx:Script>
          <![CDATA[
              import flash.display.Sprite;
              import mx.controls.Image;
              private var mouseUpPosition:Number
              private var mouseDownPosition:Number
              private function init():void{
                  var square:Sprite = new Sprite();
                  square.alpha=0
                  square.graphics.beginFill(0xFF0000);
                  square.graphics.drawRect(0,0,100,100);
                  square.graphics.endFill();
                  square.addEventListener(MouseEvent.MOUSE_DOWN, reportMouseDown);
                  square.addEventListener(MouseEvent.MOUSE_UP, reportMouseUp);
                  square.width =stage.stageWidth
                  square.height=stage.stageHeight
                  display.addChild(square);
              }
              private function reportMouseDown(event:MouseEvent):void{
                  mouseDownPosition=event.stageX
                  trace("Down position="+mouseDownPosition)
              }
              private function reportMouseUp(event:MouseEvent):void{
                  mouseUpPosition=event.stageX
                  trace("Up position="+mouseUpPosition)
              }
             
              private function buttonClick():void{       
                  trace("xPos=")
              }
             
          ]]>
      </mx:Script>

       

      <mx:Button  id="button" label="Click"  click="buttonClick()" />  
      <mx:UIComponent id="display" />
      </mx:Application>

        • 1. Re: Display order
          PhilipKeiter Level 2

          SiHoop,

           

          What is it that you are trying to accomplish? You could get a lot of answers to this that work for the hypothetical question, but that wouldn't be the best for what you are practically trying to accomplish. If you can define your true goal, we could tell you the best/right way to get there.

           

          Thanks,

          Philip

          • 2. Re: Display order
            SiHoop Level 1

            I'm doing 2 things: First, I'm trying to understand BitmapData in greater depth. Second, I thought I'd create a screen capture utility that would allow users to drag over a section of an interface and save it as a jpg file. I'm able to get the screen positions of an area of the screen, but I need a button to initiate the action! I thought I'd just create the button using actionscript, to ensure it was above the sprite, but it won't show up!!

            • 3. Re: Display order
              PhilipKeiter Level 2

              SiHoop,

               

              In mxml, components are added in the order they are listed, which means the display list is opposite of the order you listed them. The first item is on the bottom, the next is added over it, the next added over it, etc. Try switching

              <mx:Button  id="button" label="Click"  click="buttonClick()" />  
              <mx:UIComponent id="display" />

              to

              <mx:UIComponent id="display" />

              <mx:Button  id="button" label="Click"  click="buttonClick()" /> 

               

              Thanks,

              Philip