18 Replies Latest reply on Jul 10, 2006 9:08 PM by kglad

    How to center a child mc to the parent mc

    >Vee< Level 1
      I have two mcs that i would like centered to eachother using AS (not the align palette):
      • The parent mc named parent_mc and the child is named child_mc.
      • The catch is that I am loading different size jpgs into the child mc.
      • Seems simple but when you take into account that the width and height of the jpgs are NOT consistent, but the width of the child_mc stays the same regardless- I cant get a true width and height to center the dam thing inside the parent.
      • Is there some way to read the width of the imported graphic maybe?
        • 1. Re: How to center a child mc to the parent mc
          kglad Adobe Community Professional & MVP
          use an empty movieclip for the target of your loadMovie() statement. after you initiate loading use a loop to determine when the target's _width property is greater than zero. terminate the loop and you can now access the loaded pics dimensions and center it.
          • 2. Re: How to center a child mc to the parent mc
            >Vee< Level 1
            I have it up to the part where it has to break out and perform the centering... my loop is off... heres a piece of the code
            • 3. Re: How to center a child mc to the parent mc
              kglad Adobe Community Professional & MVP
              for-loops and while-loops execute from beginning to end (once they start) before anything else happens in your swf. so, they cannot be used for checking load progress/tweening etc.

              you could use an onEnterFrame loop or a setInterval() loop, but because you're already using the moviecliploader class you may as well use its built-in load handlers. for example, (assuming you've instantiated your mcl properly):

              • 4. Re: How to center a child mc to the parent mc
                >Vee< Level 1
                Well, as I wwas trying to move forward I found that the code I was using has an issue: The onLoad = function part of the code triggers my moviecliploader. The problem is that all load the image but they dont trigger the separate button vars, instead they all trigger the number "btn var # 2". Im guessing its because my loop stops at 3. Heres the trace followed by all my code:
                _level0.top_menu_1
                btnLabel_1
                _level0.top_menu_2
                btnLabel_2
                _level0.top_menu_3
                btnLabel_3
                onLoadStart: 2
                onLoadProgress: 2
                onLoadProgress: 2
                onLoadProgress: 2
                onLoadStart: 2
                onLoadProgress: 2
                onLoadProgress: 2
                onLoadProgress: 2
                onLoadStart: 2
                onLoadProgress: 2
                onLoadProgress: 2
                onLoadProgress: 2
                • 5. How to center a child mc to the parent mc
                  >Vee< Level 1
                  I got it to center using this code but I cannot get the correct btnVar to trigger the right variable in the MVCloader. The problem definitely stems from the onLoad b/c when the onPress is triggered the right sequence happens. The btnVar always ends up triggering #2 in the MVCloader from the "tmp_mc.menuName.onLoad = function() {...". Any ideas in that?
                  • 6. Re: How to center a child mc to the parent mc
                    kglad Adobe Community Professional & MVP
                    what's tmp_mc.menuName.onLoad doing? remove it.

                    trace your btnVar to make sure each button is reporting the correct value.
                    • 7. Re: How to center a child mc to the parent mc
                      >Vee< Level 1
                      What i wanted to accomplish is load different content in each mc right off the bat using there respective btnVar's (0 - 2, not using 3 at the moment).The onLoad event traces correctly but does not trigger the right part in the mvcLoader while each onPress event works just fine.
                      tmp_mc = top_menu_1 - top_menu_3 which is the container for two mc's my emtpyMC & menuName (which happens to be a mvcBtn). Below is the trace which illustrates exactly what i am talking about:
                      onLoad: 0
                      onLoad: 1
                      onLoad: 2
                      onLoadStart: 2
                      onLoadProgress: 2
                      onLoadProgress: 2
                      onLoadProgress: 2
                      onLoadStart: 2
                      onLoadProgress: 2
                      onLoadProgress: 2
                      onLoadProgress: 2
                      onLoadStart: 2
                      onLoadProgress: 2
                      onLoadProgress: 2
                      onLoadProgress: 2
                      • 8. Re: How to center a child mc to the parent mc
                        kglad Adobe Community Professional & MVP
                        what trace comes from your onLoad handler? and what's the mvcLoader?
                        • 9. Re: How to center a child mc to the parent mc
                          >Vee< Level 1
                          kglad,
                          quote:

                          Originally posted by: kglad
                          what trace comes from your onLoad handler? and what's the mvcLoader?

                          My onLoad traces this:
                          onLoad: 0
                          onLoad: 1
                          onLoad: 2
                          my trace looks like this: trace(btnVar); //within each part of the conditonal. I was saying "mvcLoader" in my last post instead of "var mcl:MovieClipLoader = new MovieClipLoader();" b/c i thought it was I thought it would explain it in short. The real name of my movie clip loader is "mcl". While it is working somewhat, I still have the problem of it receiving the wrong variable (the number two) from the onLoad handler. I think that this is somehow due to the fact my loop tops of at 2. If you see above I am using a vaiable (var topButtonCount:Number = 3;). I just dont know why the should be wrong.
                          Best
                          Vee
                          • 10. Re: How to center a child mc to the parent mc
                            kglad Adobe Community Professional & MVP
                            the code you posted will not yield

                            onLoad: 0
                            onLoad: 1
                            onLoad: 2

                            i just don't know what you're doing. it seems clear that you're going to have problems with that onLoad handler because it's not going to execute unless you have code elsewhere that would trigger its execution.

                            is menuName a child movieclip of main_menu? if so, then i understand how you could make that error. otherwise, i have no idea.
                            • 11. Re: How to center a child mc to the parent mc
                              >Vee< Level 1
                              In my last post i made an error as you can tell from the trace instead of the trace(btnVar) I used trace("onLoad: "+this.ivar); to get that result. To answer your question:is menuName a child movieclip of main_menu? if so, then i understand how you could make that error.
                              Yes it is.
                              Listen I thought the loop would be able to assign each menuName the correct btnVar, trigger its onLoad and setup its onPress handler. I thought that the onLoad handler would pass the correct btnvar "tmp_mc.menuName.ivar = i;" to the "mcl"s listener. Am i just approaching thi wrong?
                              • 12. Re: How to center a child mc to the parent mc
                                kglad Adobe Community Professional & MVP
                                your onLoad handler's not going to execute. it does nothing. put a trace() statement in there and see.

                                and tmp_mc.menuName is instantiated as soon as you execute your attachMovie() statement. you can use the following to assign an onPress handler (assuming top_menu_1.loader etc are instantiated movieclips).

                                • 13. Re: How to center a child mc to the parent mc
                                  >Vee< Level 1
                                  top_menu_1 - whatever: are all the parent mcs that get attached
                                  loader: child of top_menu_ + i - this was the original mc i was using to load my jpgs into and is not created dynamically
                                  child_mc: was created dynamically later on throughout our discussion in replacement of loader (above)
                                  menuName: also a child of top_menu_ + i - this is a movieclip button that is not created dynamically
                                  I do get onLoad: 0 - 2 when i trace the onLoad handler. My onPress handler works perfect the way it is, although im sure yours does too.
                                  • 14. Re: How to center a child mc to the parent mc
                                    kglad Adobe Community Professional & MVP
                                    copy that code or edit it or whatever, and post a link to a fla that shows an onLoad handler executing in response to movieclips that are instantiated using an attachMovie() statement.
                                    • 16. Re: How to center a child mc to the parent mc
                                      kglad Adobe Community Professional & MVP
                                      here's your corrected code. for centeredMenu0.

                                      • 17. Re: How to center a child mc to the parent mc
                                        >Vee< Level 1
                                        kglad,

                                        Thank you for taking a look at those files and helping make the corrections to the code. I hope you had a good 4th. Ill see you around soon I'm sure.
                                        Best
                                        Vee
                                        • 18. Re: How to center a child mc to the parent mc
                                          kglad Adobe Community Professional & MVP
                                          you're welcome.