PDA

View Full Version : getBytesTotal on dynamic loaded jpg


oxy
03-26-2003, 10:50 AM
hi,

i downloaded this (http://www.actionscripts.org/showMovie.php?id=42) preloader code from this site
(thx for that btw, it really helped :) )

i changed the code a bit, but it works works perfectly when i load a flashmovie into my empty movieclip.
now here's the problem:
when i load a jpg-image into the movieclip, the getBytesTotal method returns 0 while the image is loading, only when it's completely loaded it returns the size of the image.
(getBytesLoaded method works fine btw)

could it be that flash can't determine the size of a dynamically loaded jpg before it's fully loaded? or is there a way to work around this?

Oxy

CyanBlue
03-26-2003, 11:01 AM
Howdy and Welcome aboard... ;)

Try this thread (http://www.actionscript.org/forums/showthread.php3?s=&threadid=23918) and this thread (http://www.flashkit.com/board/showthread.php?threadid=411677)...

oxy
03-26-2003, 11:41 AM
thx a lot Blue,
not sure i understand all that's said in those threads, but it got me some ideas, so i'm gonna try those now :cool:

CyanBlue
03-26-2003, 11:48 AM
Yes... Take some time to go over those information and try to make them yours... You are welcomed to ask for more detailed questions... ;)

oxy
03-26-2003, 02:45 PM
i read the other threads and tried to "use" some of their code to make it work, but i keep getting same problem. so i'm gonna post code in here, maybe someone can tell me what i do wrong. any help is appreciated ;).

i got an empty movieclip called "container"
and 3 textfields called "total_bytes", "loaded_bytes" and "percent_done"

i got this code on the container-movieclip:
onClipEvent (enterFrame) {
_parent.total_bytes = getBytesTotal();
_parent.loaded_bytes = getBytesLoaded();
_parent.percent_done = int((_parent.loaded_bytes/_parent.total_bytes)*100);
if (_parent.loaded_bytes==_parent.total_bytes) {
set(container._alpha, 100);
}
}


and this code in the first frame of main timeline:
set(_root.container._alpha, 0);
loadMovie("image1.jpg", container);


problem is the total_bytes textfield showing "0" during loading, it only shows the jpg-size when loading is complete :confused: .

i got the .swf uploaded here : (http://www.angelfire.com/wizard/bluerider/preloader_jpg.swf)

Tink
03-26-2003, 03:19 PM
this is working fine!

the problem is that the file is cached on your comp so that soon as it finds the totalBytes the image appears straight away and the bytesLoaded is the same as totalBytes.

delete your temp internet files and then have a look at your file again with the link u provided.

oxy
03-26-2003, 08:04 PM
i tried that before, but it showed me the same. I guess my connection is too fast or something (don't mean to brag ;), but i connect through university-LAN and it's very fast :o)

anyway, i'm glad it seems to work then, and thank you for taking a look at it,

oxy

CyanBlue
03-27-2003, 08:14 AM
Just in case... ;)

Code with setInterval() function...// Code By Helen Triolo //
// Copied from FlashMacromedia Yahoo Group //
MovieClip.prototype.loadjpg = function(picName, holderName)
{
// holderName can be passed in case needed for progress indicator
// if not passed, use 'holder' as default
var h = holderName==undefined ? "holder" : holderName;
this.createEmptyMovieClip(h, 1);
this._visible = false;
this[h].loadMovie(picName);
var id = setInterval(function (mc)
{
if (mc[h].getBytesLoaded() > 1 &&
mc[h].getBytesLoaded() > mc[h].getBytesTotal()-10 &&
mc[h]._width > 0)
{
mc._alpha = 99;
clearInterval(id);
mc._visible = true;
mc.onComplete();
}
else
{
mc.onLoading();
}
}, 80, this);
};

// And call it like this to load and size your image:

x = this.createEmptyMovieClip('xxx', 1);
x.onComplete = function()
{
this._width = whatever;
this._height = whatever;
// continue with movie, either with eg this._parent.gotoAndPlay(n)
// or by sending a broadcast event that a listener will hear
}
x.loadjpg("mypic.jpg"); // holdername parameter not required, but
// can be used if progress indicator needed
stop(); // include if using gotoAndPlay to continue

CyanBlue
03-27-2003, 08:18 AM
Code with onEnterFrame handler...// Code By Helen Triolo //
// Copied from FlashMacromedia Yahoo Group //
MovieClip.prototype.loadjpg = function(picName, holderName)
{
// holderName can be passed in case needed for progress indicator
// if not passed, use 'holder' as default
var h = holderName==undefined ? "holder" : holderName;
this.createEmptyMovieClip(h, 1);
this._visible = false;
this[h].loadMovie(picName);
this.onEnterFrame = function()
{
if (this[h]._width > 0)
{
this._alpha = 99;
delete this.onEnterFrame;
this._visible = true;
this.onComplete();
}
else
{
this.onLoading();
}
}
};

x = this.createEmptyMovieClip("xxx",1);
this.createTextField("yyy", 2, 10, 10, 300, 20);
this.yyy.text = 'here i am';
x.onLoading = function()
{
this._parent.yyy.text = this.hhh.getBytesLoaded() + "/" + this.hhh.getBytesTotal();
}
x.onComplete = function()
{
this._parent.yyy.removeTextField();
var ratio = this._width / this._height;
var newwidth = 100;
this._x = 20;
this._y = 20;
this._width = newwidth;
this._height = newwidth/ratio;
};

x.loadjpg('bigpic.jpg', 'hhh');