5 Replies Latest reply on Jan 13, 2013 11:39 AM by kglad

    Bracket notation

    TOverturf Level 1

      According to my memory this:

       

      textData = jsessionLoader.data;

       

      and this:

       

      var loaderName:String = "jsessionLoader";

       

      textData = [loaderName].data;

       

      Should amount to the same thing, apparently Flash doesn't agree. =P

       

      What am I doing wrong?

        • 1. Re: Bracket notation
          kglad Adobe Community Professional & MVP

          there's no scope assigned to your array notation.  use:

           

          textData=this[loaderName].data;  // assuming "this" is the correct scope.

          • 2. Re: Bracket notation
            TOverturf Level 1

            Already tried that, flash throws this error:

             

            TypeError: Error #1010: A term is undefined and has no properties.

                      at MethodInfo-397()

                      at flash.events::EventDispatcher/dispatchEventFunction()

                      at flash.events::EventDispatcher/dispatchEvent()

                      at flash.net::URLLoader/onComplete()

             

            Got a quick tip on how I can define/get the scope?

            • 3. Re: Bracket notation
              kglad Adobe Community Professional & MVP

              copy and paste your code showing your loader's data property is defined and the code using a string and array notation trying to access your loader's data.

              • 4. Re: Bracket notation
                TOverturf Level 1

                var fl_TextLoader:URLLoader = new URLLoader();

                var fl_TextURLRequest:URLRequest = new URLRequest("http://google.com");

                 

                 

                function loadSession(loaderText:String):void

                {

                          this[loaderText].addEventListener(Event.COMPLETE, completeHandler);

                 

                 

                          function completeHandler(event:Event):void

                          {

                                    trace([loaderText].data);

                          }

                          fl_TextLoader.load(fl_TextURLRequest);

                }

                 

                 

                loadSession("fl_TextLoader");

                 

                As soon as I replace trace([loaderText].data) with trace(fl_TextLoader.data) everthing check outs.

                • 5. Re: Bracket notation
                  kglad Adobe Community Professional & MVP

                  you are nesting named functions.  that is always problematic.

                   

                  use:

                   

                   

                   

                   

                  var fl_TextLoader:URLLoader = new URLLoader();

                  var fl_TextURLRequest:URLRequest = new URLRequest("http://google.com");

                  var s:String;

                   

                   

                  function loadSession(loaderText:String):void

                  {

                  s=loaderText;

                            this[loaderText].addEventListener(Event.COMPLETE, completeHandler);

                   


                            fl_TextLoader.load(fl_TextURLRequest);

                  }

                   

                            function completeHandler(event:Event):void

                            {

                                      trace(this[s].data);

                            }

                   

                   

                  loadSession("fl_TextLoader");