开发者

Actionscript Movieclip fade

I'm struggling with something rather simple in flash at the moment.

Imagine you have two movieclips ontop of eachother. Both of these movieclips have identical movieclips within them.

If I fade out the top movieclip I expect to see no change at all, but for some reason I can see the fade happen.

It's like actionscript is fading out the sub movieclips independently.

Anyone know how to get around this? I don't want to be able to see any fade at all.

Edit:

People seem to be having trouble visualising what I'm having trouble with. Here's a really simple example in code:

var format:TextFormat = new TextFormat();
format.size = 100;
format.color = 0xFFFFFF;

// create a red square with text inside
var x:MovieClip = new MovieClip();
x.graphics.beginFill(0xCC0000);
x.graphics.drawRect(0, 0, 400, 400);
x.graphics.endFill();
var x_txt:TextField = new TextField();
x_txt.text = "hello";
x_txt.width = 500;
x_txt.setTextFormat(format);
x.addChild(x_txt);
addChild(x);


// create a red square with text inside
var y:MovieClip = new MovieClip();
y.graphics.beginFill(0xCC0000);
y.graphics.drawRect(0, 0, 400, 400);
y.graphics.endFill();
var y_txt:TextField = new TextField();
y_txt.text = "hello";
y_txt.width = 500;
y_txt.setTextFormat(format);
y.addChild(y_txt);
addChild(y);

y.alpha = 0.5;

As far as I can tell, it makes no sense that the text displayed should not be pure white.

Instead, it comes out as a faded white. http://www.mikeefranklin.co.uk/Test2.swf

Edit 2:

I've decided to grab the bitmap data and add that instead. it's not ideal, but does what I was looking for.

var format:TextFormat = new TextFormat();
format.size = 100;
format.color = 0xFFFFFF;


// create a red square w开发者_如何学Pythonith text inside
var x:MovieClip = new MovieClip();
x.graphics.beginFill(0xCC0000);
x.graphics.drawRect(0, 0, 400, 400);
x.graphics.endFill();
var x_txt:TextField = new TextField();
x_txt.text = "hello";
x_txt.width = 500;
x_txt.setTextFormat(format);
x.addChild(x_txt);


var xbmpd:BitmapData = new BitmapData(x.width, x.height);
xbmpd.draw(x);
addChild(new Bitmap(xbmpd));


// create a red square with text inside
var y:MovieClip = new MovieClip();
y.graphics.beginFill(0xCC0000);
y.graphics.drawRect(0, 0, 400, 400);
y.graphics.endFill();
var y_txt:TextField = new TextField();
y_txt.text = "hello";
y_txt.width = 500;
y_txt.setTextFormat(format);

y.addChild(y_txt);

var ybmpd:BitmapData = new BitmapData(y.width, y.height);
ybmpd.draw(y);
addChild(new Bitmap(ybmpd));


y.alpha = 0.5;

Edit 3:

Setting blendMode to BlendMode.Layer seems to do the job instead, which is nice.


If you were only looking to have that top movie clip fade without the transparency layering on top of the bottom movieclip, you could just change the blendMode to Overlay before you apply the alpha.

y.blendMode = BlendMode.OVERLAY;
y.alpha = 0.5;

Nevermind, seems like you found it xD


The Problem is that there are two objects in the MovieClip. You have to understand how flash handles alpha transparency for MCs. Each child of y has the aplha of 0.5. wich means you will see a little red through the hello of y. and that red is covering the hello of x.

you could set the visibility of the red shape in y to false. then you will not see the fade.


Are you creating two seperate movieclips or using the same reference twice? A movieclip can only have one parent, so if you do like this:

container.addChild(mc); container.addChild(mc);

Only one movieclip will exist. That could explain why you see a fading, because there is no movieclip behind the movieclip you are fading.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜