Keep original stage dimensions of loaded swf

Alex500
Alex500 used Ask the Experts™
on
Hi all ive jsut made an image gallery in another swf that I want to load into a website. The problem is when I load the swf in it looses its stage dimensions of 540 x 380, which means all the content that was off the stage is now visible in the document it is loaded into which is much larger 1200 x 800. Ive seen some stuff about masking but due to the way this is developed id like to do it with actionscript. How would i go about keeping the loaded swfs original stage dimensions.  my loader code is posted below. is it not possible to mask it with actionscript?


/*Load in external swf */
				var loadSwf:Loader = new Loader();
				var requestSwf:URLRequest = new URLRequest("photo_gallery.swf");
				loadSwf.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
				loadSwf.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
				

				loadSwf.load(requestSwf);
				
				
				
				/* Add swf to stage */
				function onCompleteHandler (loadEvent:Event) {
					stage.addChild(loadEvent.currentTarget.content);
					
					
					
					
				}
				
				/* Progress tracking*/
				function onProgressHandler(mProgress:ProgressEvent) {
					var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
					trace (percent);
				}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
In the parent .swf, I'd create a sprite that contains a rectangle or other shape that has the desired size, i.e. 540x380.  Then, set the Loader.mask to the new sprite.

Author

Commented:
how would i go about doing this?
There are a couple of options here, you could make the sprite in the Flash IDE, using the rectangle tool(color doesn't matter unless you are going to be blending), and load it into the document class. Or, you could make the rectangle with the flash.geom.rectangle class, and add it to a sprite.  Instead of Loader.mask, you would want to set it to the Loader variable (I apologize for being unclear..) so, loaderSWF.mask = maskingSprite;
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

Here you go
import flash.display.Sprite;

var imask:Sprite=new Sprite();
var canvas:Graphics=imask.graphics;
canvas.lineStyle(0,0xFF0000,1);
canvas.beginFill(0xFF0000,1);
canvas.drawRect(0,0,540,380);
canvas.endFill();
/*Load in external swf */
var loadSwf:Loader = new Loader();
var requestSwf:URLRequest = new URLRequest("photo_gallery.swf");
loadSwf.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
loadSwf.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
loadSwf.load(requestSwf);
/* Add swf to stage */
function onCompleteHandler (loadEvent:Event) {
	stage.addChild(loadEvent.currentTarget.content);
	//mask it to the sprite we created above
	loadEvent.currentTarget.content.mask=imask;
}
/* Progress tracking*/
function onProgressHandler(mProgress:ProgressEvent) {
	var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
	trace (percent);
}

Open in new window

Author

Commented:
Haha thanks for your comments I actually sorted this myself just after posting my last message, but had to get the train home and have only just checked back. I simply just made a mask movieclip and applied it to the loader swf. A combination of what you both suggested in the end, cheers!

Author

Commented:
Great Help

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial