Target loading

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!?

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.

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:

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:

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.

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?

Let’s not confuse people, Flex :stuck_out_tongue: Just call me Dr Evil…

pom :stuck_out_tongue: :stuck_out_tongue:

Or Harry, as you wish :stuck_out_tongue:

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!??

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%…?