Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
So it doesn't matter where the function is declared (I'm assuming "declared" == "defined")? I could, for example, declare all the functions at the top of the code, then just call them at the appropriate time?
This will mean that almost all of my variable will have to be global, yes? (As I understand it, a variable declared within a function, ie between { }, is only available within that function and is discarded.)
Thank you for the suggestion (and sample code). This is exactly the kind of help I was looking for... the books and video tutorials are useful, but this addresses a specific need.
To be clear, will this change affect how much processor time or memory is involved? My guess is no, because all the same steps have to be carried out, but it makes the code much more elegant.
Thank you again: my original problem remains unsolved (for the moment) but you have taught me a great deal. I have already thought of places in the code where I could employ the same method to reduce the volume.
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
/t5/animate-discussions/1046-type-was-not-found-or-was-not-a-compile-time-constant-event/m-p/4141832#M117272
May 21, 2012
May 21, 2012
Often there's very few variables you need to keep in global scope. If you find you have a ton of them, that's when you make an array or object and start sticking the references and values in there.
e.g.
var settings:Object = new Object();
settings.someVar = value;
settings.someOtherVar = value;
settings.someClipReference = some_clip_mc;
or
var lotsOfObjectReferences:Array = new Array();
lotsOfObjectReferences.push(someClip
1
);
lotsOfObjectReferences.push(someClip
2
);
lotsOfObjectReferences.push(someClip
3
);
lotsOfObjectReferences.push(someClip
4
);
lotsOfObjectReferences.push(someClip
5
);
By doing that it keeps a bunch of related information contained inside a single object for easy access (and removal).
Yes you definitely want to put all these functions on a global scope. There's no optimization difference between either approach on a modern computer, but one is much easier to debug and memory friendly.
You'll be more optimal bringing every function down to global scope because you won't be re-creating a function and assigning it over and over. By creating it inside the function scope over and over like you are, you are creating a new "anonymous" function every time you assign it. That can be optimized by pointing all the clips to the same single global function. Then only one function is in memory and all the clips use it.
After you get done rewriting it feel free to post it back. Only then can I really speculate on what the errors might be as the structure and line numbers will change.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
/t5/animate-discussions/1046-type-was-not-found-or-was-not-a-compile-time-constant-event/m-p/4141833#M117273
May 23, 2012
May 23, 2012
Often there's very few variables you need to keep in global scope. If you find you have a ton of them, that's when you make an array or object and start sticking the references and values in there.
|
Define "a ton of them". I just counted 81 global variables in ± 2,100 lines (of which probably 1,300 lines are actual code , with appropriate white-space for readability).
Does this qualify as "a ton of them"? I'm beginning to suspect it might. Does stuffing them into an array, or attaching them to a generic object reduce memory use? If not, how else does it help?
By doing that it keeps a bunch of related information contained inside a single object for easy access (and removal).
|
How do I remove an object or an array used to store variable? I'm familiar with removeChild() for removing objects from the display list, but that's all. It seems to me that using an array would be most useful if I wanted to cycle through the stored values in an incrementing loop, for example. Otherwise I think using an object might be better because the names would be easier to keep straight in
my
memory than the array index position. (To quote an old BBS tagline, "The older I get, the better I used to be.")
Your suggestion to un-nest most of my functions worked. The "1046: Type was not found or was not a compile-time constant: Event." compiler errors disappeared, They were replaced by 126 other compiler errors, but I eventually solved all of those and I've reduced the size of the source code to about 25% of the original size. I would have to say that your guess from 30 feet away was exceptionally astute. Thank you again.
Terry
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
/t5/animate-discussions/1046-type-was-not-found-or-was-not-a-compile-time-constant-event/m-p/4141820#M117260
May 16, 2012
May 16, 2012
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
/t5/animate-discussions/1046-type-was-not-found-or-was-not-a-compile-time-constant-event/m-p/4141822#M117262
May 16, 2012
May 16, 2012
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
/t5/animate-discussions/1046-type-was-not-found-or-was-not-a-compile-time-constant-event/m-p/4141823#M117263
May 16, 2012
May 16, 2012
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more