# Target loading

**URL:** <https://forum.kirupa.com/t/target-loading/5772>\
**Category:** Uncategorized\
**Created:** [September 21, 2002, 1:00pm UTC](https://forum.kirupa.com/t/target-loading/5772 "2002-09-21T13:00:00Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jerry](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@jerry](https://forum.kirupa.com/u/jerry)\
**Post date:** [September 21, 2002, 1:00pm UTC](https://forum.kirupa.com/t/target-loading/5772/1 "2002-09-21T13:00:00Z")

</div>

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

---

<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:** [September 21, 2002, 4:30pm UTC](https://forum.kirupa.com/t/target-loading/5772/2 "2002-09-21T16:30:42Z")

</div>

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.

---

<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:** [September 21, 2002, 5:10pm UTC](https://forum.kirupa.com/t/target-loading/5772/3 "2002-09-21T17:10:37Z")

</div>

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](http://www.actionscript-toolbox.com/samplemx_loadjpg.php) to see how it works.

pom :asian:

---

<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:** [September 21, 2002, 5:16pm UTC](https://forum.kirupa.com/t/target-loading/5772/4 "2002-09-21T17:16:23Z")

</div>

Basically, [SIZE=1]for the people that are too lazy to check the site[/SIZE], you can do it like that:

```auto
_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:

---

<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:** [September 21, 2002, 5:28pm UTC](https://forum.kirupa.com/t/target-loading/5772/5 "2002-09-21T17:28:48Z")

</div>

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.

---

<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:** [September 21, 2002, 6:46pm UTC](https://forum.kirupa.com/t/target-loading/5772/6 "2002-09-21T18:46:54Z")

</div>

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?

---

<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:** [September 21, 2002, 7:23pm UTC](https://forum.kirupa.com/t/target-loading/5772/7 "2002-09-21T19:23:25Z")

</div>

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

pom 😛 😛

---

<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:** [September 21, 2002, 7:30pm UTC](https://forum.kirupa.com/t/target-loading/5772/8 "2002-09-21T19:30:42Z")

</div>

Or Harry, as you wish 😛

---

<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:** [September 22, 2002, 9:12am UTC](https://forum.kirupa.com/t/target-loading/5772/9 "2002-09-22T09:12:38Z")

</div>

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

---

<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:** [September 22, 2002, 9:50am UTC](https://forum.kirupa.com/t/target-loading/5772/10 "2002-09-22T09:50:35Z")

</div>

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