# Code on MC's created with createEmptyMovieClip

**URL:** https://forum.kirupa.com/t/code-on-mcs-created-with-createemptymovieclip/28598
**Category:** flash
**Created:** [August 15, 2003, 2:26pm UTC](https://forum.kirupa.com/t/code-on-mcs-created-with-createemptymovieclip/28598 "2003-08-15T14:26:16Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![jillymo](https://avatars.discourse-cdn.com/v4/letter/j/5f9b8f/32.png) [@jillymo](https://forum.kirupa.com/u/jillymo)
#### Post date: [August 15, 2003, 2:26pm UTC](https://forum.kirupa.com/t/code-on-mcs-created-with-createemptymovieclip/28598/1 "2003-08-15T14:26:16Z")

</div>

Is there any way to put code on an mc created with createEmptyMovieClip?

---

<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: [August 15, 2003, 3:04pm UTC](https://forum.kirupa.com/t/code-on-mcs-created-with-createemptymovieclip/28598/2 "2003-08-15T15:04:58Z")

</div>

hmm. i dont know for sure but you might try like this, saying your mc was holder.

```auto

holder.onClipEvent(load){
play();
}

```

you know? something like that MIGHT work, i dont have flash in front of me so i dont know, but i am assuming thats how you would do it.

---

<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: [August 15, 2003, 3:13pm UTC](https://forum.kirupa.com/t/code-on-mcs-created-with-createemptymovieclip/28598/3 "2003-08-15T15:13:21Z")

</div>

Yes. Just do it as you would with a normal mc that you made yourself.

Regards,  
Viru.

---

<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: [August 15, 2003, 3:15pm UTC](https://forum.kirupa.com/t/code-on-mcs-created-with-createemptymovieclip/28598/4 "2003-08-15T15:15:46Z")

</div>

thank you

:geek:

---

<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: [August 15, 2003, 6:04pm UTC](https://forum.kirupa.com/t/code-on-mcs-created-with-createemptymovieclip/28598/5 "2003-08-15T18:04:11Z")

</div>

okay I am now attempting to target the clip with this code:  
\<hr\>  
this.createEmptyMovieClip(“clip1”, 1);  
clip1.loadMovie(“welcome.swf”);  
clip1.\_x = 320 ;  
clip1.\_y = 320 ;

\<b\>this.“clip1”.onClipEvent(enterFrame)\</b\>{  
percentloaded=Math.floor(\_level1.getBytesLoaded()/\_level1.getBytesTotal()\*100)  
percentdisplay=percentloaded + "%"  
if(percentloaded == 100 && !initialized){  
play();  
initialized=true  
\_visible=false  
}  
}  
\<hr\>

and I am getting this error:

Scene=Scene 1, Layer=script, Frame=4: Line 43: Expected a field name after ‘.’ operator.  
this.“clip1”.onClipEvent (enterFrame){

Any thoughts as to what field name is expected? I do not understand what I am need to do here…

---

<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: [August 15, 2003, 6:30pm UTC](https://forum.kirupa.com/t/code-on-mcs-created-with-createemptymovieclip/28598/6 "2003-08-15T18:30:50Z")

</div>

I think it should be

```auto

MovieClip.clip1.onClipEvent(enterFrame){
etc..

```

Regards,  
Viru

---

<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: [August 15, 2003, 6:32pm UTC](https://forum.kirupa.com/t/code-on-mcs-created-with-createemptymovieclip/28598/7 "2003-08-15T18:32:34Z")

</div>

okay viru, you have given great advice so far so I am sure it will work

:}

I will test it out

Thanks!

---

<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: [August 15, 2003, 6:34pm UTC](https://forum.kirupa.com/t/code-on-mcs-created-with-createemptymovieclip/28598/8 "2003-08-15T18:34:49Z")

</div>

Well I tried it and I am still getting the same message :crazy:

---

<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: [August 15, 2003, 6:36pm UTC](https://forum.kirupa.com/t/code-on-mcs-created-with-createemptymovieclip/28598/9 "2003-08-15T18:36:10Z")

</div>

ok, sorry that was just the first thing i thought you should try. Is it possible to post your fla?

Viru.

---

<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: [August 15, 2003, 6:39pm UTC](https://forum.kirupa.com/t/code-on-mcs-created-with-createemptymovieclip/28598/10 "2003-08-15T18:39:46Z")

</div>

Ok, hit me, i wasnt thinking straight, i’m pretty sure this will work,

```auto

Movieclip.clip1.onEnterFrame = function() {
//write the code you want to happen on each enterframe here.
}

```

Regards,  
Viru.

---

<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: [August 15, 2003, 6:41pm UTC](https://forum.kirupa.com/t/code-on-mcs-created-with-createemptymovieclip/28598/11 "2003-08-15T18:41:18Z")

</div>

no it is a really big file - I guess I could try deleted some of the unactive artwork and zipping it.

when you test the movie the external movie clips will not show up though…

this is my trouble- I am trying to put preloaders on the external swf’s without actually putting them in the swf’s themselves. I do not have that luxory as they are made with Wildform FX (text program) and it only outputs swf’s that you cannot add code to…

---

<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: [August 15, 2003, 6:46pm UTC](https://forum.kirupa.com/t/code-on-mcs-created-with-createemptymovieclip/28598/12 "2003-08-15T18:46:15Z")

</div>

okay so like this:

code:  
\<hr\>  
this.createEmptyMovieClip(“clip1”, 1);  
clip1.loadMovie(“welcome.swf”);  
clip1.\_x = 320 ;  
clip1.\_y = 320 ;

Movieclip.clip1.onEnterFrame = function() {  
percentloaded=Math.floor(\_level1.getBytesLoaded()/\_level1.getBytesTotal()\*100)  
percentdisplay=percentloaded + "%"  
if(percentloaded == 100 && !initialized){  
play();  
initialized=true  
\_visible=false  
}  
}  
\<hr\>

when I want to call the function I say?

Movieclip.clip1.onEnterFrame ();

I’m not sure. I am not very advanced in my as…if you couldn’t tell by my millions of questions…  
(-:

---

<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: [August 15, 2003, 6:51pm UTC](https://forum.kirupa.com/t/code-on-mcs-created-with-createemptymovieclip/28598/13 "2003-08-15T18:51:04Z")

</div>

I dont think you can call it like that. But its worth a try first. It that doesnt work create a function like this that you can call:

```auto

Movieclip.clip1. **preloaderFunc** = function() {
percentloaded=Math.floor(_level1.getBytesLoaded()/_level1.getBytesTotal()*100)
percentdisplay=percentloaded + "%"
if(percentloaded == 100 && !initialized){
play();
initialized=true
_visible=false
}
}

```

And call it with

```auto
Movieclip.clip1.preloaderFunc();

```

Regards,  
Viru.

P.S I’m still learning too 🙂

---

<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: [August 15, 2003, 6:52pm UTC](https://forum.kirupa.com/t/code-on-mcs-created-with-createemptymovieclip/28598/14 "2003-08-15T18:52:33Z")

</div>

[AS]\_root.createEmptyMovieClip(“clip1”, 1);  
clip1.\_x = 320 ;  
clip1.\_y = 320 ;  
clip1.onEnterFrame = function() {  
if (this.\_url != \_root.\_url) {  
\_root.preload(this);  
}  
}

```auto

```

function preload(clip) {  
if (!loaded) {  
if (clip.getBytesLoaded\>0 && clip.getBytesLoaded\>=clip.getBytesTotal) {  
loaded = true;  
}  
var percent = (clip.getBytesLoaded()/clip.getBytesTotal());  
loadBar.\_width = 100\*percent; //replace 100 for your loadbar width  
}  
}  
clip1.loadMovie(“welcome.swf”);

```auto

```

---

<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: [August 15, 2003, 7:00pm UTC](https://forum.kirupa.com/t/code-on-mcs-created-with-createemptymovieclip/28598/15 "2003-08-15T19:00:42Z")

</div>

well viru it doesn’t seem to be working-

There are NO problems or errors with your code, I think the error lies within the code I was trying to use to get the preload working.

So I thank you because what you came up with is right-

Claudio I am going to have a look at what you have here. I was looking at your tutorial about preloading external swf’s with transition and trying to apply that to what I need to do. I was not able to do so and was hoping maybe you would write one without the transition 😉

I thank you both!

---

<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: [August 15, 2003, 7:07pm UTC](https://forum.kirupa.com/t/code-on-mcs-created-with-createemptymovieclip/28598/16 "2003-08-15T19:07:02Z")

</div>

Your welcome. And Claudio is very good, i’m sure anything he/she says will help you to no end.

V.

---

<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: [August 15, 2003, 7:09pm UTC](https://forum.kirupa.com/t/code-on-mcs-created-with-createemptymovieclip/28598/17 "2003-08-15T19:09:14Z")

</div>

Yes Claudio provided great code but I am thinking that it is possibly preloading the movie clip (“clip 1”) and not the actual content that gets loaded into the clip.

Maybe I did not make my goal clear, or I could be wrong but it seems as though that is what it is doing…

:bounce:
