Skip navigation.
Home

Mask issues with ActionScript 3

While working on the homepage for portfolio.baizman.net (a website to showcase my work for a graduate school application), I ran into a bit of trouble with ActionScript masks.

I was trying to create a series of Sprites that held photos, and then assign another Sprite as a mask to crop out some of the unnecessary parts of the photos. The pseudo-code looked like this:

maskSprite:Sprite = new Sprite ( ) ;
// code to create a square
photoSprites:Array = new Array ( ) ;

for ( i = 0 ; i < photos.length ; i++ )
{
photoSprites[i] = new Sprite ( ) ;
// code to load image and insert image into photoSprites[i]
photoSprites[i].mask = maskSprite ;
}

Programmatically, this makes sense. But apparently this doesn't work. The maskSprite will only be applied to the last item in the photoSprites array. The way to fix this is to create a mask for every photo. Caveat emptor!

see more related to: