Skip to main content
Known Participant
October 12, 2006
Question

align external .swf

  • October 12, 2006
  • 6 replies
  • 529 views
I have a main movie. There is a mc container called loader and couple of external animations called anima.swf. I dont know the anima.swf size (width, height), but I know it will always be smaller (width, height) than the loader.

How to write an AS which would align my anima.swf inside the container loader

1) to be on CENTER, MIDDLE
2) to be on CENTER, TOP
3) to be on CENTER, BOTTOM
etc.

thanks for any help
This topic has been closed for replies.

6 replies

gringitoAuthor
Known Participant
October 12, 2006
uuuuy ... thanks a lot ... but - well - I am beginner. this is beyond my brain capacity :))) ... it is too compicated for me to understand. may I ask you to be more SIMPLE? ...
I have the container already on the scene, fixed size 200x200 px.
I load the the external .swf like: loadMovie(nameofthefile, "loader");

what shall come next?
Inspiring
October 12, 2006
Of course it’s possible to do this. What you would need to do is, load the SWF into a movieclip and when its fully loaded you can then retrieve its X Y properties. After you have those 2 values, just do some arithmetic to align it.

So I would recommend to load the SWF using the MovieClipLoader.
http://livedocs.macromedia.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00002543.html

…This link goes to its onLoadComplete (). The code on the bottom of this page uses loadClip() to load the content and the onLoadInit is invoked when the SWF is fully loaded and able to access its properties. Ahh…this example shows exactly what you need! Notice that the onLoadComplete() returns 0 for the loaded _width. You must use the onLoadInit()! This is mentioned in the 3rd paragraph. So once you get a value from this function, do some division to find its center. Let’s say that the SWF has a value of 200 for its _width. Just divide that by 2 (200/2) and that will give you the value to the center vertical axis. Do the same for the _height and that will give you the center horizontal axis. Then with those values, assign the content using _x and _y properties.
gringitoAuthor
Known Participant
October 12, 2006
I managed the easy part of the problem. I load my .swf like:

var mcLoader:MovieClipLoader = new MovieClipLoader();
mcLoader.addListener(loadListener);
mcLoader.loadClip("anima.swf", "loader");

and now I need to add the Listener and get the _width value of "anima.swf". but I dont know how ...

this is the FLASH HELP but how to use it ...

var loadListener:Object = new Object();
loadListener.onLoadComplete = function(target_mc:MovieClip, httpStatus:Number):Void {
trace(">> loadListener.onLoadComplete()");
trace(">> =============================");
trace(">> target_mc._width: " + target_mc._width); // 0
trace(">> httpStatus: " + httpStatus);
}
loadListener.onLoadInit = function(target_mc:MovieClip):Void {
trace(">> loadListener.onLoadInit()");
trace(">> =============================");
trace(">> target_mc._width: " + target_mc._width); // 315
}

the alignment (CENTER, MIDDLE) might work like:

target_mc._y = (loader._width - target_mc._width)/2;
target_mc._x = (loader._height - target_mc._height)/2;

but how to put all this together ? ... any help, uff?




Inspiring
October 13, 2006
The code below will load a SWF file named “ball” and when the onLoadInit is invoked it will invoke a function called alignMovieClip. It is here where you need to do some work.
You want 3 possible alignment settings for this project of yours, center/top, center/middle and center/bottom. Currently the code only has one alignment setting coded in this alignMovieClip function, center/middle. The first line of code is commented out. You can make 2 other lines of code that are similar for the other 2 alignment settings. And then something or someone will make one of those variables true. The conditional statement that is commented out in the alignMovieClip function will choose the correct alignment setting by the variable that is true.
Participating Frequently
October 12, 2006
Your loader movieclip being empty, it will show the content. Just you have to adjust the position accordingly. it won't show the position for empty movie. it will show for the content only.
gringitoAuthor
Known Participant
October 12, 2006
the x,y position and the size of the container stays same all the time. I need to move the "content" - the external .swf ...
Participating Frequently
October 12, 2006
Try this

Each time when you are loading the new swf, you can set the x, y position of
your mc-container loader.
Inspiring
October 12, 2006
Typically your container would be an empty clip. And it being 0 x 0 in size,
there is no center, or top or bottom. Loaded movies come into the container
at 0,0. If you want to align the loaded clip to the Stage, or to another
clip, then your best bet is to use the MovieClipLoader class and its
associated onLoadInit method to move the loaded clip once it's ready.

--
Dave -
Adobe Community Expert
www.blurredistinction.com
http://www.adobe.com/communities/experts/