Putting a movieclip as child for another movieclip - actionscript-3

So I have the MovieClip mc1 which added to the stage (addChild) is put on top of all the layers. I actually need another movieclip to be on top of all the scene so I've created an empty movieclip with the instance name fbp, that is set on the appropriate layer, in which I want to put my mc1 movieclip. How can I get that fbp movieclip and then add mc1 as child?

fbp.addChild(mc1). However, you might need to make a Sprite instead of MovieClip for fbp. Not sure if it works for movieclips.

Related

Is there any way to add a child movieclip on nth frame of a parent movieclip

There are two movieclips on stage
mc1 and mc2
mc1 right now has say 10 frames total.
mc2 needs to be added on say 3rd frame of mc1.
I used the following, but it adds the child movieclip on every frame, instead of 3rd only.
mc1.addFrameScript(3-1,frameFunction);
mc1.play();
function frameFunction():void
{
mc1.addChild (mc2);
}
MovieClips only have a single display list, so once you add a child, it will remain there until you remove it. That being said, you can possibly accomplish what you are attempting by adding a second frame script on a later frame to remove the child from the display list:
mc1.addFrameScript(2, addClip);
mc1.addFrameScript(6, removeClip); // you'll want to change this frame number
mc1.play();
function addClip():void
{
mc1.addChild(mc2);
}
function removeClip():void
{
mc1.removeChild(mc2);
}

exception, information=ReferenceError: Error #1056: Cannot create property ground on Main. (FLASH As3)

I have a deep problem which I have encountered.
I am adding a movie clip inside to another movie clip and flash doesn't like this.
What I'm doing is dynamically adding a movieclip to a movieclip that hasn't been added dynamically.
movieclip 1
private var tim:player = new player();
//inside main
tim.addChild(ground);
now ground is an instance name that hasn't been added via code. It's on the stage in flash and it's a movievlip with the instance name ground.
What can I do to fix this please.
Basically I wasn't really understanding As3,
From reading As3 101 - Display Lists I was able to understand that all things like sprites, shapes and movieclips are added to a display list.
In order to have added tim to a parent, that parent would have to be present.
This means that the parent would need to be added to the display list.
addChild(container);
You can see that container is now part of the display list.
This means I can now:
container.addChild(character);
Add the character to the container, and this now becomes a display object container
I can now trace what's in the container.
trace(container.numChildren);
In this container there are 3 childrens, my ground, the player and the enemy :D

Bring Timeline animation to top

I have a movie that adds a MovieClip to it's stage in the constructor, i Also have an animation on the timeline that plays on certain events. Everything is working, except the movie I need the movie on the timeline to be the top layer, it is on the bottom currently.
public Class BallCollision extends MovieClip{
public function BallCollision(){
mcBall = new MovieClip();
stage.addChild(mcBall);
//Adds stuff to the movie clip
}
}
You can do one of the following:
Create a container on the timeline called 'container' and then add mcBall to that instead. This container will be on a layer underneath the existing animation.
Place all of the existing animation into a MovieClip and give it an instance name like animation. Whenever you add something to the stage, also use stage.addChild(animation) to bring it back to the top.
Obviously option 1 is preferable, but I've offered option 2 for the sake of free knowledge.

Dynamically adding tween to n MC's

Here's what I'm aiming for. I'm querying the Rotten Tomatoes API for Upcoming Movies. For each movie returned, I'm creating an instance of MovieIcon (MC). I'm then adding this MC as a child of a Container MovieClip that's already on the scene. Each time, I'm incrementing the xPosition of each MovieIcon MC such that, they're positioned next to each other.
My container MC has a mask applied to it, therefore any child objects that are positioned beyond the size of the mask, they're are hidden from view.
How can I dynamically add a tween/easing animation between all these MovieIcon MC's so that when I hover over the Container MC, it 'scrolls' left or right, depending on the mouse motion?
Thanks in advance.
First I would recommend using a tweening library.
TweenLite and Tweener are good options
http://www.greensock.com/tweenlite/
http://code.google.com/p/tweener/
Both of these include docs that will help you get everything set up in your project.
Then you should be able to add a ROLL_OVER event to each of your MovieIcon MC's
MovieIcon.addEventListener(MouseEvent.ROLL_OVER, handleRollOver);
Inside your handler you can use the event.target property to get a handle on the over MovieIcon.
Assuming your using TweenLite you can go and add your tween to that target
private function handleRollOver(e:MouseEvent):void{
TweenLite.to(e.target, duration, {x: new x value, any other prop: any other val})
}

Moving a child MC to stage but remaining its animation

Is it possible to remain an on going animation on a child MC while moving the MC to the stage (same level as its parents)
If by using removeChild and addChild again the animation will not be consistancy.
You don't need to removeChild/addChild if you're just changing parents. Just calling addChild on a child that already has a parent, will re-parent the child automatically.
I haven't tested your exact problem. But if the MovieClip stops playing when you call addChild, you could just store the current frame and then resume playing from that frame after you've called addChild. Like this:
var frameNumber : int = myMovieClip.currentFrame;
newParent.addChild(myMovieClip);
myMovieClip.gotoAndPlay(frameNumber);