透過グラデーションマスク
透過グラデーションマスクのサンプル&備忘録。
マスク用Spriteが無駄にドラッグ&ドロップできます。
下のソースにポイントを書いたけど、ポイント1ばかりを気にして、
ポイント2をおろそかにしていたため、ちょっとハマりました。
package{ import flash.display.DisplayObjectContainer; import flash.display.Sprite; import flash.display.GradientType; import flash.geom.Matrix; import flash.events.MouseEvent; public class alphaGra extends Sprite{ var wm:WmIconSym; //画像シンボル var maskObj:Sprite; //マスク用Sprite public function alphaGra(timeline:DisplayObjectContainer){ timeline.addChild(this); //インスタンス生成 wm = new WmIconSym(); maskObj = new Sprite(); //画像シンボルの位置調整 wm.x = 65; //マスク用透過グラデーションの描画 var mtr:Matrix = new Matrix(); mtr.createGradientBox(this.stage.stageWidth, this.stage.stageHeight, -Math.PI/2); maskObj.graphics.beginGradientFill(GradientType.LINEAR, [0,1], [0,1], [0,255], mtr); maskObj.graphics.drawRect(0, 0, this.stage.stageWidth, this.stage.stageHeight); maskObj.graphics.endFill(); //【ポイント1】画像とマスク用SpriteのcacheAsBitmapをtrueにする wm.cacheAsBitmap = true; maskObj.cacheAsBitmap = true; //【ポイント2】画像とマスク用Spriteを同じMovieClipにaddChildする this.addChild(wm); this.addChild(maskObj); //マスク wm.mask = maskObj; this.addEventListener(MouseEvent.MOUSE_DOWN, onMDown); this.addEventListener(MouseEvent.MOUSE_UP, onMUp); } function onMDown(event:MouseEvent):void{ maskObj.startDrag(); } function onMUp(event:MouseEvent):void{ maskObj.stopDrag(); } } }