Flash/ActionScript: How to center smaller swf when

2019-08-30 18:32发布

问题:

I am making an interactive storybook project given these specifications:

My book has 13 pages, where 1 page = 1 swf loaded externally into the book swf. As you can see, the page swf must be centered in between the 2 buttons that are both 100x450 each. Whenever I try to load the swf, usually it's cut off at some point.

In short, how do I center my externally swf when loaded?

回答1:

Make the completeHandler Function like given bellow

function completeHandler(event:Event):void{         
    this.container.addChild(event.target.content);
    this.container.x = this.stage.stageWidth/2 - event.target.width /2;
    this.container.y = this.stage.stageHeight/2 - event.target.height /2;           
}

U can change this.stage.stageWidth with the center container width and apply same for width also



回答2:

The advice gyandas gives is good. However, from the way you've worded your question I'm guessing you're already doing something along the lines of what he suggests. If so, you could try adding a filled shape of 520x450 as the background of each of your pages. You can set the alpha to 0 or match the background color of the book itself, but the important thing is to have some actual content of the required dimensions rather than relying on the supposed width of the SWF when centering it in another movie.

I'm not in a position to test this right now, but I seem to recall that the dimensions of a loaded SWF are calculated according to the bounding box created around actual content, and that I have resorted to doing this as a result.