Hey Guys, I have one string variable that change when I push a button. Now usually when I add an eventlisenter to a movieclip I do this:
But now the variable is holding the name of the Mc to which to listener should be added. I tried this:
Thanks, but it works partly. Simply adding an event listener works, but farther down in my code I have this:
this[unitNumberUrl].price.text = price;
The unitNumberUrl is a string and looks something like this "mc1.mc2", but it doesnt work. Ideas?
Yep, you can't use strings like that with the bracket notation. Each bracket set can only represent one object "mc1.mc2" is trying to represent two of them.
You can do this["mc1"]["mc2"].etc.... but not this["mc1.mc2"].etc...
now I have:
var var1:String = "mc1"
var var2:String = "mc2"
But it still gives me the same error.
TypeError: Error #1010: A term is undefined and has no properties.
at Function/ruse_fla:MainTimeline/onBtnCClick/ruse_fla:completeConfigura tion()[ruse_fla.MainTimeline::frame1:114]
Try using traces to see where it is falling out. The error message will indicate which line of code is causing the problem (currently indicates line 114)
I see you want to have "values" changed dynamicaly with only a few lines of code. That's always the goal.
But I was wondering if you thought of using the MovieClip's main caracteristic, which is being a dynamic class. I do not see your whole code, but maybe you could think about storing the actual Textfields or movieclips as the buttons' properties. Inside your MouseEvent function, you could target them, (maybe) more easily.
In general, "this" is a reference to the current timeline.
Aside from a typo in the code, the [undefined] is indicating you have an issue with the object you are trying to target It doesn't exist. You need to be sure you've named "mc1" by that name and that it is present when that code executes.
Ok, I remove the "this" code:
trace(this[var1]) ---> trace([var1])
and It worked! So I changed my code
[var1][var2].price.text = price;
But I got the 1084: Syntax error:expecting identifier before dot.
Yep, you need to have some kind of targeting lead-in for the bracket notation to work, and "this" is usually a workable option.
When you use trace([var1]) you are merely tracing the elements of an array you just created when you used [var1] alone.
The problem you seem to have is that you do not have an object on the stage when that code executes that has the instance name "mc1" assigned to it.
If you replace
you'll probably still be getting the error, though it might turn into a 1009 error. If so, that's indicating for certain that there is no object named mc1 around where that code is.
Europe, Middle East and Africa