[thelist] Laying out components in Flash

joe stowaway at uklinux.net
Tue May 18 17:21:23 CDT 2004


Marcus Andersson wrote:

>
> So if I, in some way, attaches a movie clip to a parent movie clip 
> with actionscript (haven't figured out how to do that), then the child 
> movie clip will be positioned relative to the parent movie clip?
>
> /Marcus
>
yes.  imagine you have an empty movie clip called myContainer positioned 
at 0,0.  something I have in every movie I make cos it's so useful.  
(although you're a noob, I assume you understand instances and instance 
names since you're walking xml trees :) )

to attach another movie clip to that container, you have to export it 
for actionscript first (right click on your movie clip in the library 
and go to "Linkage", check the box saying "Export for actionscript", and 
give it a name - for example "myClip"). 

Then you use attachMovie thus:

clipOne = myContainer.attachMovie("myClip", "instance1", 1);     // see 
Flash help on attachMovie for what these params mean
clipTwo = myContainer.attachMovie("myClip", "instance2", 2);

this has just created two different instances of your library item, and 
they both sit at 0,0.

move the second one relative to the first thus:

clipTwo._x = clipOne._x + clipOne._width + 5;     // (for example)

move them all (by moving the container) thus:

myContainer._x = 200;
myContainer._y = 200;

The point is that myClip (and anything else _in your library_, such as a 
component which has been created for use with the createClassObject 
method, for example) has already been "designed", which means that it 
has got dimensions and a position relative to its own registration point. 

Its probably useful to remember Flash evolved from being a graphical 
tool, and acquired OO functionality, rather than vice versa...

> ps. thanks for the comments. I may seem unthankful with the responses 
> but I'm not. Remember I'm a noob

no sweat - hope I'm helping ;D

joe



More information about the thelist mailing list