jerry
September 21, 2002, 1:00pm
1
hey!
I’m loading a movie into target like this:
[COLOR=royalblue]_root.createEmptyMovieClip(“container”, 1);
loadMovie(“loaded.swf”, “container”);
container._x = 150 ;
container._y = 20 ;[/COLOR]
is there any way of putting a preloader, who displays the percent loaded, inside the main movie instead of the loaded movie!?
system
September 21, 2002, 4:30pm
2
Not that I know of.
You can’t preload something that isn’t there. So since your .swf file will not originally be included into your main movie, you will not be able to preload it from there.
system
September 21, 2002, 5:10pm
3
Of course you can!
You can’t preload something that isn’t there
So how can you preload anything then??
You can have a look at this excellent article on actionscript-toolbox.com to see how it works.
pom :asian:
system
September 21, 2002, 5:16pm
4
Basically, [SIZE=1]for the people that are too lazy to check the site[/SIZE], you can do it like that:
_root.createEmptyMovieClip("container", 1);
_root.container.loadMovie("loaded.swf");
_root.onEnterFrame = function() {
l=this.container.getBytesLoaded();
t=this.container.getBytesTotal();
if (l > 1 && l >= t) {
delete this.onEnterFrame;
this.container._x = 150 ;
this.container._y = 20 ;
}
}
Very useful piece of code.
pom :asian:
system
September 21, 2002, 5:28pm
5
Ok, that just totally made me a newbie.
I thought he was talking about an actual graphical preloader such as a loading bar. But I suppose with that code you could even do that, it would just take a little more tweeking.
system
September 21, 2002, 6:46pm
6
Yes. Someone had a similar problem, where, when loading into an empty movie clip - their preloader always showed, loaded, because they were targeting _root, instead of the container; Moral of the story: you can specify a target for getBytesLoaded just as you would _root.container.gotoAndStop();.
So Pom, do I call you Hannibal or Pom?
system
September 21, 2002, 7:23pm
7
Let’s not confuse people, Flex Just call me Dr Evil…
pom
system
September 22, 2002, 9:12am
9
THX for your help guys!
BUT can someone please tell me why I can’t load my sound file this way?
The loaded.swf contains some music:
[COLOR=royalblue]firstSound=new Sound()
firstSound.attachSound(“trance”)
_root.firstSound.start(0,999)[/COLOR]
the file get’s loaded but I can’t hear the music!??
system
September 22, 2002, 9:50am
10
NEVERMIND I’m using this instead:
[COLOR=royalblue]myMusic = new Sound(myMusicMc);
myMusic.loadSound(“sound.mp3”,false);
myMusic.start(0,999);[/COLOR]
but could someone tell me how to make a percentage preloader out of this:
[COLOR=royalblue]_root.createEmptyMovieClip(“container”, 1);
_root.container.loadMovie(“loaded.swf”);
_root.onEnterFrame = function() {
l=this.container.getBytesLoaded();
t=this.container.getBytesTotal();
if (l > 1 && l >= t) {
delete this.onEnterFrame;
this.container._x = 150 ;
this.container._y = 20 ;
}
}[/COLOR]
…something like:
[COLOR=royalblue]_root.createEmptyMovieClip(“container”, 1);
_root.container.loadMovie(“sound.swf”);
_root.onEnterFrame = function() {
l=this.container.getBytesLoaded();
t=this.container.getBytesTotal();
percent = Math.round((l/t)*100)+"%";
if (l > 1 && l >= t) {
delete this.onEnterFrame;
this.container._x = 0 ;
this.container._y = 0 ;
}
}[/COLOR]??
…but using the above I get a nan% …?