3 Replies Latest reply on Jan 31, 2011 2:03 PM by beno12345

    Mask Not Working

    beno12345

      Hi;

      I have the following code:

       

              var mask_container:Sprite = new Sprite();
              var square:Sprite = new Sprite();
              var thermometerMask:Images = new Images();

              // "Images" is imported and works. Explain further later

      ...

              private function init(e:Event)
              {
                  addChild(mask_container);
                  mask_container.addChild(thermometerMask);
                  addChild(square);
                  AddText();
      ...

              private function AddThermometerMask():void
              {
                  thermometerMask.ImagesArray = ["images/thermometer-mask.png", "index.py", 144, 1152, (stage.stageWidth-144)/2, 23];
                  AddRed();
              }
             
              private function AddRed():void
              {
                  square.mask = mask_container;
                  square.graphics.beginFill(0xff0000);
                  square.graphics.moveTo(0,0);
                  square.graphics.lineTo(75,0);
                  square.graphics.lineTo(75,504);
                  square.graphics.lineTo(0,504);
                  square.graphics.endFill();
                  square.x = (stage.stageWidth-74)/2;
                  square.y = ((stage.stageHeight+458)/2)-83;
              }

       

       

      The problem is that the mask isn't applied. Now, if I just add mask_container it adds to the stage just fine. If I mask mask_container with square, it masks just fine. They're both Sprites so both are on the display list. What gives?

      TIA,

      Beno

        • 1. Re: Mask Not Working
          Ned Murphy Adobe Community Professional & MVP

          MAybe it has something t do with whatever goes on in your Images class.

          • 2. Re: Mask Not Working
            beno12345 Level 1

            I would have thought anything I put in a sprite would be fine since it's part of the display list. And the image does show up when added as a child and not as a mask. Here's the code for that class:

             

            package  {
                import flash.display.MovieClip;
                import flash.display.Sprite;
                import flash.display.Bitmap;
                import flash.display.BitmapData;
                import flash.filters.*;
                import flash.filters.BitmapFilterQuality;
                import flash.net.URLRequest;
                import flash.net.URLLoader;
                import flash.display.Loader;
                import flash.display.LoaderInfo;
                import flash.display.DisplayObject;
                import flash.events.Event;
                import flash.events.IOErrorEvent;
               
                public class Images extends MovieClip
                {
                    private var parent_container:Sprite = new Sprite();
                    private var _path:String = new String("path");
                    private var _myWidth:Number = new Number(20);
                    private var _myHeight:Number = new Number(20);
                    private var _myX:Number = new Number(20);
                    private var _myY:Number = new Number(20);
                    private var _myURL:String = new String("url");

             

                    public function Images():void
                    {
                    }
                   
                    public function set ImagesArray(_imagesArray:Array):void
                    {
                        _path = _imagesArray[0];
                        _myURL = _imagesArray[1];
                        _myWidth = _imagesArray[2];
                        _myHeight = _imagesArray[3];
                        _myX = _imagesArray[4];
                        _myY = _imagesArray[5];
                        LoadImage();
                    }
                   
                    function LoadImage():void
                    {
                        parent_container = new Sprite();
                        addChild(parent_container)
                        var req:URLRequest = new URLRequest(_path);
                        var loader:Loader = new Loader();
                        loader.load(req);
                        loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);         
                        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, LoadedImage);
                    }

             

                    function LoadedImage(e:Event):void
                    {
                        var loaderInfo:LoaderInfo = e.target as LoaderInfo;
                        var displayObject:DisplayObject = loaderInfo.content;
                        displayObject.width = _myWidth;
                        displayObject.height = _myHeight;
                        parent_container.addChild(displayObject);
                        parent_container.x = _myX;
                        parent_container.y = _myY;
                    }
                   
                    function ioErrorHandler(event:IOErrorEvent):void {
                        trace("ioErrorHandler: " + event);
                    }
                }
            }

             

            Any ideas?

            TIA,

            Beno

            • 3. Re: Mask Not Working
              beno12345 Level 1

              Never mind. I found a way to work around this without masking.

              Thanks,

              Beno