• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

bitmap as mask

New Here ,
Aug 06, 2012 Aug 06, 2012

Copy link to clipboard

Copied

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.

TOPICS
ActionScript

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 06, 2012 Aug 06, 2012

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines