# \[fmx\] attachMovie code help

**URL:** <https://forum.kirupa.com/t/fmx-attachmovie-code-help/20121>\
**Category:** Uncategorized\
**Created:** [May 5, 2003, 4:44pm UTC](https://forum.kirupa.com/t/fmx-attachmovie-code-help/20121 "2003-05-05T16:44:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![eudora](https://avatars.discourse-cdn.com/v4/letter/e/f14d63/32.png) [@eudora](https://forum.kirupa.com/u/eudora)\
**Post date:** [May 5, 2003, 4:44pm UTC](https://forum.kirupa.com/t/fmx-attachmovie-code-help/20121/1 "2003-05-05T16:44:56Z")

</div>

myMovieClip.attachMovie(idName, newName, depth [, initObject] )

for the initObject  
i place it somewhere inside the main timeline… so i call it entry

is this correct?  
myMovieClip.attachMovie(idName, newName, depth , \_root.entry )

if so… i left an action on this movieclip entry… am i rite to say all the other movieclips which i attach will also have this action??

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:** [May 5, 2003, 4:54pm UTC](https://forum.kirupa.com/t/fmx-attachmovie-code-help/20121/2 "2003-05-05T16:54:42Z")

</div>

the init object is an object (not a movieclip - though technically a movieclip COULD work) whos properties get copied into the attached object. For most purposes, its best used to easily position a movieclip as soon as its attached like:

```auto
myMovieClip.attachMovie("mylibraryClip", clipA, 1, {_x: 100, _y: 200})

```

This will place the clip immediately at the location 100, 200. You can use any movieclip property or any variable you want though.

---

<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:** [May 5, 2003, 4:56pm UTC](https://forum.kirupa.com/t/fmx-attachmovie-code-help/20121/3 "2003-05-05T16:56:42Z")

</div>

oic… so my concept of it is wrong… then is it possible to put onPress codes for this movieclip?

---

<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:** [May 5, 2003, 4:58pm UTC](https://forum.kirupa.com/t/fmx-attachmovie-code-help/20121/4 "2003-05-05T16:58:45Z")

</div>

yes it is 🙂

```auto

whenPressed = function(){
    trace("pressed!");
}
myMovieClip.attachMovie("mylibraryClip", clipA, 1, {onPress:whenPressed});

```

---

<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:** [May 5, 2003, 5:01pm UTC](https://forum.kirupa.com/t/fmx-attachmovie-code-help/20121/5 "2003-05-05T17:01:27Z")

</div>

🙂  
thanks!  
er… is that the exact codes?  
onPress:functionName  
?  
is it like placing an object properties or functionswithin the 2 curly brackets??

---

<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:** [May 5, 2003, 5:14pm UTC](https://forum.kirupa.com/t/fmx-attachmovie-code-help/20121/6 "2003-05-05T17:14:38Z")

</div>

yeah there are basically two ways to make generic objects. You can use  
myObj = new Object()  
or  
myObj = {}  
the second version is the shorthand version, similar to [] for an array and “” for a string. You dont need to use new Array() or new String() to make a new array or string, you can use just [] or “”. Like with Arrays (or strings for that matter) you can specify the contents of that array by adding in values between those brackets. With an array it would be something like  
myArray = [value1, value2, … valueN]  
Objects however, arent numbered like arrays, They use a variable name to reference their values so in the object shorthand form, you can specify those values using the variableName, colon, value or  
myObj = {variable1:value1, variable2:value2, … variableN:valueN}  
this would be the same as saying  
myObj = new Object();  
myObj.variable1 = value1;  
myObj.variable1 = value1;  
…  
myObj.variableN = valueN;  
just a shorter easier way of doing it, and all in one line. Doing it all in one line makes it easier for use in the attachMovie function because the object is set right there. You dont have to set it there though, you could use some other object you might have already made:

```auto

myObj = new Object();
myObj._x = 100;
myObj._y = 200;
...
myMovieClip.attachMovie("mylibraryClip", clipA, 1, myObj);

```

and you’re all set!

---

<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:** [May 5, 2003, 5:16pm UTC](https://forum.kirupa.com/t/fmx-attachmovie-code-help/20121/7 "2003-05-05T17:16:23Z")

</div>

icic thanks for the detail explanation… 🙂
