View Full Version : Can't get dimensions of EmptyMC
Sinister Shadow
November 18th, 2005, 08:49 PM
Ok, I've created an empty movieclip in _root and loaded an image into it but whenever I do trace(_root.newMC._width) I get a 0! I've had this problem in the past but never really looked into it!
Ah, while I'm at it, I have the following code:
with _root
{
createEmptyMovieClip("file", 0).loadMovie("someimg.jpg");
["file"]._x = (Stage.width - ["file"]._width) / 2;
["file"]._y = (Stage.height - ["file"]._height) / 2;
lineStyle(3, 000000, 100);
moveTo(0, 0);
lineTo(800, 600);
moveTo(0, 600);
lineTo(800, 0);
}
The problem I'm having with this is that when it looks for Stage.width it's actually trying to find _root.Stage.width. How do I get around that without breaking out of the 'with'?
stringy
November 18th, 2005, 09:01 PM
Ok, I've created an empty movieclip in _root and loaded an image into it but whenever I do trace(_root.newMC._width) I get a 0! I've had this problem in the past but never really looked into it!
Ah, while I'm at it, I have the following code:
with _root
{
createEmptyMovieClip("file", 0).loadMovie("someimg.jpg");
["file"]._x = (Stage.width - ["file"]._width) / 2;
["file"]._y = (Stage.height - ["file"]._height) / 2;
lineStyle(3, 000000, 100);
moveTo(0, 0);
lineTo(800, 600);
moveTo(0, 600);
lineTo(800, 0);
}
The problem I'm having with this is that when it looks for Stage.width it's actually trying to find _root.Stage.width. How do I get around that without breaking out of the 'with'?
you need to wait until your movie has loaded before you can get dimensions.
just check for getBytesLoaded/getBytesTotal() in a loop.(onEnterFrame or setInterval)
you can just store your clip in a variable but the code you are using here will not work-wait until it is loaded
have a look at the file here, i think it sort of answers both elements of your question
http://kirupa.com/forum/showthread.php?t=190279
Sinister Shadow
November 18th, 2005, 09:46 PM
Thanks for the pointers stringy. Muchos gracias! :D
I came up with the following code using your tips and a little help from a tutorial on senocular's site:
_root.onEnterFrame = function () {
if (!this.file)
{
this.createEmptyMovieClip("file", 0).loadMovie("someimg.jpg");
}
else if (this.file.getBytesLoaded() >= this.file.getBytesTotal())
{
this.file._x = (Stage.width - this.file._width) / 2;
this.file._y = (Stage.height - this.file._height) / 2;
delete this.onEnterFrame;
}
}
Mirandir
November 19th, 2005, 04:22 AM
Just a little improvement on your preloader if-statement:
...
}
else if (this.file.getBytesLoaded() >= this.file.getBytesTotal() && this.file.getBytesTotal() > 0)
{
...
Othervise you might experience it failing from time to time when run online.
/Mirandir
stringy
November 19th, 2005, 04:43 AM
Just a little improvement on your preloader if-statement:
...
}
else if (this.file.getBytesLoaded() >= this.file.getBytesTotal() && this.file.getBytesTotal() > 0)
{
...
Othervise you might experience it failing from time to time when run online.
/Mirandir
yes thats better
***
most of us would also use an emptyMovieclip.onEnterFrame rather than _root
but if you change, your paths will be different.
You might also put your code inside a function whichyou can call anytime you need to load a movie.
Barn
November 19th, 2005, 02:16 PM
I typically do something like this, where the function will serve for multiple image loads, and the only thing the conditional checks for is if the target movieclip has _width, because that's really all you're waiting for is for the dimensions to be known -- the byte values are irrelevant:
fncImageLoad = function (rfcPath, stgClipName, nbrDepth, stgImgName) {
var rfcClip = rfcPath.createEmptyMovieClip(stgClipName, nbrDepth)
rfcClip.loadMovie(stgImgName);
rfcPath.createEmptyMovieClip("mvcLoad", nbrDepth+1);
mvcLoad.onEnterFrame = function() {
if (rfcClip._width) {
rfcClip._x = (Stage.width-rfcClip._width)/2;
rfcClip._y = (Stage.height-rfcClip._height)/2;
delete this.onEnterFrame;
this.removeMovieClip();
}
};
};
And then to call it:
[code]
fncImageLoad(_root, "file", 0, "someimg.jpg");
[code]
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.