10 Replies Latest reply on Apr 27, 2011 9:34 AM by Ned Murphy


    TOverturf Newcomer

      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:





        • 1. Re: Variables
          Ned Murphy Legend

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



          1 person found this helpful
          • 2. Re: Variables
            TOverturf Newcomer

            Hey Ned,


            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?

            • 3. Re: Variables
              Ned Murphy Legend

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

              1 person found this helpful
              • 4. Re: Variables
                TOverturf Newcomer

                now I have:


                var var1:String = "mc1"

                var var2:String = "mc2"

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


                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:completeConfiguration()[ruse_fla.Main Timeline::frame1:114]

                at flash.events::EventDispatcher/dispatchEventFunction()

                at flash.events::EventDispatcher/dispatchEvent()

                at flash.net::URLLoader/onComplete()



                • 5. Re: Variables
                  Ned Murphy Legend

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

                  • 6. Re: Variables
                    Cyboide Pioneer

                    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

                    • 7. Re: Variables
                      TOverturf Newcomer

                      trace(this);                         [object global]                                

                      trace(this[var1];                    [undefined]


                      Im still not quite sure what the "this" thing means. Could you explain?



                      • 8. Re: Variables
                        Ned Murphy Legend

                        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.

                        • 9. Re: Variables
                          TOverturf Newcomer

                          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.

                          • 10. Re: Variables
                            Ned Murphy Legend

                            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.