6 Replies Latest reply on Jul 5, 2007 3:05 PM by type05

    centre aligning images within picture frame using XML file

    type05
      Hi
      I am using a flash file that uses an xml file to upload a series of images one at a time into a picture holder.
      There are two different widths of the images. The height is always the same. Is it possible to set this up so every image that the xml file calls is centre aligned within the picture frame.
      At the moment when using the xml file to load the image it always left aligns the image when it brings it into the picture frame even if you change the alignment to centre align within in the align panel.
      Does anyone have a suggestion why this is happening or how to fix it?
      Thanks for the help
        • 1. Re: centre aligning images within picture frame using XML file
          Greg Dove Level 4
          Are you usng as2?
          If yes then I believe the best option (using the MovieClipLoader class) is to adjust your image (via the containing movieclips _x property, after checking its _width property) in the the MovieClipLoader's onLoadInit handler.

          • 2. Re: centre aligning images within picture frame using XML file
            type05 Level 1
            Hi GWD
            Thanks for the reply.
            I am very new to this so a little unsure where I would adjust this action script. I have included the script if you get a chance to reply could you give me an example where this new code would go.
            Will not be able to reply back until tonight as about to go to work.
            Thanks again for the help.
            • 3. centre aligning images within picture frame using XML file
              Greg Dove Level 4
              I did this quickly and didn't test it - but if it doesn't work straight off it might give you a starting point - or someone else may correct it if there are errors. I'll check back tomorrow - where I am its time to go to sleep...
              EDIT DETAILS: Just changed a couple of bits of the code I posted last night - I forgot to change the holder_mc.loadMovie instruction in the xml.onLoad handler. I haven't tested this, but its along the lines of the approach I would use to fix your problem with the image sizing. Let me know how you get on with it.
              • 4. Re: centre aligning images within picture frame using XML file
                type05 Level 1
                Hi GWD
                Thanks so much for the help I really appreciate it. Your script works perfect. All images that get called by the xml are centre aligned within the picture holder. I think it's going to take me a while to understand the changes you made to make it work.
                Until next time
                Thanks again
                • 5. Re: centre aligning images within picture frame using XML file
                  Greg Dove Level 4
                  You're welcome. Pleased it worked.

                  All it does is use the MovieClipLoader class to load the images into your holder_mc. Because loading takes time, and because you can't check or adjust the size or position of images until they have loaded, the MovieClipLoader class gives you a handy option to run some code whenever its finished loading something you told it to load.
                  That's what the addListener instruction does... it says whenever myLoader has something new to tell me about the status of the load requests I ask it to do... make it run some related code in the listener object (which is called loadListener in this code... it could equally be called something else). You 'listen' for different events or updates of status. All I 'listened' for here was the onLoadInit event.
                  The onLoadInit is the 'final' status update after loading. It occurs when something has loaded and its properties are accessible (_x, _width etc). The target_mc that is an argument for the loadListener.onLoadInit is a reference to the clip that was loaded into.

                  The best way to learn about this stuff is probably to read up on MovieClipLoader in the livedocs and try google to see if there's an online tutorial somewhere. Then give it a try yourself in another new fla.

                  cheers
                  GWD

                  • 6. Re: centre aligning images within picture frame using XML file
                    type05 Level 1
                    Thanks GWD for the help as well as explanaton of what the script is doing.
                    Will try it out in a new fla.