PDA

View Full Version : AS Project - Nested MCs - Error #1006 MovieClip function not found


tarafenton
02-10-2009, 09:27 PM
I've been struggling with this for several days now and no post or reference has helped. I originally created a project in the Flash IDE, but started to become overwhelmed with the size of the project and have been told to migrate over to Flex as an editor.

So I am starting over by added pieces of the code little by little so I can narrow where the errors originate. What I have been struggling with is getting a MovieClip added to the display. I think it may be because the MovieClip is null - not created yet (at least that is what I have seen in other posts that go with this error) But I do a trace after the MCs are created and they trace out correctly. I look in the debugger, but I don't know what I am looking for besides name and parent seems right to me.

private function pageHolder():void {

for (var i:int=0; i < this.myArray.length; i++) {
//set up single page layers
singleHolder=new MovieClip ;
singleHolder.name="page" + i;
singleImage=new MovieClip ;
singleImage.name="imageMC";
singleLetter=new MovieClip ;
singleLetter.name="letter";

singleHolder.addChild(singleImage);
singleHolder.addChild(singleLetter);
singlePages.addChildAt(singleHolder,0);
}
}

Then later on in the code

private function checkToContinueLetter():void {
MovieClip(singlePages.getChildByName("page1")).MovieClip(getChildByName("imageMC")).addChild(MovieClip(singleImage_arr[1]));
}

Throws up... TypeError: Error #1006: MovieClip is not a function.

I should note that
MovieClip(singlePages.getChildByName("page1")).addChild(MovieClip(singleImage_arr[1]));
works for some reason, but it is not where I want to add the child. I need to add it to the imageMC not page.

PLEASE HELP!!!
Any advice on the debugger, migration from Flash IDE to Flex, adding displayObjects to the document class through classes? I need all the help you can give, even if it is just a suggestion.

Thanks

wvxvw
02-10-2009, 11:45 PM
this isn't the way you cast types...
MovieClip(singlePages.getChildByName("page1")).MovieClip(getChildByName("imageMC")).addChild(MovieClip(singleImage_arr[1]));
Strange it tried to compile this...
((singlePages.getChildByName("page1") as
MovieClip).getChildByName("imageMC") as
MovieClip).addChild(singleImage_arr[1] as MovieClip);
would be the right way to do it...
Though, the framework prescribes:
- converting instead of casting, i.e.
you'd do it like this (but that's weird IMO):
MovieClip(MovieClip(singlePages.getChildByName("page1"
)).getChildByName("imageMC")
).addChild(MovieClip(singleImage_arr[1]));
But it's weird anyway to write this sort of "macaroni" code. Try not to write lines longer than 80 symbols.
- put parentheses after calling constructor.
- don't use MovieClip.name property.
- if possible, for arrays of items of the same type use Vectors.

tarafenton
02-12-2009, 07:42 PM
Thanks that worked!

I know this is not the best way to go about it, but when I was loading it another way, some images would load on top and I can't have that, so I thought I would set up, layer place holders to insert the images from my arrays in the correct layer when I need it to display.

This is my first really big project working with classes and I appreciate the help, even though I know it's weird. I'm just trying to get the project to a certain point to be able to go to another programmer for advice on how to restructure it into a good project.

I have a few questions about your additional suggestions.

- put parentheses after calling constructor - I stopped doing that because when I was working in the Flash IDE and formatted the code they would get erased. I assumed they weren't really needed. Do you think they are?
- don't use MovieClip.name property. - What should I use?
- if possible, for arrays of items of the same type use Vectors. - I don't really get this statement, can you explain a little more?

wvxvw
02-12-2009, 08:01 PM
Ok... Flash IDE script editor isn't really a good one :) And, being honest, whatever it does when doing autoformat is not so good... After you'll get used to Flex you'll see the difference. Though, I really like FlashDevelop more, but, Flex is at least normal...

MovieClip.name isn't really needed, it, along with the MovieClip class being dynamic and having addFrameScript() is a sort of compromise between normal coding and "simplified" variant that you may use when writing the code on timeline. Normally you want to have references to the objects themselves, and not to search for them using some string identifier. Also, this property shouldn't be unique and may be changed by another part of code occasionally, so, it's not a reliable source for identifying the display object.

Vector is a typed array class introduced in FlashPlayer 10. It's preferable over Array because of:
- better performance.
- you don't need to cast types when using hash access, i.e.
array[index] is of type *
while
vector<String>[index] is of type String
- as the result from above, you'll have autocompletion for vector members, while if you want autocompletion for array members you'd use:
(array[index] as String).someStringProperty

tarafenton
02-12-2009, 08:19 PM
I know Flash IDE is garbage! for coding classes, I learned the hard way and finally convinced my job to get me Flex, can't get FlashDevelop since I'm on a mac. I already love Flex in just a couple of days.

Your definitely giving me more to think about. Although this piece totally went over my head
MovieClip.name isn't really needed, it, along with the MovieClip class being dynamic and having addFrameScript() is a sort of compromise between normal coding and "simplified" variant that you may use when writing the code on timeline.
But I think I get what your saying with the rest of your post...I should not use getChildByName, I should have created another array that will hold a reference to the displayObject I want to add the image to? I just thought that would be array overload, but I am happy to be pushed in a better direction. I'm going to try it out.
Normally you want to have references to the objects themselves, and not to search for them using some string identifier. Also, this property shouldn't be unique and may be changed by another part of code occasionally, so, it's not a reliable source for identifying the display object.

Vector is a typed array class introduced in FlashPlayer 10
Wow! That's the first I heard of this, so would I want to make my array a vector?....I'm going to look more into this right now


Thanks again!!