7 Replies Latest reply on Dec 3, 2008 1:55 PM by Newsgroup_User

    onData doesn't load from within class function

    Level 7

      This isn't my actual code, just trying to demonstrate what I'm trying to
      accomplish.
      Any suggestions?

      //Call class method
      var exampleCls = new exampleClass();
      exampleCls.exampleFunction();


      //Class
      class exampleClass{

      public var my_lv:LoadVars;

      //Constructor
      function exampleClass{
      my_lv = new LoadVars();
      }

      public function exampleFunction(){
      my_lv.onData = function(src:String) {
      trace("This never loads...");
      };

      my_lv.load(" http://"+ Host +"/test.html",my_lv, "GET");

      }


        • 1. Re: onData doesn't load from within class function
          clbeech Level 3
          it's difficult to tell exactly 'what' it is you're trying to load here, a HTML page will not provide a 'return' that will be compatible with a 'String' object. you need to call to another type of document like PHP or ASP that echoes a return value. secondly, the 'load' method of the LoadVars class, requires a single parameter. for this type of call you would use the sendAndLoad() method, even if you are only retrieving the variable, but using the 'GET' method.
          • 2. Re: onData doesn't load from within class function
            Level 7
            I think you missed my question.

            > it's difficult to tell exactly 'what' it is you're trying to load here, a
            > HTML
            > page will not provide a 'return' that will be compatible with a 'String'
            > object. you need to call to another type of document like PHP or ASP that
            > echoes a return value.

            Yes it will. A page extension has little to nothing to do with the fact that
            a string will always be returned. A string is a string. What are you talking
            about?


            "clbeech" <webforumsuser@macromedia.com> wrote in message
            news:gh1o01$f87$1@forums.macromedia.com...
            > it's difficult to tell exactly 'what' it is you're trying to load here, a
            > HTML
            > page will not provide a 'return' that will be compatible with a 'String'
            > object. you need to call to another type of document like PHP or ASP that
            > echoes a return value. secondly, the 'load' method of the LoadVars class,
            > requires a single parameter. for this type of call you would use the
            > sendAndLoad() method, even if you are only retrieving the variable, but
            > using
            > the 'GET' method.
            >


            • 3. Re: onData doesn't load from within class function
              Level 7
              Sorry for being rude.. been trying get this resolved for a while and I can't
              seem to get
              an answer.

              "clbeech" <webforumsuser@macromedia.com> wrote in message
              news:gh1o01$f87$1@forums.macromedia.com...
              > it's difficult to tell exactly 'what' it is you're trying to load here, a
              > HTML
              > page will not provide a 'return' that will be compatible with a 'String'
              > object. you need to call to another type of document like PHP or ASP that
              > echoes a return value. secondly, the 'load' method of the LoadVars class,
              > requires a single parameter. for this type of call you would use the
              > sendAndLoad() method, even if you are only retrieving the variable, but
              > using
              > the 'GET' method.
              >


              • 4. Re: onData doesn't load from within class function
                Rothrock Level 5
                I have no problem. I put this in my FLA:

                var myTL:TestLoader=new TestLoader();
                myTL.loadData("testfile.txt");

                I create a utf text file that contains:

                val="Hello world."

                And the AS file is below. I could only get onData or onLoad to work at a time. It also worked perfectly fine with a random html that I found on my hard drive.
                • 5. Re: onData doesn't load from within class function
                  clbeech Level 3
                  Tim - "Yes it will. A page extension has little to nothing to do with the fact that a string will always be returned. A string is a string. What are you talking about?"

                  well it most certainly does have everything to do with it. true, the html CODE will be returned as a 'String' of HTML tags - but for instance a PHP (an extension) will not necessary return anything unless the program specifically is told to do so - just one example.

                  however, my point, which you obviously missed, and that I also did not state very clearly, was that Flash supports on a 'few' html tags - which does NOT include the html, body or head tags as well as the html header. this is saying that if you load an html 'page' the values will basically be useless. now, this is altogether different if you are loading an html formatted 'string'.

                  additionally, you failed to comment on the 'fact' that you are using the wrong parameters in the load method.

                  Rothrock's code works perfectly, as usual ;)
                  • 6. Re: onData doesn't load from within class function
                    Level 7

                    Thank you. I had a different issue with variable scoping.


                    "Rothrock" <webforumsuser@macromedia.com> wrote in message
                    news:gh296c$55u$1@forums.macromedia.com...
                    >I have no problem. I put this in my FLA:
                    >
                    > var myTL:TestLoader=new TestLoader();
                    > myTL.loadData("testfile.txt");
                    >
                    > I create a utf text file that contains:
                    >
                    > val="Hello world."
                    >
                    > And the AS file is below. I could only get onData or onLoad to work at a
                    > time.
                    > It also worked perfectly fine with a random html that I found on my hard
                    > drive.
                    >
                    > class TestLoader{
                    >
                    > private var _myLV:LoadVars;
                    >
                    > public function TestLoader(){
                    > _myLV=new LoadVars();
                    > trace("Constructed");
                    > }
                    >
                    > public function loadData(file:String){
                    > _myLV.onLoad=myLoad
                    > //_myLV.onData=myData
                    > _myLV.load(file);
                    > trace("loading");
                    > }
                    >
                    > private function myLoad(success:Boolean){
                    > trace("Loaded: "+success);
                    > }
                    >
                    > private function myData(str:String){
                    > trace("Got data: " + str);
                    > }
                    > }
                    >


                    • 7. Re: onData doesn't load from within class function
                      Level 7
                      Once again, sorry for being rude as I was getting impatient. That was more
                      or less pseudo code to demonstrate what I was trying to do. I wasn't really
                      asking about recognizing html tags. You are correct about the GET
                      parameter..
                      not sure why I had it in there.

                      Thank you



                      "clbeech" <webforumsuser@macromedia.com> wrote in message
                      news:gh3qkj$5hc$1@forums.macromedia.com...
                      > Tim - "Yes it will. A page extension has little to nothing to do with the
                      > fact
                      > that a string will always be returned. A string is a string. What are you
                      > talking about?"
                      >
                      > well it most certainly does have everything to do with it. true, the html
                      > CODE
                      > will be returned as a 'String' of HTML tags - but for instance a PHP (an
                      > extension) will not necessary return anything unless the program
                      > specifically
                      > is told to do so - just one example.
                      >
                      > however, my point, which you obviously missed, and that I also did not
                      > state
                      > very clearly, was that Flash supports on a 'few' html tags - which does
                      > NOT
                      > include the html, body or head tags as well as the html header. this is
                      > saying
                      > that if you load an html 'page' the values will basically be useless.
                      > now,
                      > this is altogether different if you are loading an html formatted
                      > 'string'.
                      >
                      > additionally, you failed to comment on the 'fact' that you are using the
                      > wrong
                      > parameters in the load method.
                      >
                      > Rothrock's code works perfectly, as usual ;)
                      >