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

Nested loop not working

Contributor ,
Sep 20, 2017 Sep 20, 2017

Copy link to clipboard

Copied

Hi
I'm new to Animate and createJS, and I'm trying to learn the syntax, but I'm stuck with this code, where my loop wont loop, meaning that the outer loop stops after the first iteration.

var letters = ["M_container", "O1_container", "T_container", "I_container", "O2_container", "N_container"]

// Pause events

root.pauseBtn.addEventListener("click", pauseAll.bind(this));

function pauseAll() {   

    var j;

    var i;

    var containermc;

    for (j = 0; j < letters.length; j++) {

        containermc = letters;

        for (i = root[containermc].numChildren - 1; i >= 0; i--) {

            var mc = root[containermc].getChildAt(i);   

            mc.stop();

        }

    }

}

So all instances running in the first containermc "M_container" stops as intended, but then nothing else happens.

Also, I'm getting a console error from line 12 ( mc.stop();) , saying that it's not a function even though it works.


I hope someone can help me

P.s. Where can I find some guides for rewriting actionscript syntax to javascript/createJS?
createjs.com is fine for learning some things, but I'm an unexperienced coder, so I need some really basic stuff - maybe I should learn Javascript from the bottom?
Is native Javascript working in Animate? Sorry if it's a dumb question

Views

1.9K

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

correct answers 1 Correct answer

Community Expert , Sep 22, 2017 Sep 22, 2017

you have a shape (the bg) on T that's not elsewhere.

use the timeline property to remedy:

if(mc.timeline){

mc.stop();

}

Votes

Translate

Translate
Contributor ,
Sep 22, 2017 Sep 22, 2017

Copy link to clipboard

Copied

But NOW it works!

for (j = 0; j < letters.length; j++) {

        containermc = letters;

        for (i = root[containermc].numChildren - 1; i >= 1; i--) {

            //mc = ("root." + [containermc] + "._" + );

            mc = root[containermc].getChildAt(i);

            console.log(mc);   

            if (mc.timeline) {

                mc.stop();

            };           

        }


Thanks very much for your help - both of you!

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
Contributor ,
Sep 22, 2017 Sep 22, 2017

Copy link to clipboard

Copied

But... now I'm faced with the fact, that I don't really know what I'm doing with "timeline" because it doesn't work with the play button.
I guess it's because the timelines have been stopped? What to do... can I put some 'not' operator in to fix it?

function playAll() {

    var j;

    var containermc;

    var mc;

    for (j = 0; j < letters.length; j++) {

        containermc = letters;

        mc = root[containermc].getChildAt(i);

        console.log(mc);

        if (mc.timeline) {

            mc.play();

        };

    }

}

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 ,
Sep 22, 2017 Sep 22, 2017

Copy link to clipboard

Copied

what's wrong with that code?

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
Contributor ,
Sep 22, 2017 Sep 22, 2017

Copy link to clipboard

Copied

I'f I used the pause button to stop all the mc's, then I can not start them again using that code. How come?

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 ,
Sep 22, 2017 Sep 22, 2017

Copy link to clipboard

Copied

what code are you using to re-start them?

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
Contributor ,
Sep 22, 2017 Sep 22, 2017

Copy link to clipboard

Copied

This:

function playAll() {

    var j;

    var containermc;

    var mc;

    for (j = 0; j < letters.length; j++) {

        containermc = letters;

        mc = root[containermc].getChildAt(i);

        console.log(mc);

        if (mc.timeline) {

            mc.play();

        };

    }

}

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
Contributor ,
Sep 22, 2017 Sep 22, 2017

Copy link to clipboard

Copied

It start the O1_container, which has a timeline in it, but non of the gears are playing.

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 ,
Sep 22, 2017 Sep 22, 2017

Copy link to clipboard

Copied

where's the inner loop?

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
Contributor ,
Sep 22, 2017 Sep 22, 2017

Copy link to clipboard

Copied

Oh dear... how embarrassing...

Sorry for that, and thanks again!

Can you tell me if it is possible to ad some sort of delay, so the gears will stop/start in a sequence?

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 ,
Sep 22, 2017 Sep 22, 2017

Copy link to clipboard

Copied

yes, but you might find it easier to just add an increasing number of frames at the start of each gear where they do not tween.

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
Contributor ,
Sep 22, 2017 Sep 22, 2017

Copy link to clipboard

Copied

Thanks, but that won't have the desired effect I'm afraid, because they are placed in different orders in the letters, so the result would be very randomly looking. I wanted it to look like they stopped from the left to the right.
I hoped there was some easy way to attach some milliseconds for the loop to iterate - or something like that

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 ,
Sep 22, 2017 Sep 22, 2017

Copy link to clipboard

Copied

you could use code but the child gears would need to be at the depth you want to get the effect you want:

for (j = 0; j < letters.length; j++) {

        containermc = letters;

        for (i = root[containermc].numChildren - 1; i >= 1; i--) {

            mc = root[containermc].getChildAt(i);

            if (mc.timeline) {

            setTimeout(stop_gearF,500*i,mc);

            };           

        }

function stop_gearF(mc){

mc.stop();

}

likewise with play()

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
Contributor ,
Sep 22, 2017 Sep 22, 2017

Copy link to clipboard

Copied

Thanks a lot!

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 ,
Sep 22, 2017 Sep 22, 2017

Copy link to clipboard

Copied

LATEST

you're welcome.

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