(ActionScript) Change movie clip width with mask
Is there a way to mask a movie clip in a w开发者_StackOverfloway that alters the width and height of the object? I have a child movie clip that is larger in width so I'm having issues manipulating the width, height and coordinates proportionally of the parent movie clip.
I appreciate the help. Thank you.
Colin Moock has a good write-up on the subject here, including a kind of cumbersome way to get the visible width and height instead of the width and height of the content, via a bitmap:
http://www.moock.org/blog/archives/000292.html
I´ve found a simple way in actionscript.
First create a class for the movieclip that will hold the mask and the "item to be masked".
this movieclip must have the same width and the height of the mask in order to manipulate data inside without change the dimensions of the movie.
in order to do that i simply override the width and height of this. Something like this:
public class MyMaskedItem extends MovieClip
{
public var mvMask:MovieClip;
public var mvContent:MovieClip;
public function MyMaskedItem() {
this.mask = mvMask;
}
/**
* Override width and height properties
*/
override public function get width():Number { return this.mvMask.width; }
override public function set width(value:Number):void
{
this.mvMask.width = value;
}
override public function get height():Number { return this.mvMask.height; }
override public function set height(value:Number):void
{
this.mvMask.height = value;
}
}
And now is just add contents to the mvContent movie;
Hope it helps!
It might help to work with the _xscale and _yscale properties of the parent (rather than the _height and _width), since these aren't affected by how big the child object is.
So if your parentClip is 50 wide x 80 high, then to re-size it to 150 x 160 you do
parentClip._xscale=3; parentClip._yscale=2;//still works even after child is added
(This is for AS2, but the code would be something similar for AS3... your question wasn't specific)
You could also grab the dimensions of the mask itself rather than the movieclip.
精彩评论