# Mask doesn't work all the time

**URL:** https://forum.kirupa.com/t/mask-doesnt-work-all-the-time/279025
**Category:** Uncategorized
**Created:** [January 8, 2009, 5:53pm UTC](https://forum.kirupa.com/t/mask-doesnt-work-all-the-time/279025 "2009-01-08T17:53:28Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![christinelalala](https://avatars.discourse-cdn.com/v4/letter/c/90ced4/32.png) [@christinelalala](https://forum.kirupa.com/u/christinelalala)
#### Post date: [January 8, 2009, 5:53pm UTC](https://forum.kirupa.com/t/mask-doesnt-work-all-the-time/279025/1 "2009-01-08T17:53:28Z")

</div>

Hi,

I have encountered this weird problem that my mask sometimes work and sometimes  
doesn’t. I’m using an animated movieclip, then cache as bitmap. I tried a lot of ways to  
see what’s wrong, but I still couldn’t find out the problem. Here’s my code, thanks 🙂

I’ll talk a little bit about my code,

I added a loader to the stage

```auto
        addChild(animcontent2);
        maskfunc1(animcontent2);

```

After loaded, the mask is triggered. The thing is that I have a button that reloads the loader  
every time when someone clicks on it, but the mask doesn’t show every time, it seems pretty  
random…

```auto

        private function maskfunc1(aa):void {
            aa.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
            aa.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
     
        }
        
        private function loadProgress(e:ProgressEvent):void {
            var percent:Number = e.bytesLoaded/e.bytesTotal;
            per.visible = true;
            per.text = Math.ceil(percent * 100).toString();
            
        }
        
        private function loadComplete(e:Event):void {
            per.visible = false;
            mask1.gotoAndPlay(1);
            mask1.cacheAsBitmap = true;
            e.target.loader.cacheAsBitmap = true;
            e.target.loader.mask=mask1;
        }

```

thanks again!
