so i want to duplicate a movie multiple times. each duplicate i would have to then set some properties for, such as a random location and change the contents of the textbox it contains.
so i thought writing a function would be an easy way to accomplish this. so this is what i tried:
-i is the depth, just to make each movie lay on top of the previous ones.
-newName is the new instance name for the box
-chem is the string that will be entered into the textbox
-it duplicates the movie txt1
[AS]
function dupe(newName, chem){
i++;
dulicateMovieClip(_root.txt1,newName,i);
_root[newName]._x = random(x);
_root[newName]._y = random(y);
_root[newName].htmlText = “<font face=“Verdana” size=”+3">" + chem + “</font>”;
}
[/AS]
so i try to later call the function with
[AS]
dupe(“text2”, “radon”);
[/AS]
but it doesn’t work. am i not specifying the new instance name correctly by using ‘_root[newName]’? or is it something else?
newname A unique identifier for the duplicate movie clip.
depth A unique number specifying the depth at which the movie specified is to be placed.
initObject An object containing properties with which to populate the duplicated movie clip. This parameter allows dynamically created movie clips to receive clip parameters. If initObject is not an object, it is ignored. All properties of initObject are copied into the new instance. The properties specified with initObject are available to the constructor function. This parameter is optional.
Returns
Nothing.
Description
Method; creates an instance of the specified movie clip while the movie is playing. Duplicated movie clips always start playing at Frame 1, no matter what frame the original movie clip is on when the duplicateMovieClip method is called. Variables in the parent movie clip are not copied into the duplicate movie clip. Movie clips that have been created using the duplicateMovieClip method are not duplicated if you call the duplicateMovieMethod on their parent. If the parent movie clip is deleted the duplicate movie clip is also deleted. Movie clips added with duplicateMovieClip can be deleted with removeMovieClip action or method.
yeah it was because of the p. thats kind of sad… lol
and i was using duplicateMovieClip(target, newname,depth)… i guess the older version of the function
duplicateMovieClip
Availability
Flash Player 4.
Usage
duplicateMovieClip(target, newname,depth)
… and so on
and the only difference between Math.random()*x and random(x) is that the former allows for decimals, right? or is it a better function for generating random numbers?
Are you trying to duplicate the TextField, or the MovieClip that contains the TextField?
If you want to duplicate the TextField, you’ll need to define a method to do so. A quick guess:
[AS]TextField.prototype.duplicateTextField = function(newName, depth) {
if (arguments.length<2) return;
this._parent.createTextField(newName, depth, 0, 0, 0, 0);
for (var prop in this) {
this._parent[newName][prop] = this[prop];
}
return this._parent[newName];
};[/AS]
If you want to duplicate the MovieClip that contains the TextField, this line is wrong:
[AS]_root[newName].htmlText = “<font face=“Verdana” size=”+3">"+chem+"</font>";[/AS]
It should read:
[AS]_root[newName].instance.htmlText = “<font face=“Verdana” size=”+3">"+chem+"</font>";[/AS]
Where instance is the instance name of the TextField inside the MovieClip.
createTextField? I didn’t even knew that existed!! You amaze me everytime you post Kode.
Just to throw in my two coins; I don’t know about the text fields, but I put the duplicate command in a function, then all the atributes of whatever I’m duplicating on the movieClip to be duplicated, then it will duplicate the code as well.
This isn’t the best way to do it, though; I’ve been told that it’s disorganized and sloppy; but I’m lazy and find that way easier - Kode will disagree (I remember :P) - good luck!
And the code basically loops through the properties of the TextField, and sets the properties of the newly created TextField equal to the properties of the TextField you want to duplicate. Am I making any sense?