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
you have a shape (the bg) on T that's not elsewhere.
use the timeline property to remedy:
if(mc.timeline){
mc.stop();
}
Copy link to clipboard
Copied
where's root defined?
Copy link to clipboard
Copied
Oh - in the beginning of my js. file: var root = this;
Copy link to clipboard
Copied
if that's on a different frame, it's not defined in the code you showed.
Copy link to clipboard
Copied
It's not; all the code is in the first frame.
And the function works, it pics up the movieclip ('containermc') targeted in the outer loop, and all the movieclips ('mc') inside of the 'containermc', but the looping stops and does not continue to the next 'containermc'.
Copy link to clipboard
Copied
It's stopping because of the error, which may or may not be caused by a bug. Have you tried putting the code on the second frame, and letting it play the first frame?
Copy link to clipboard
Copied
No... I'm not sure what you mean...? Should I move this function to frame 2?
And by error - do you mean the mc.stop(); error I'm getting?
Copy link to clipboard
Copied
Yes, you can move all the code to frame 2 as well as add this.top(); at the top, just to see if that fixes it
And yes, any error that your code generates will stop it from running.
Copy link to clipboard
Copied
I'll try to do so tomorrow morning (it's late now and I need some dinner and sleep )
I'll get back with the results - thanks for your help so fare!
Copy link to clipboard
Copied
if root's defined, the code is ok. it's probably a letters
ie, find for which j does you code fails and then check for the object.
Copy link to clipboard
Copied
Okay - I'll try to work on that tomorrow, and hopefully get back with a positive report on the results
Thanks for now!
Copy link to clipboard
Copied
you're welcome.
Copy link to clipboard
Copied
Your best friend in this situation is console.log(). You can make it write to the console inside the nested loop to check if the code actually runs or not. You can also check if mc is found, if you do console.log(mc), along with anything else you want to check.
To open the console you can press F12 and change to the console tab.
Copy link to clipboard
Copied
I already did that, and all the 'mc's in the first 'containermc' is found, so this is not my problem.
It's that the iteration of the outer loop stops finishing the inner loop, meaning that the outer loop does not continue to the next 'containermc'.
Copy link to clipboard
Copied
Goodmorning
Now I'm getting somewhere: If I remove line 12 (mc.stop()), which is giving me the console error "not a function", the outer loop is working fine according to the console, and I am getting all the instancenames when doing "console.log(containermc);"
But when I run "console.log(mc);" from the inner loop, I get a bunch of this instead of the instancenames inside the letter movieclips:
"Object { _listeners: null, _captureListeners: null, alpha: 1, cacheCanvas: null, cacheID: 0, id: 88, mouseEnabled: true, tickEnabled: true, name: null, parent: Object, 30 more… }"
The instancenames are just an underscore followed by a number from 1 - 19.
I seams that I am making an error when targeting. In actionscript2 I would write _root.containermc._1.stop(); to stop the timeline in a specific mc.
Copy link to clipboard
Copied
So the error causing all my trouble is that I don't know how to write my stop function.
My variable mc is now containing the correct movieclip name "root.M_container._1" and so on.
But writing "mc.stop()", which in my logic should be the same as writing "root.M_container._1.stop()", does not work.
Copy link to clipboard
Copied
That's actually normal. It's logging the object and all it's properties.
The way you are stopping the movieclips should work though, so could you upload the project and link it?
Copy link to clipboard
Copied
I've put a copy here: motion
Please don't laugh out to loud - I know it's quit ugly coding, but it's come together as chunks of ideas and has been used for practicing and learning.
It's highly CPU consuming which I guess is caused by my many timelines in the gears? Or is it the ugly coding or something with caching?
Strange thing: If you take a look at function O1clicked(), with the console opened, you'll see that it does not return an error from the mc.stop() as it does in my initial problem with the loops. On function Tclicked() it does!
Copy link to clipboard
Copied
I can't see the code that you wrote from the page you linked, I would need the project file to see it.
I get the error you mentioned, but only when clicking on the T but it still works as expected it seems, other than that I don't get any errors. If you're getting errors in other cases, it may be because of your operating system and browser.
Copy link to clipboard
Copied
Oh - I thought you would be able to see it in the console...
I put a zip here
The reason the pausebutton doesn't return an error anymore will be obvious when you see the file
Definitely not a very good piece of code!
Copy link to clipboard
Copied
you're trying to apply a stop() to a shape. ie, the child 0 is a shape.
Copy link to clipboard
Copied
The letters are movieclips with instancenames "O1_container", "T_container" and so on.
Inside them there are other movieclips named "_1", "_2" and so on.
If it is indeed a shape, how come the mc.stop() work on the first O (O1_container) and not on the T?
Copy link to clipboard
Copied
you have a shape (the bg) on T that's not elsewhere.
use the timeline property to remedy:
if(mc.timeline){
mc.stop();
}
Copy link to clipboard
Copied
Aha! Because I have the background i the T it gives me the error on the mc.stop()?
And if I write your code instead of just mc.stop(); it will work?
Will it also do the trick on my nested loop on the pausebtn?
Copy link to clipboard
Copied
if you see the same error, yes.