# Trouble getting/using \_width/\_height of a loaded jpeg

**URL:** https://forum.kirupa.com/t/trouble-getting-using--width--height-of-a-loaded-jpeg/56760
**Category:** flash
**Created:** [July 7, 2004, 4:37pm UTC](https://forum.kirupa.com/t/trouble-getting-using--width--height-of-a-loaded-jpeg/56760 "2004-07-07T16:37:45Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![mariachi77](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@mariachi77](https://forum.kirupa.com/u/mariachi77)
#### Post date: [July 7, 2004, 4:37pm UTC](https://forum.kirupa.com/t/trouble-getting-using--width--height-of-a-loaded-jpeg/56760/1 "2004-07-07T16:37:45Z")

</div>

Hi,

I’m having trouble getting the \_width & \_height of a jpeg loaded using loadMovie.

I’m trying to reposition it (pseudo-registration point) for rotation in a container movie clip.

If I use hard-coded numbers, it works fine. However, if I try to position it based on its \_width and \_height properties, it’s no go… in fact, it doesn’t even show up on stage.

Are there problems getting those properties from loadMovie clips?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 7, 2004, 5:36pm UTC](https://forum.kirupa.com/t/trouble-getting-using--width--height-of-a-loaded-jpeg/56760/2 "2004-07-07T17:36:50Z")

</div>

It’s the same idea as assigning an event handler to the loaded picture. Check number 3 on the following post:  
[http://www.kirupaforum.com/forums/showthread.php?t=61309](http://www.kirupaforum.com/forums/showthread.php?t=61309)

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 7, 2004, 5:57pm UTC](https://forum.kirupa.com/t/trouble-getting-using--width--height-of-a-loaded-jpeg/56760/3 "2004-07-07T17:57:56Z")

</div>

In that thread, you mention that you can’t assign event handlers (or access these properties) until the clip is done loading. However, that’s precisely where I’m trying to access the clip’s properties.

In the container clip, I’ve got an onEnterFrame function which checks to see that it’s 100% loaded and then it attempts to set the image’s position (based on it’s measurements). Perhaps I’m trying to reference the clip incorrectly?

Have a look:

\<!-- an excerptfrom the outer clip’s onEnterFrame function  
\<!-- “jpg” is the name of the loadMovie clip

```
                  if(this.percent.text == "100") {
                      this.percent.text = "";
                      
                      var w = this.jpg._width/2;// didn't work
                      var h = this.jpg._height/2;//didn't work
                      //this.jpg._x = -(this.jpg._width/2);//didn't work
                      //this.jpg._y = -(this.jpg._height/2);//didn't work

```

[//this.jpg](https://this.jpg).\_x = -w;//didn’t work  
[//this.jpg](https://this.jpg).\_y = -h;//didn’t work  
with (this.jpg){  
\_x = -60;//static position I gave  
\_y = -60;//static position I gave  
\_yscale = 24;  
\_xscale = 24;  
}

```
                      delete this.onEnterFrame;
                  }

```

As you can see, I’ve tried a few ways to reference the clip, thinking that’s the problem. How would you write this code?

Cheers,

Mike

> [@claudio](#):
>
> It’s the same idea as assigning an event handler to the loaded picture. Check number 3 on the following post:  
> [http://www.kirupaforum.com/forums/showthread.php?t=61309](http://www.kirupaforum.com/forums/showthread.php?t=61309)

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 7, 2004, 6:09pm UTC](https://forum.kirupa.com/t/trouble-getting-using--width--height-of-a-loaded-jpeg/56760/4 "2004-07-07T18:09:44Z")

</div>

This will fail:

```auto
createEmptyMovieClip("container_mc", 1);
container_mc.loadMovie("picture.jpg");
trace(container_mc._height);//will return 0
trace(container_mc._width);//will return 0

```

This will work:

```auto
createEmptyMovieClip("container_mc", 1);
createEmptyMovieClip("loader_mc", 2);
container_mc.loadMovie("picture.jpg");
loader_mc.onEnterFrame = function() {
	var t = container_mc.getBytesTotal();
	var l = container_mc.getBytesLoaded();
	if (t && l == t) {
		trace(container_mc._height);
		trace(container_mc._width);
		this.removeMovieClip();
	}
};

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 8, 2004, 9:49am UTC](https://forum.kirupa.com/t/trouble-getting-using--width--height-of-a-loaded-jpeg/56760/5 "2004-07-08T09:49:25Z")

</div>

Ok, I used your code and approach but I think because it’s all taking place within a function on the outer clip, there’s still some problem.

\<!-- short example of my situation

```auto

 
 _root.outerclip.loadPic = function(){
 
 // your code (modified)
 
 this.createEmptyMovieClip("container_mc", 1);
 this.createEmptyMovieClip("loader_mc", 2);
 this.container_mc.loadMovie("picture.jpg");
 this.loader_mc.onEnterFrame = function() {
      var t = this._parent.container_mc.getBytesTotal();
      var l = this._parent.container_mc.getBytesLoaded();
      if (t && l == t) {
 //unfortunately, I can't trace at this point
 //because I'm testing through my server (using PHP)
          //trace(this._parent.container_mc._height);
          //trace(this._parent.container_mc._width);
         var h = this._parent.container_mc._height;
         var w = this._parent.container_mc._width;
         this._parent.container_mc._x = -(w/2);
         this._parent.container_mc._y = -(h/2);
          this.removeMovieClip();
      }
  }
 
 }
 
 

```

Anyway, this above code doesn’t work – however, if I set the \_x and \_y values with hard-coded numbers, it works. I even tried to put an if statement ( if (this.\_parent.container\_mc.\_width \> 0) … )… didn’t work.

Any ideas?

Thanks for your attention, Claudio.

Cheers,

Mike

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 8, 2004, 11:39am UTC](https://forum.kirupa.com/t/trouble-getting-using--width--height-of-a-loaded-jpeg/56760/6 "2004-07-08T11:39:42Z")

</div>

Have you tried tracing your paths?  
Does the following variables return any values at all?  
var t = this.\_parent.container\_mc.getBytesTotal();  
var l = this.\_parent.container\_mc.getBytesLoaded();

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 8, 2004, 1:40pm UTC](https://forum.kirupa.com/t/trouble-getting-using--width--height-of-a-loaded-jpeg/56760/7 "2004-07-08T13:40:58Z")

</div>

Ok, I’ve gotten it to work – that should be good news, but it’s not that good because I feel more confused than ever about the details of Flash’s referencing.

This is my function:

Upimage = the outer clip  
Jpg = the container clip that loads the Jpg  
Loader\_mc = as you suggested, the clip that checks the loading info for “jpg”

```auto

  _root.upimage.loadJPG = function (jpg1 : String){
              
              // create mc
              this.createEmptyMovieClip("jpg", 1);
              this.jpg.loadMovie(jpg1);
              this.createEmptyMovieClip("loader_mc", 2);
              this.loader_mc.onEnterFrame = function() {
                  var t = this._parent.jpg.getBytesTotal();
                  var l = this._parent.jpg.getBytesLoaded();
                  
                  if (t && l == t) {
                      //this.percent.text = "loaded!!!!!!!!!!!!!!!!!!!!!";
                      if (this._parent.jpg._width > 0){
                                   
                              this._parent.jpg._x = -(this._parent.jpg._width/2);
                              this._parent.jpg._y = -(this._parent.jpg._height/2);
                              this._parent.jpg._yscale = 24;
                              this._parent.jpg._xscale = 24;    
                          }
                      //this.removeMovieClip(); // notice this is commented out
                  }
              }
          }
  

```

As you can see, I had to comment out the “this.removeMovieClip” line. Why? Because if I left it in, it would remove “upimage” and everything inside. This has always been a problem for me. When I tried your previous code (with the “loader\_mc” and “container\_mc” references):

```auto

  createEmptyMovieClip("container_mc", 1);
  createEmptyMovieClip("loader_mc", 2);
  container_mc.loadMovie("picture.jpg");
  loader_mc.onEnterFrame = function() {
      var t = container_mc.getBytesTotal();
      var l = container_mc.getBytesLoaded();
      if (t && l == t) {
          trace(container_mc._height);
          trace(container_mc._width);
          this.removeMovieClip();
      }
  };
  

```

… the Flash compiler gave me errors, saying that there were no loader\_mc or container\_mc properties. So, I used the “this.\_parent” prefix. Inside a function on clip, “this” stands for what? I’m really confused now.

I’m having trouble tracing my paths because this section is only reachable with the database. I did a small experiment before, comparing “this”, “\_parent”, and “this.\_parent” in an event handler and the results were:

“this” is the clip that has the event handler  
"\_parent" and “this.\_parent” both refer to the parent of the clip

HOWEVER, when I compile code, Flash won’t accept “\_parent”… it will only accept “this.\_parent”… I’m lost with referencing in Flash… do you have a guideline, rulebook, etc.?

Thanks again for your time, mate.

Mike

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 8, 2004, 1:50pm UTC](https://forum.kirupa.com/t/trouble-getting-using--width--height-of-a-loaded-jpeg/56760/8 "2004-07-08T13:50:49Z")

</div>

Just tried it like this to see what would happen:

```auto

  _root.upimage.loadJPG = function (jpg1 : String){
              //set image var
              this._parent.image = jpg1;
              // create mc
              createEmptyMovieClip("jpg", 1);
              jpg.loadMovie(jpg1);
              createEmptyMovieClip("loader_mc", 2);
              loader_mc.onEnterFrame = function() {
                  var t = jpg.getBytesTotal();
                  var l = jpg.getBytesLoaded();
                  
                  if (t && l == t) {
                       if (jpg._width > 0){
                          jpg._x = -(jpg._width/2);
                          jpg._y = -(jpg._height/2);
                          jpg._yscale = 24;
                          jpg._xscale = 24;    
                      }
                      this.removeMovieClip();
                  }
              }
          }
  

```

Check out the errors I get from the compiler:

**Error** code.as: Line 414: There is no method with the name ‘createEmptyMovieClip’.  
createEmptyMovieClip(“jpg”, 1);

**Error** code.as: Line 415: There is no method with the name ‘jpg’.  
jpg.loadMovie(jpg1);

etc.

Total ActionScript Errors: 11 Reported Errors: 11

What do you think?

Mike
