PDA

View Full Version : Masking out off-stage content of loaded .swf?



Finne
August 28th, 2009, 08:51 PM
I'm just starting out with AS3 and this is what I'm trying to do:

1. I have an external .swf banner which is 900x250 pixels
2. I want to load this .swf into my main project, using this code:

var myLoader:Loader = new Loader();
addChild(myLoader);
var myRequest:URLRequest = new URLRequest("ptp.swf");
myLoader.load(myRequest);

3. The problem is that the .swf banner that is being loaded has content 'outside the stage' so instead of just showing the 900x250 area I see all the off-stage content as well.

How do I 'mask out' the off-stage content of the loaded .swf so that it will be only the 900x250 that I want?

Thanks in advance!!

dail
August 29th, 2009, 05:34 AM
Put the content of the loaded swf into a mask?

MurtenSaerbi
August 29th, 2009, 05:47 AM
There are two solutions for this, both involving masks:

1. Place a 900*250 mask in the banner swf (ptp.swf) so the off-stage content is not visible. The mask will offcourse still work when you load the whole thing in your main project and therefore the off-stage content will not be visible.

2. When you load the banner swf (ptp.swf) and it gets placed (in the complete handler) draw a rectangle shape the size of your banner and set it as a mask.



var rectangle:Shape = new Shape();
rectangle.graphics.beginFill(0x555555); //whatever color, doesn't matter for a mask.
rectangle.graphics.drawRect(X_POS_OF_LOADED_BANNER , Y_POS_OF_LOADED_BANNER, 900, 250);
rectangle.graphics.endFill();
addChild(rectangle);

YOUR_LOADED_SWF_NAME_HERE.mask = rectangle;