# \[FMX2\] preloader and visibility

**URL:** <https://forum.kirupa.com/t/fmx2-preloader-and-visibility/38801>\
**Category:** flash\
**Created:** [December 30, 2003, 12:55am UTC](https://forum.kirupa.com/t/fmx2-preloader-and-visibility/38801 "2003-12-30T00:55:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maizoon](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@Maizoon](https://forum.kirupa.com/u/Maizoon)\
**Post date:** [December 30, 2003, 12:55am UTC](https://forum.kirupa.com/t/fmx2-preloader-and-visibility/38801/1 "2003-12-30T00:55:05Z")

</div>

Hello,

I have index.swf which has the following script on frame one:  
[AS]  
\_root.createEmptyMovieClip(“container”, 1000);  
\_root.container.\_visible = 0;  
\_root.createEmptyMovieClip(“preloader”, 1001);  
\_root.container.loadMovie(“content.swf”);  
[/AS]  
then on frame two:  
[AS]  
preloader.onEnterFrame = function() {  
t = \_root.container.getBytesTotal();  
trace(“t=”+t)  
l = \_root.container.getBytesLoaded();  
trace(“l=”+l)  
p = l/t;  
trace (“p=”+p)  
loader.\_width = p\*100;  
if (l\>=t) {  
\_root.container.\_visible = 1;  
trace(“done”)  
delete this.onEnterFrame;  
}  
};  
stop();  
[/AS]  
It works like it should, minus the fact that at about 35% (60k out of 153k) it shows the content.swf. This doesn’t make any sense because container (the MC holding content.swf) is set to to be invisible until l = t (loaded = total). I’ve been tweaking this for hours and can’t for the life of me figure out why its showing the container prematurly and why its ignoring my \_visible tags

---

<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:** [December 30, 2003, 3:20am UTC](https://forum.kirupa.com/t/fmx2-preloader-and-visibility/38801/2 "2003-12-30T03:20:38Z")

</div>

Try:

```auto
this.createEmptyMovieClip("container", 1000);
this.createEmptyMovieClip("preloader", 1001);
container.loadMovie("content.swf");
preloader.onEnterFrame = function() {
	var t, l, p;
	t = container.getBytesTotal();
	l = container.getBytesLoaded();
	p = l/t;
	trace("t="+t);
	trace("l="+l);
	trace("p="+p);
	if (l) {
		container._visible = 0;
		loader._width = p*100;
		if (l == t) {
			container._visible = 1;
			trace("done");
			delete this.onEnterFrame;
		}
	}
};
stop();

```

---

<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:** [December 30, 2003, 3:58am UTC](https://forum.kirupa.com/t/fmx2-preloader-and-visibility/38801/3 "2003-12-30T03:58:09Z")

</div>

sweet thanks…so putting that if (l) block is what makes this work on one frame…and make it visible/invisible? Why did my code not work as i thought it should have?

---

<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:** [December 30, 2003, 4:04am UTC](https://forum.kirupa.com/t/fmx2-preloader-and-visibility/38801/4 "2003-12-30T04:04:47Z")

</div>

Because you set the visible property to false and then you loaded some movie into it. When that happens, the visible property is set back to true.
