When a duplicate a mc, I am testing two functions.
The onPress works great it returns each mc, but when I try to use the onEnterFrame function my returning value is always the first mc. Can anyone explain?
Printable View
When a duplicate a mc, I am testing two functions.
The onPress works great it returns each mc, but when I try to use the onEnterFrame function my returning value is always the first mc. Can anyone explain?
Here is a simple example. I added a dynamic text to a frame then converted it to a mc. I added another dynamic text for debugging.
The onPress function works fine. It returns the number for each mc.
The onEnterFrame function only returns the first mc text.
Can anyone expand on the problem, please?
Or maybe it is just the differences in the functions. I would like to be able to return the value of each mc as I change the text.
for (i=0; i <= 2; i++){
mc1.duplicateMovieClip("mc1"+i, i+10);
dt=this["mc1"+i];
dt._x=i*50;
dt._y=20;
dt.txt1.text=i;
//dt.onPress = function() {
dt.onEnterFrame = function(){
txt1.text = this.txt1.text;
}
}
stop();
I mergered your two threads. Please keep everything pertaining to your question in the same thread...
As to your problem I imagine it's this lineThe scope of txt1 would be the same as this.txt1 I guessing that's not what you intend here. I imagine you have a txt1 on the root timeline so you want to refer to it via _root.txt1 or _parent.txt1Code:txt1.text = this.txt1.text;
The (txt1.text = this.txt1.text) line can be changed to (debug.text = this.txt1.text). The > indicates differences.
The question is why does this work.
for (i=0; i <= 2; i++){
mc1.duplicateMovieClip("mc1"+i, i+10);
dt=this["mc1"+i];
dt._x=i*50;
dt._y=20;
dt.txt1.text=i;
> dt.onPress(){
debug.text = this.txt1.text;
}
}
Which returns 1 in the debug.text when I click the first mc, and 2 when I click the second mc in the debug.text.
This does not work:
for (i=0; i <= 2; i++){
mc1.duplicateMovieClip("mc1"+i, i+10);
dt=this["mc1"+i];
dt._x=i*50;
dt._y=20;
dt.txt1.text=i;
> dt.onEnterFrame = function(){
debug.text = this.txt1.text;
}
}
This returns the 1 in the debug window when I click the first mc and 1 when I click the second mc, which indicates that the only onEnterFrame being entered is the first mc. How do can I get the onPress to behave like the onEnterFrame?
well if you have several different mc's all setting the text in the same text field I would expect it to always show the last one or maybe the first one to get there...
To test this try changing
debug.text = this.txt1.text;
to
debug.text += "my number is "+this.txt1.text;
that way you are adding to the text box and not overwriting it I think you'll get something like
my number is 1mynumber is 2
over and over again
I now understand what is happening. Each movie clip keeps playing.
thanks for your help