Skip navigation
Currently Being Moderated


Apr 26, 2011 7:42 AM

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:





  • Currently Being Moderated
    Apr 26, 2011 8:11 AM   in reply to TOverturf

    If variablename is supposed to be a String value then use the bracket notation when you want to have a String interpretted as an object...



    Mark as:
  • Currently Being Moderated
    Apr 27, 2011 6:28 AM   in reply to TOverturf

    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...

    Mark as:
  • Currently Being Moderated
    Apr 27, 2011 6:57 AM   in reply to TOverturf

    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)






    this[var1][var2].price.text =.....

    Mark as:
  • Currently Being Moderated
    Apr 27, 2011 7:08 AM   in reply to TOverturf

    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.



    Design Cyboïde

    Création de site web

    Mark as:
  • Currently Being Moderated
    Apr 27, 2011 7:28 AM   in reply to TOverturf

    In general, "this" is a reference to the current timeline.


    trace(this[var1];                    [undefined]


    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.

    Mark as:
  • Currently Being Moderated
    Apr 27, 2011 9:34 AM   in reply to TOverturf

    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.

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points