Why (root as MovieClip).this["mc"+i] doesnt work? - actionscript-3

How can I control 3 movie clips from another mc dynamically?
My 3 clips are mc1, mc2 and mc3. What is wrong with the codes given below?
for(i=1;i<=3;i++){
(root as MovieClip).this["mc"+i];
}

Child is not a property of his parent, you can use (root as MovieClip).get ChildByName('mc'+i).

Related

How to remove a Movie clip from with-init self

Ok am trying to remove a movie clip from inside its self. I basically telling a button to play a clip, and at the end of the clip I want it to remove the movie clip. I have tried a few different lines of code but telling me it "1120: Access of undefined property Navi_MC"
root.Main_stage.removeChild(Navi_MC);
also
this.Main_stage.removeChild(Navi_MC);
Sorry forgot to add the layers are Object(root).Main_stage.Navi_MC
if (this.parent) { this.parent.removeChild(this); }
Should work.

How to insert/place a movie clip from the library in a specific layer (z-order) in AS3?

I haven't found anything about this and it's really intriguing me. Here's an example:
var example1:example1_mc = new example1_mc();
addChild(example1);
It comes on top of all layers in my scene and I wanted to assign it to the back.
To put an item at the back most z-index of it's parent, do the following:
addChildAt(example1,0);
//the second parameter is the z-index to put the child at
//0 is the back, parent.numChildren-1 is the front most
//so this:
addChild(example1);
//is the same as this:
addChildAt(example1, numChildren-1);
addChild always places the child at the front.
To change the position of an item later, you can either addChild/addChildAt again, or use setChildIndex(example1,0).
So this:
addChildAt(example1,0); //add it to the back
setChildIndex(example1,2); //move it above the next 2 items
is the exact* same as this:
addChildAt(example1,0);
addChildAt(example1,2); //since example1 is already added, this just moves it above the next 2 items in the parent (it doesn't add a copy)
addChild will dispatch an Event.ADDED event on the item you added the child to. setChildIndex will not result in that event being dispatched.

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

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);