Skip to main content
Participant
August 6, 2012
Question

bitmap as mask

  • August 6, 2012
  • 1 reply
  • 1238 views

I have a few imported images in my library I'd like to use as a mask to fit over a video but I can't get it to work. Here's how it works so far. The imported image is a photoshop .psd with some transparent layers.

import flash.display.Sprite;

import flash.media.Video;

import flash.display.MovieClip;

public class Main extends Sprite {

public function Main() {

     private var video:Video = new Video();

     private var dot:MovieClip = new Symbol1();

    

    

     video.width = 160;

     video.height = 90;

 

     video.x = 443; //Video position

     video.y = 190;

     addChild(video); //Add video to stage

    

     dot.x = video.x;

     dot.y = video.y;

     addChild(dot);

 

     video.mask = dot;

}

}

This doesn't work. The video just gets masked by the whole image, and not the shape with the trasparent layer.

So I figure I'd have to convert the psd to a bitmap, cause it sounds like you can only use bitmaps. So I just draged the psd image into flash to get a bitmapdata file in my library. But it still doesn't work. Here's the new code:

private var dot:BitmapData = new Bitmap6;

public function main {

          video.x = 443; //Video position

                                        video.y = 190;

                                        addChild(video); //Add video to stage

 

                                        dot.x = video.x;

                                        dot.y = video.y;

                                        addChild(dot);

 

                                        video.mask = dot;

}

but now I get these compiler errors:


1119: Access of possibly undefined property x through a reference with static type flash.display:BitmapData.

1119: Access of possibly undefined property y through a reference with static type flash.display:BitmapData.

1067: Implicit coercion of a value of type flash.display:BitmapData to an unrelated type flash.display:DisplayObject.

1067: Implicit coercion of a value of type flash.display:BitmapData to an unrelated type flash.display:DisplayObject.

So now I'm not sure what to do. Can anybody help me out?

Thanks, if anyone can help.

This topic has been closed for replies.

1 reply

Participant
August 6, 2012

Nevermind, totally figured it out on my own. The image needs to be imported as a png or as a bitmap. Then:

public class Main extends Sprite {

public function Main() {

     private var video:Video = new Video();

     private var dot:BitmapData = new Symbol1();

     private var mymask:Bitmap = new Bitmap(dot);

   

     video.width = 160;

     video.height = 90;

     video.x = 443; //Video position

     video.y = 190;

     addChild(video); //Add video to stage

  

            video.cacheAsBitmap = true;  // this is pretty important

            mymask.cacheAsBitmap = true;

     mymask.x = video.x;

     mymask.y = video.y;

     addChild(mymask);

     video.mask = mymask;

}

}

Well... thanks anyway to anyone.