Skip to main content
Participant
March 8, 2008
Question

Container Help

  • March 8, 2008
  • 2 replies
  • 491 views
Hi all.

Beware, I'm very new still to AS3, AS ing general really.

Let's say I want to animate a spider using tweens. I have a movie clip for each part, body, eyes, legs. Coming from a 3D background, I would group the components or use constraints to hold them all together, so that when I move the body, the rest will follow. I can then use tweens to make the legs and eyes rotate randomly.

However, I have no idea how to do this in AS3. I thought I could use Containers, but can't figure that out. I thought I would be able to simply state that spiderEye.y = spiderBody.y; but that seems to only kind of work (the eye follows, but is always one tween behind!).

Any help on how I could make one movieclip follow another, whilst using the caurina tween library, would really help me out (and stop me drinking so much coffee, therefore increasing my chance of living longer!).

Take care, Andrew.
This topic has been closed for replies.

2 replies

somascope
Inspiring
March 8, 2008
I won't have a full answer for you here, Andrew, but I would suggest that you may want to limit your scope of movement to one object - your spider.

To do that, you should nest all your legs, eyes, etc. inside of a movie clip symbol that you create in Flash. All your parts, too, should be movie cliup symbols (then give them instance names so you can access them to affect x, y, scale, alpha, etc). The movieclip symbol for you should be a manually created object in the Flash program, versus other ways of doing things that are completely code-based. This is that same as the "container" you mention. (movieclips and sprites are the main DisplayObject containers in AS3 that can hold other items within them).

Your movieclips' instance names could be:
spider
(and then the instance names of items inside the spider symbol)
- leg1, leg2, leg3, etc.
- eyeLeft, eyeRight

Then, in a basic sense, with the spider on the stage you can set a couple basic things:
spider.y = 200;
spider.eyeLeft.rotation = 45;

But, you also have to deal with bringing your spider onto the stage if it isn't already. Start with getting familiar with creating the physical art, converting that to movieclip symbols, nesting them inside a "container" spider, and then look into how you bring things onto the stage and move them with AS3.
Inspiring
March 8, 2008
You can group several movie clips into one container by selecting them all on the stage and choosing Modify - Convert to Symbol, then use the caurina tweener class with the nested movie clips from the main timeline. So for instance if you have a movieclip container called spider_mc which contains another movie clip called eyes_mc, you can tween it's alpha like this from the timeline:

Tweener.addTween(spider_mc.eyes_mc, {alpha:1, time:1});




Participant
March 8, 2008
Aah, this makes more sense. :) I always look at things the tricky way, and it always turns out that the simple way works! I now have an animating spider. It's odd that using AS I can make complex things work, but simple things like this my brain can never figure it out. :)

Thanks for the help.

A.
Participant
March 9, 2008
Hello, one more question regarding this.

If I have a box, Box1 for example. In this movieclip I also have box2. Let's say I want to move the y position of box 2 with a tween, whilst box 1 is moving with a tween. So, box 2's Y position should equal box 1's plus 25 pixels say. If I do this, it snaps to an odd place at the start of the tween, then performs the 25 pixel move.

Did that make any sense at all?

A.