2 Replies Latest reply on Aug 10, 2006 6:58 PM by gruffybear

    Loaded Image Width

    gruffybear Level 1
      Am trying to access the width of an image loaded using the code shown below.

      Obviously I know the image width but have written this code into a dynamic function that can load different images dependant on user interaction. Would like to access each images' dimension so that I can position it on stage according to size. If I try trace(displayPossBack_mc.displayHolder_mc._x) all I get is 0.

      Any suggestions greatly appreciated.


        • 1. Re: Loaded Image Width
          Rothrock Level 5
          You need to wait until the external file finishes loading before you can access its width. I'm pretty sure you are using Flash 8 because no other version of Flash can dynamically load a gif file. So if that is the case, I would recommend you use the MovieClipLoader class instead of loadMovie.

          loadMovie is an older method that requires you to build your own preloader to check for the finish of loading. Search the forums or the web for a tutorial on how to make a preloader.

          With the MovieClipLoader class (check the help files for the code) you will be able to use the onLoadInit event to define your code for checking the size, scaling, and/or whatever else you want to do with the external asset.

          If you don't mind I will give you another little tip as well. The createEmptyMovieClip method returns a reference to the newly created clip. So you can assign that to a variable and reuse it. So your code could become.

          var myClip=displayPossBack_mc.createEmptyMovieClip("displayHolder_mc",3)

          Neater, huh? Also notice how I have use the MovieClip class method for loadMovie? by putting the clip to load into before the loadMovie it makes it just a bit cleaner and neater – at least to my eye. So many other methods and properties work this way it just makes it nicer.
          • 2. Re: Loaded Image Width
            gruffybear Level 1
            Thanks a lot Rothrock... get the idea now. Will use MovieClipLoader instead as I can set a function to access the size once it is loaded. Should have thought of this myself.