• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Actions in a nested mc

Community Beginner ,
Nov 29, 2017 Nov 29, 2017

Copy link to clipboard

Copied

Hello again.

I'm trying to do actions with movieclips that are nested inside another.

I'm calling them dynamically with a for, something like this:

root = this;

for (i = 1; i <= 12; i ++) {

root ["mcP_" + i] .visible = false;

};

This code works, but when the movieclips are nested, it does not find them anymore.

for (i = 1; i <= 12; i ++) {

root.anotherMovieClip ["mcP_" + i] .visible = false;

};

Surely I am executing incorrectly the call to the objects, I wish they could tell me what is the correct way to execute this.

Thanks for your support.

Greetings.

Views

254

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 29, 2017 Nov 29, 2017

Copy link to clipboard

Copied

if your path/name were correct that would work.  ie, if this.anotherMovieClip.mcP_1 etc were correct, your code would work.

use the trace function to see if any if the first references is incorrect or the failure occurs after mcP_1.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 29, 2017 Nov 29, 2017

Copy link to clipboard

Copied

I can't get it to fail. One thing to watch out for, assuming this is HTML5 Canvas, because you're not saying this.root = this; or var root = this;, 'root' is a window variable, and if anything else going on makes a change to the same variable name, it could mess things up.

Same for 'I'. Now, it could be you're doing that already, and the code you showed was just an example written while you were posting. So, if it's not working I would check that the outer movieclip and the inner movieclips have the names you think they should have.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 29, 2017 Nov 29, 2017

Copy link to clipboard

Copied

Make sure you're waiting a frame or two for all the nested movieclips to initialize.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 29, 2017 Nov 29, 2017

Copy link to clipboard

Copied

Thanks for the answers. Really thank you very much. I commented:

The file is made for html. The code I'm picking up from a file I did before is this:

var root = this;

for (i = 1; i <= 12; i ++) {

     root ["mcP_" + i] .visible = false;

};

In this file the mcP_1, mcP_2 ... mcP_12 are at the same level as the action frame. This is your instace name.

In the file I am currently doing I am trying to reuse the code, only that in this case the mcP are nested movies inside another. We will call this movieclip map (instance name).

for (i = 1; i <= 12; i ++) {

     root.mapa ["mcP_" + i] .visible = false;

};

When I execute it, it does not work. The message in the console is: Can not set property 'visible' of undefined, so I think it is not enough to retrieve the instance name of the movieclip.

If I take it out of the for and I put it one by one, if it works.

root.mapa.mcP_1.visible = false;

root.mapa.mcP_2.visible = false;

root.mapa.mcP_3.visible = false;

.

.

.

root.mapa.mcP_12.visible = false;

I have already reviewed the instance names and they are correct.

Probably with this information you can help me.

Thanks for the support.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 29, 2017 Nov 29, 2017

Copy link to clipboard

Copied

those movieclips don't exist when your code executes.  put that code in a function:

var root=this;

function intiF(){

for (i = 1; i <= 12; i ++) {

     root.mapa ["mcP_" + i] .visible = false;

};

}

// and on a frame where the mcP exist, put

this.parent.initF();

// if that fails, use a ticker to wait one tick before calling initF

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 29, 2017 Nov 29, 2017

Copy link to clipboard

Copied

That could lead to a flash of the movieclips being visible for a moment. If you want those 12 movieclips to all be invisible when you get to their frame, you could put this into each one, in the first frame:

this.visible = false;

That would work no matter how nested they are.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 29, 2017 Nov 29, 2017

Copy link to clipboard

Copied

LATEST

It sounds logical, but still and what is missing is to give them a little more context about what I am doing.

The development is a game type where the character moves from left to right and after speaking with some character has to start a search. This is why the buttons should initially be disabled / not visible. They are inside a movie clip because I am moving the stage and the elements that it has inside to simulate the advance, the character does not move, only his movement is animated.

This scenario loads (and moves within) the areas (buttons) that the user has to click on. I could take them out of the movie but what I want to avoid is to make multiple lines of code like this:

this.mcPlayer.play ();

this.mcFront.x + = velocityFront * directionScene;

this.mcMedium.x + = velocityFront * directionScene;

this.mcNPC01.x + = velocityFront * directionScene;

this.mcRightLimito.x + = velocityFront * directionScene;

this.mcLeftLimit.x + = velocityFront * directionScene;

...

And add line by line each of the buttons and elements with which the user will interact.

Thanks again, I'm still on the lookout.

By the way, I'm a graphic designer, I've had to implement code ... it's quite fun.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines