Masking FLV video in AS3 with PNG alpha channel.

Posted by James Roberts on Stack Overflow See other posts from Stack Overflow or by James Roberts
Published on 2010-05-03T10:43:35Z Indexed on 2010/05/03 10:48 UTC
Read the original article Hit count: 442

Filed under:
|
|
|

Hey there,

I'm trying to mask an FLV with a PNG alpha channel. I'm using BitmapData (from a PNG) but it's not working. Is there anything I'm missing? Cut up code below:

var musclesLoader:Loader = new Loader();
var musclesContainer:Sprite = new Sprite();
var musclesImage:Bitmap = new Bitmap();
var musclesBitmapData:BitmapData;

var musclesVideo:Video = new Video(752, 451.2);
var connection:NetConnection = new NetConnection();
var stream:NetStream;

function loadMuscles():void {
    musclesLoader.load(new URLRequest('img/muscles.png'));
    musclesLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, musclesComplete);
}

function musclesComplete():void {
    musclesBitmapData = new BitmapData(musclesLoader.content.width, musclesLoader.content.height, true, 0x000000);
    musclesImage.bitmapData = musclesBitmapData;
    musclesImage.smoothing = true;
    musclesContainer.addChild(musclesImage);
    contentContainer.addChild(musclesContainer);
}

function loadMusclesVideo():void {
    connection.connect(null);
    stream = new NetStream(connection);
    stream.client = this;
    musclesVideo.mask = musclesBitmapData; 
    stage.addChild(musclesVideo);
    musclesVideo.attachNetStream(stream);
    stream.bufferTime = 1;
    stream.receiveAudio(true);
    stream.receiveVideo(true);
    stream.play("vid/muscles.flv");
}

Outside this code I have a function that adds the containers to the stage, etc and places the objects in the appropriate spots. It sort of works - the mask applies, but in a square (the size of the boundaries of musclesBitmapData) rather than with the shape of the alpha channel.

Is this the right way to go about this?

© Stack Overflow or respective owner

Related posts about as3

Related posts about flash