[fmx] attachMovie code help

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

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:

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.

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

yes it is :slight_smile:


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

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

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:


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

and you’re all set!

icic thanks for the detail explanation… :slight_smile: