10 Replies Latest reply on Mar 14, 2007 10:21 AM by shikozel

    MovieClip Width

    RonenUliel
      hello!
      can someone help?
      i've been trying to solve this problem for a few days:

      i have an array of MovieClips that contains external images.
      i'm trying to find what is the width of a certain image/movieclip in that array.

      i used duplicatMovieClip when i created the array and loaded the images in it.
      for example:
      var NumberOfImages = 17;
      var LocationToImages = "INSPIRATION/";
      var FileType = ".jpg";
      var imgSHOW = 16; //(or any other random number)
      var mc = 1;
      while (mc <= _root.NumberOfImages) {
      MyArray2[mc] = _root.LocationToImages+mc+_root.FileType;
      MyArray2["newCONT" + mc] = duplicateMovieClip("CONT","newCONT"+mc,mc);
      loadMovie(MyArray2[mc], "newCONT" + mc);
      mc++;
      }

      NOW I WANT TO GET the width of a certain MovieClip:
      it works when i write:
      WID = newCONT16._width;
      BUT IT DOESNT WORK when i write:
      WID = "newCONT"+imgSHOW._width; // I tried many other variations

      It seems that i im doing something wrong - HOW CAN I GET THE WIDTH??

      PLEASE HELP.
      (i feel that the solution is not that complicated...)

      Thanks a lot!
      Ronen

        • 1. Re: MovieClip Width
          shikozel Level 1
          ma kore? you need to get the instance of the movie clip first. thats how you do it:
          _root[ "newCONT"+imgSHOW]

          then you can get the width:
          _root[ "newCONT"+imgSHOW]._width
          • 2. Re: MovieClip Width
            RonenUliel Level 1
            Thanx SHIKO!
            ATA GADOL!
            • 3. Re: MovieClip Width
              RonenUliel Level 1
              hello Again!
              can someone help again? SHIKO...are you there?

              i have this array of MovieClips that contains external images.
              i'm trying to find what is the width of a certain image/movieclip in that array.

              i used duplicatMovieClip when i created the array and loaded the images in it.
              for example:

              in frame 1:

              var NumberOfImages = 17;
              var LocationToImages = "INSPIRATION/";
              var FileType = ".jpg";
              var imgSHOW = 16; //(or any other random number)
              var mc = 1;
              while (mc <= _root.NumberOfImages) {
              MyArray2[mc] = _root.LocationToImages+mc+_root.FileType;
              MyArray2["newCONT" + mc] = duplicateMovieClip("CONT","newCONT"+mc,mc);
              loadMovie(MyArray2[mc], "newCONT" + mc);
              mc++;
              }

              NOW I WANT TO GET the width of a certain MovieClip - BUT IT RETURNS - 0 (ZERO)
              (as if refering to the original empty MovieClip ("CONT"))
              look:

              if (mc > _root.NumberOfImages) {
              imgSHOW = Math.floor(Math.random()*(_root.NumberOfImages))+ 1;
              wid = _root.INSP["newCONT"+imgSHOW]._width; // this is the problematic line
              }



              NOTE:
              this line works well when being called from a button release (in the same scene):

              on (release) {
              WID = _root.INSP["newCONT"+imgSHOW]._width;
              }


              WHY CAN'T I GET THE WIDTH In the first frame in the exact same??

              PLEASE HELP.


              Thanks a lot AGAIN!
              Ronen
              ronenuliel@gmail.com Text Text Text
              • 4. Re: MovieClip Width
                BorosAdam Level 1
                the problem is that you are trying to get the _width property before the image is totally loaded into your application therefore the width of the mc is zero. if i can give an advice: try to avoid using loadMovie! that's very very old-fashioned! :)
                there is a class called MovieClipLoader try to use that! it has many useful methods and is very easy to use! (search for it in the flash help)

                adam
                • 5. Re: MovieClip Width
                  RonenUliel Level 1
                  thanx ADAM!

                  i'll take your advice and look for help about MovieClipLoader.

                  but anyway i'm not sure that i recive the value zero because the image hasn't fully loaded... look i ask for this value only after making sure the the
                  variable mc is greater then the NumberOfImages.

                  is there any other way to verify that the image / all images has fully loaded?

                  thanks again,
                  Ronen
                  • 6. MovieClip Width
                    shikozel Level 1
                    hey Ronen,

                    Adam is right. you get 0 because the image wasnt fully loaded when you ask for the _width property.
                    use movieClipLoader class:

                    thats how you should load your images...



                    var mcLoader:MovieClipLoader = new MovieClipLoader();
                    mcLoader.addListener(this);
                    mcLoader.loadClip(MyArray2[mc] "newCONT" + mc;)

                    //this function will envoke when image was loaded to the container
                    function onLoadComplete(mc:MovieClip) {
                    trace("onLoadInit: " + mc);
                    }


                    check the DOC too:
                    http://brajeshwar.com/reference/as2/
                    • 7. Re: MovieClip Width
                      RonenUliel Level 1
                      Thanks SHIKO and ADAM,

                      i did replace the method and used the MovieClipLoader.
                      thanks to you guys.

                      but i still have a problem getting the width of the movie clip.
                      ?? is this the line i should use:

                      imgSHOW = Math.floor(Math.random()*(_root.NumberOfImages))+ 1;
                      wid = _root.INSP["newCONT"+imgSHOW]._width; // this is the problematic line

                      where should i put it? i tried putting it in many place and i still get zero value.
                      how do i make sure the image has fully loaded?
                      should i use the function onLoadComplete(mc:MovieClip) to do this?

                      hope i'm not being a pain in the ***.... thanks AGAIN.
                      Ronen
                      • 8. Re: MovieClip Width
                        shikozel Level 1
                        you should put it in the onLoadComplete function:

                        look at this code. it does more or less what you trying to acheive

                        var loadListener:Object = new Object();

                        loadListener.onLoadComplete = function(target_mc:MovieClip, httpStatus:Number):Void {
                        trace(">> loadListener.onLoadComplete()");
                        trace(">> =============================");
                        trace(">> target_mc._width: " + target_mc._width); // 0
                        trace(">> httpStatus: " + httpStatus);
                        }

                        loadListener.onLoadInit = function(target_mc:MovieClip):Void {
                        trace(">> loadListener.onLoadInit()");
                        trace(">> =============================");
                        trace(">> target_mc._width: " + target_mc._width); // 315
                        }

                        var mcLoader:MovieClipLoader = new MovieClipLoader();
                        mcLoader.addListener(loadListener);

                        var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
                        mcLoader.loadClip(" http://www.w3.org/Icons/w3c_main.png", mc);



                        this function will invoke when the image is fully loaded.
                        • 9. Re: MovieClip Width
                          RonenUliel Level 1
                          Thanks a lot SHIKO!
                          you really helped me getting through to a better level in actionscripting.
                          i'm working on it right now...

                          if there is anyway i could help you back feel free to get in touch:
                          0547774936
                          Ronen
                          Industrial | Graphic designer
                          ronenuliel@gmail.com
                          • 10. Re: MovieClip Width
                            shikozel Level 1
                            too bad i live in NY :). thanks for offering help. if you stuck with something email me: ezderman@yahoo.com