4 Replies Latest reply on Jan 20, 2007 8:03 AM by Peter Lorent

    why flash parsed the original text ?

    AlMostabed
      hi all :)


      i need to know why flash parsed the original text/raw text when i used onLoad event in LoadVars ? when i used onData & onLoad event handler & why ?

      regards,
      AlMostabed
        • 1. Re: why flash parsed the original text ?
          digitellinc
          Post the text, and the code you are using please or examples so we can better assist you.
          • 2. Re: why flash parsed the original text ?
            AlMostabed Level 1
            ok digitellinc look at this explanation :

            what's the deference between onData & onLoad ?

            onData is pre-parsed. onLoad is parsed.

            what does 'parsed' mean ?

            it means taking a string and breaking it down into smaller parts or somehow transforming it into a more complex object based on some kind of recognition process. So, for example, when dealing with LoadVars, you load content from a URL. This content is typically a url-encoded string, meaning variables defined with values in the form of

            [code]variable1=value1&variable2=value2&variable3=value3&[/code]

            and so on. As it exists there, its just a string - a collection of letters, numbers, and symbols. Once its parsed by Flash, however, what you get is an object that has 3 variables, each with 3 values; something equivalent to:

            [as]var obj = new Object();
            obj.variable1 = "value1";
            obj.variable2 = "value2";
            obj.variable3 = "value3";[/as]

            That transformation of the string to that object (which in the case of LoadVars, obj would actually be the LoadVars instance) is the result of Flash parsing that original string.

            when you use the onData event handler, your handler gets passed one variable, the raw string loaded into the Flash player before that string is parsed

            [as]myLoadVars.onData = function(rawText) {
            trace(rawText); // variable1=value1&variable2=value2&variable3=value3&
            }[/as]

            Those variables would not have been parsed and, infact, you are preventing them from being parsed at all since Flash internally uses onData for parsing. By creating your own, you have intercepted Flash's own parsing call which looks something like:

            [as]defaultLoadVars.onData = function(rawText) {
            var success = this.parse(rawText);
            this.onLoad(success);
            }[/as]

            This default onData that Flash uses parses the text and then calls the onLoad event handler passing, not the rawText, as it has now been parsed into variables defined in the LoadVars instance, but instead the success of the parsing (and loading) process.

            So by not using onData, the default onData is used and in turn calls onLoad which you can use to get the text after it has been parsed and turned into variables

            [as]myLoadVars.onLoad = function(success) {
            if (success) {
            trace(this.variable1); // "value1"
            trace(this.variable2); // "value2"
            trace(this.variable3); // "value3"
            }else{
            trace("Something went wrong");
            }
            }[/as]

            ====

            now why flash parsed the original text/raw text when i used onLoad event in LoadVars ? when i used onData & onLoad event handler & why ?
            • 4. why flash parsed the original text ?
              Peter Lorent Level 2
              You either use your own onData handler -> to use a custom parsing routine you wrote yourself
              OR you use the build in onLoad handler.

              Using both handlers doesn't make any sense.