_width of dynamic movie clip

_width of dynamic movie clip

Post by LeeKi » Thu, 09 Oct 2008 12:39:16

I'm working on a thumbnail gallery, populated by XML. I've included the code
loading the XML into Flash, and the function that populates my MC called
'picture' with the first image in XML.

But I end up tracing "0" for width of my picture MC....Why is this not
updating to the width of the picture? I need to center this clip dynamically
for each picture, and I don't know how to do this unless I can use the width of
the picture...which clearly I can't access.

Any help?

function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
image = [];
thumbnails = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
thumbnails[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
else {
content = "file not loaded!";
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;

function firstImage() {
if (loaded == filesize) {
picture._alpha = 0;
picture.loadMovie(image[0], 1);
trace("width: " + picture._width);

_width of dynamic movie clip

Post by Rites » Thu, 09 Oct 2008 16:30:11


You should use loadClip function instead of loadMovie. and So your
code will be as below

function firstImage() {
picture._alpha = 0;
// ********** RItesh Code Starts
var mcLoader:MovieClipLoader = new MovieClipLoader();
// ++++ argument 1 - YourImage.jpg
// ++++ argument 2 - container movie clip
function onLoadInit(mc:MovieClip) {
} // function load init ends
// *********** RItesh Code Ends

This code will be run into AS 2.0

if you are using as 1.0 then you should use a Interval and check
getBytesLoaded. Let me know which Flash version you are working.

RItesh Newal


_width of dynamic movie clip

Post by DMennenoh » Thu, 09 Oct 2008 21:13:03

>> picture.loadMovie(image[0], 1);
trace("width: " + picture._width);

Your width is tracing 0 because you are getting it before the loadMovie is
complete - it is an asynchronous operation, so you can't get the width until
it is done. The way to know it's done is to not use loadMovie - use the
MovieClipLoader class instead, and use its onLoadInit method to get / set
loaded clip properties.

Dave -
Head Developer
Adobe Community Expert