7 Replies Latest reply on Jul 15, 2008 6:16 AM by kglad

    code needed to move object on stage

    dtodab Level 1
      i have a photography based site where i'm hoping to create a simple AS code to move a navigation menu in relation to changing image sizes. there are many different widths to the images and i'm hoping to have the navigation menu (movie clip buttons currently in the top right area) move along the x axis to keep the same distance away from each image. rather than manually doing it by frame, i'm hoping to solve the issue with some script.
      any advice?
      thank you in advance.
        • 1. Re: code needed to move object on stage
          kglad Adobe Community Professional & MVP
          after loading is complete you can access the loaded images width using its loader's properties.
          • 2. Re: code needed to move object on stage
            dtodab Level 1
            not sure if i was clear enough with my question.
            basically i'm trying to slide the navigation menu to keep the same distance away from the image (stage center, more or less) as the user advances through different images.
            is there not some script that dictates relative positioning? (position relative to an image whose width changes from frame to frame)
            thanks for the input so far.
            • 3. code needed to move object on stage
              Shandy Elliott Level 1
              How are you loading your images? Are you using a Loader component? Like kglad said, (and if you are using a Loader component), when listener.complete is reported back to Flash, you can obtain the .width of the Loader component itself, or the ._width on the Loader component's .content (depends on how you want to use the Loader). From that, you can move your menu clips along the x axis with something like (and using a listener):

              var cpLoaderListener:Object = new Object();
              cpLoaderListener.complete = function(evt_obj:Object) {
              var loaderWidth:Number=LoaderInstance.width;
              // or var loaderWidth:Number=LoaderInstance.content._width;//
              }
              LoaderInstance.addEventListener("complete", cpLoaderListener);

              Then you can take that information and move your menu (based on LoaderInstance.x or LoaderInstance.left + loaderWidth + some padding room if you want). All this code is off the top of my head, and not ALL the code you would need, but it is enough to point in that direction.
              • 4. Re: code needed to move object on stage
                dtodab Level 1
                thanks for the help.
                i'm not actually using a loader component - but maybe i should be.
                would a loader component help at all with keeping the overall size of an image based site down? or is it more an easier way to control things?
                • 5. Re: code needed to move object on stage
                  kglad Adobe Community Professional & MVP
                  using any component will increase, not decrease, the size of your application. and it's not easier to control things using components.

                  and there's no script that dictates relative positioning. you must explicitly position objects where you want them.

                  so again, you need to wait until loading is complete to access the size of your loaded objects. how you do that is dependent on how you're loading your images.

                  if you're using loadMovie() or loadMovieNum() you need to create a loop to check the target movieclip's load progress. if you're using the moviecliploader class, you can use the mcl listener's onLoadInit() method.
                  • 6. Re: code needed to move object on stage
                    dtodab Level 1
                    thanks for the clarification.
                    i will apply that to my next site for sure.
                    • 7. Re: code needed to move object on stage
                      kglad Adobe Community Professional & MVP
                      you're welcome.