getChildByName return null if publis setting is Flash 9
Hi,
I am facing a weird problem.
The following code returns null if targeted player is Flash player 9 but works fine for Flash Player 10.
PHP Code:
var _mc:MovieClip = getChildByName("introMC") as MovieClip;
It works fine if I give a delay using setTimeout.
I am not sure what I may be doing wrong. I have attached the source files. (Flash CS5 format)
Any help is appreciated
Bug? That's not a bug, that's a feature. "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rich Coo
Make sure that the movieclip is available when you call the getChildByName method.
The fact that it returns the movieclip reference if u add a delay suggest that the method getChildByName is called before the movieclip is rendered available.
But why changing the Flash Player version to 10 makes the same code to work?
Bug? That's not a bug, that's a feature. "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rich Coo
I really cant answer that question. I can only make assumption that maybe the new player makes sure that all the objects on the frame are loaded and 'available' before sending the completion call or whatever.
1. using setTimeout to give delay and call "control()" function.
2. Put the "control();" function on the layer which has label "start"
3. attach the MovieClip using the class notation var _mc:MovieClip = new MyMC();
However I want to understand why the normal method is not working is there any error in the code?
Bug? That's not a bug, that's a feature. "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rich Coo
This is what i usually follow while coding and make the movieclip structure accordingly. This helps me in loading and managing external files as well.
1) each swf will have one frame having a main movieclip, this movieclip might have all the movieclips and animations that you want internally in that swf
2) the class associated with this swf is instantiated in the root timeline itself
3) this main movielcip will have a blank first frame and a stop() command
4) the second frame is labeled 'start'
5) the last frame has a callback function which calls the class method, this makes sure that all the assets (movieclips, textfields) are available before I begin firing all the method and the layout is done and the class instance is already created
6) as soon as the movieclip loads, the class instance is created and I play it from the label 'start', once the movieclip header reaches the last frame, it calls the callback method from the class which in turn takes over and performs the other commands
This never fails for me. Be it player 9 or player 10. The movieclip structure is crucial.