开发者

Problems with dimensions of swf when loaded into fla

I am creating a portfolio website for myself and want to embed a swf that is a simple flash game into my main flash file. My problem is that when I use this code to put the swf into my main flash file it doesn't keep the proper swf dimensions and shows things that are outside of the stage. I can't seem to figure it out! Any help is much appreciated! Thanks.

Here's my code.(I'm using Flash CS3 with AS3.)开发者_如何学JAVA

var my_Loader:Loader = new Loader();

var my_url:URLRequest=new URLRequest("piggybankgame.swf");

my_Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, finishLoading);
my_Loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);

my_Loader.load(my_url);

function finishLoading(loadEvent:Event) {
    addChild(loadEvent.currentTarget.content);
}


If I'm understanding you correctly, this has to do with the way that the flash game SWF was created. Most probably, it's built without caring about what goes on outside of the stage boundaries.

A common misconception is that the rectangle defined by the SWF width and height is a crop boundary. It is not. Any content that extends beyond this border will be visible, if the window that displays the SWF is large enough to show it. This also happens when resizing a standalone Flash Player window in your operating system, or when embedding a SWF into a HTML page with width and height set to greater values than what was defined in the SWF (e.g. when publishing from Flash CS3/CS4.)

If you want to load content like a game, into a SWF with larger dimensions, and only show that part of the game SWF that is within it's stage dimensions, you will need to mask it.

var loader : Loader = new Loader();
loader.load(new URLRequest('my320x240game.swf'));

var gameMask : Shape = new Shape;
gameMask.graphics.beginFill(0xffcc00);
gameMask.graphics.drawRect(0, 0, 320, 240);

loader.mask = gameMask;
this.addChild(loader);

This will create a vector shape (a 320x240 rectangle) that acts as a cropping mask for the loader display object. If you are familiar with masks, it's hopefully ease to see how this means that anything extending outside of the 320x240 rectangle will be made invisible.

There are nicer ways to arrange the code of course, but this will hopefully get you going in the right direction.


I think you can just add the Loader to the parent display object. For Example,

var gameSwf:Loader = new Loader();
gameSwf.load(new URLRequest("piggybankgame.swf"));
gameSwf.x = 100;
gameSwf.y = 100;
gameSwf.width = 320;
gameSwf.height = 200;
//Maybe make it visible of something     
gameSwf.contentLoaderInfo.addEventListener(Event.COMPLETE, gameLoaded);
gameSwf.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
addChild(gameSwf);

I know for a fact that this works in Flex 3 with the SWFLoader class, which is the Flex equivalent I believe.


After the loading of your swf you have to set it's size to what you want =>

function finishLoading(loadEvent:Event) {
 var dob:DisplayObject= loadEvent.currentTarget as DisplayObject;
 // or
 // var dob:Loader = loadEvent.currentTarget as Loader;
 addChild(dob);
 dob.width=myWidth;
 dob.height=myHeight; 
}

Of course the swf you are loading can doing what it wants with the width and the height you are passing.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜