View comments | RSS feed

decode (LoadVars.decode method)

public decode(queryString:String) : Void

Converts the variable string to properties of the specified LoadVars object.

This method is used internally by the LoadVars.onData event handler. Most users do not need to call this method directly. If you override the LoadVars.onData event handler, you can explicitly call LoadVars.decode() to parse a string of variables.

Availability: ActionScript 1.0; Flash Player 7

Parameters

queryString:String - A URL-encoded query string containing name/value pairs.

Example

The following example traces the three variables:

// Create a new LoadVars object
var my_lv:LoadVars = new LoadVars();
//Convert the variable string to properties
my_lv.decode("name=Mort&score=250000");
trace(my_lv.toString());
// Iterate over properties in my_lv
for (var prop in my_lv) {
    trace(prop+" -> "+my_lv[prop]);
}

See also

onData (LoadVars.onData handler), parseXML (XML.parseXML method)


Version 8

Comments


reinier77 said on Feb 16, 2006 at 7:44 AM :
The decode function doesn't decode characters like %F3 (ó) and %D1 (Ñ) etc properly (characters with code > %C0).

Here's a workaround:
Override the onData event of the LoadVars-class in a new class extending LoadVars.
Replace all encoded chars with code>%C0 in the source string by their normal ascii character
Then decode in the normal fashion with the decode method of the LoadVars-class.

Example:

class LoadVarsRF extends LoadVars {
private function onData(src:String):Void {
var chars:String = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~__________________________________¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ";
while(true) {
var i0:Number = src.indexOf("%");
if (i==-1) break;
var n:Number = parseInt("0x"+src.substr(i+1,2));
if (n>0xC0) src = src.substr(0,i)+chars.charAt(n-32)+src.substr(i+3);
}
this.decode(src);
}
}

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00002326.html