View comments | RSS feed

MovieClip._width

Availability

Flash Player 4 as a read-only property.

Usage

my_mc._width:Number

Description

Property; the width of the movie clip, in pixels.

Example

The following code example displays the height and width of a movie clip in the Output panel:

this.createEmptyMovieClip("image_mc", this.getNextHighestDepth());
var image_mcl:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();
mclListener.onLoadInit = function(target_mc:MovieClip) {
   trace(target_mc._name+" = "+target_mc._width+" X "+target_mc._height+" pixels");
};
image_mcl.addListener(mclListener);
image_mcl.loadClip("http://www.macromedia.com/devnet/blueprint/articles/nielsen/spotlight_jnielsen.jpg", image_mc);

See also

MovieClip._height

Comments


webweber@bluewin.ch said on Aug 26, 2004 at 10:22 AM :
Beware of assigning a value to the _with (or _height) property of an _empty_ MovieClip.

When the _width or _height of an empty MovieClip is set to a value of 0 or
greater, it's _width or _height gets kind of 'frozen' at 0: when some content is loaded into the clip, the content does not show up because the value of _width and _height will still be 0.
Any attempt to assign a new value after the load to the _height property
fails silently, the value will still be 0.
Assigning a value (after the load) to the _width property however shows an unexpected result: the value is set to 3/4 of the assigned value. (The imagewill still not show up though, as the _height is still 0)

As expected, attempts to assign a negative number to an empty clip (i.e.
before anything is loaded into it) are ignored. With the paradoxical result that if (nonsensical) negative values are assigned to the empty clip and
something is loaded into it, the contents _does_ show, as the assignment was ignored and thus did not 'freeze' the _width and _height at 0...

While assigning a value to the _width or _height of an empty clip does not make much sense anyway, I still would consider this behavior a bug.
Novice flashers who are not familiar yet with the asynchronicity of loadMovie() often try to set the size of a holder clip before the file is loaded - they will then never see anything being loaded.

The following code demonstrates this

before loading 0 x 0
after loading 75 x 0

The loaded image does not show up.

imageToLoad = 'BlueHills.jpg';

var image = createEmptyMovieClip("image_mc",1);
image._width = 100;
image._height = 100;
image.loadMovie(imageToLoad);
trace('before loading '+image._width +' x '+image._height);

this.onEnterFrame = function(){
var loaded = image.getBytesLoaded();
var total = image.getBytesTotal();
if(loaded > 15 && loaded >= total){
delete this.onEnterFrame;
image._width = 100;
image._height = 100;
trace('after loading '+image._width +' x '+image._height);

}
}

Output:
before loading 0 x 0
after loading 75 x 0

The loaded image does not show up.
MytyMykyk said on Jan 31, 2005 at 6:01 AM :
I'm having a problem kind like the one above...

I have a on Release function on some thumbnails that loads a pic into a movieclip. The way its set up by default, it always loads on the left, i.e., top left image corner attached to teh top left movieclip corner.... this happens by default . Problem is that I want to load the image and align it to the right, wich seems impossible at the momment:

thumbHolder.onRelease = function() {

loadMovie(this.main,loader);
loader._x = 396 - loader._width;
};

This is what i tried; works only when i click the thumbnail for the second time, which is really wierd. loader is the mc to which im loading the image.

Really strange....
dumbified said on Apr 2, 2005 at 2:18 PM :
you would probably need to add a something on this frame do somehting else with the new loaded thing inside the movie clip after its not empty.
Keoki_SoftwareDeveloper said on May 27, 2005 at 9:54 AM :
There's a bug in _root._height & _root._width. The dimensions are incorrect.
Supashy said on Jun 8, 2005 at 11:50 PM :
When I load external movie which nothing in the first frame, I got
_width = 0 and _height = 0.

How do I know the Stage's size of the loaded movie?

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/mx2004/main_7_2/00001567.html