开发者

How to replace a movie a movie in flash - dress up game

I have a flash movie instance name "headArea" I want to load a external swf and swop the movie inside the headArea - replacing the开发者_C百科 head.

I have the following code:

clickIt.addEventListener(MouseEvent.MOUSE_DOWN, swopHead);
function swopHead(event:MouseEvent):void {
    var loadit = new Loader();
    headArea.addChild(loadit);
    loadit.load(new URLRequest("head2.swf"));
}

Problem is that the new swf is not being loaded exactly within the headArea and seems the registration may be off - even though all the reg points are set to centre.

Is this the best way yo do this?


THe loader gets positioned at 0,0 so it would look like upper left registration. To properly center it you probably have to do something like this:

loadit.contentLoaderInfo.addEventListener(Event.COMPLETE, onHeadLoaded);
function onHeadLoaded(evt:Event):void{
  loadit.x = -loadit.width/2;
  loadit.y = -loadit.height/2;
}

It's important the you do negative half the width and negative half the height so that the head moves up and to the left rather than down and to the right.

This has to be done on the Event.COMPLETE handler because the loader will not have a size until its fully loaded into your flash movie.


Registration for loaded movie clips is always top left I believe, causing your center to be off. Maybe you should reposition the clip once it has been loaded (width/2 - height/2)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜